Skip to content

Commit 4f9c5c6

Browse files
author
Fabrice Tiercelin
committed
Do not replace if literals are evaluated to null
1 parent a906ff7 commit 4f9c5c6

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

plugin/src/main/java/org/autorefactor/jdt/internal/ui/fix/LogParametersRatherThanLogMessageCleanUp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ private boolean maybeReplaceConcatenation(final MethodInvocation visited, final
9696
hasLiteral= true;
9797
String literal= (String) string.resolveConstantExpressionValue();
9898

99-
if (literal != null && (literal.contains("{") || literal.contains("}"))) { //$NON-NLS-1$ //$NON-NLS-2$
99+
if (literal == null || literal.contains("{") || literal.contains("}")) { //$NON-NLS-1$ //$NON-NLS-2$
100100
return true;
101101
}
102102

samples/src/test/java/org/autorefactor/refactoring/rules/samples_in/LogParametersRatherThanLogMessageSample.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
package org.autorefactor.refactoring.rules.samples_in;
2727

28+
import java.util.List;
29+
2830
import org.slf4j.Logger;
2931

3032
public class LogParametersRatherThanLogMessageSample {
@@ -93,4 +95,8 @@ public void doNotReplaceConcatenateSplitLiteral(Logger slf4jLog) {
9395
slf4jLog.debug("This text is very long and it can't be kept on a single line"
9496
+ " so we have to break it in order to keep readability.");
9597
}
98+
99+
public void doNotReplaceIfLiteralsAreEvaluatedToNull(Logger slf4jLog) {
100+
slf4jLog.debug("aa" + "aa" + 1);
101+
}
96102
}

samples/src/test/java/org/autorefactor/refactoring/rules/samples_out/LogParametersRatherThanLogMessageSample.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
*/
2626
package org.autorefactor.refactoring.rules.samples_out;
2727

28+
import java.util.List;
29+
2830
import org.slf4j.Logger;
2931

3032
public class LogParametersRatherThanLogMessageSample {
@@ -93,4 +95,8 @@ public void doNotReplaceConcatenateSplitLiteral(Logger slf4jLog) {
9395
slf4jLog.debug("This text is very long and it can't be kept on a single line"
9496
+ " so we have to break it in order to keep readability.");
9597
}
98+
99+
public void doNotReplaceIfLiteralsAreEvaluatedToNull(Logger slf4jLog) {
100+
slf4jLog.debug("aa" + "aa" + 1);
101+
}
96102
}

0 commit comments

Comments
 (0)