Skip to content

Commit

Permalink
Do not replace if literals are evaluated to null
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabrice Tiercelin committed May 28, 2021
1 parent a906ff7 commit 4f9c5c6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private boolean maybeReplaceConcatenation(final MethodInvocation visited, final
hasLiteral= true;
String literal= (String) string.resolveConstantExpressionValue();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/
package org.autorefactor.refactoring.rules.samples_in;

import java.util.List;

import org.slf4j.Logger;

public class LogParametersRatherThanLogMessageSample {
Expand Down Expand Up @@ -93,4 +95,8 @@ public void doNotReplaceConcatenateSplitLiteral(Logger slf4jLog) {
slf4jLog.debug("This text is very long and it can't be kept on a single line"
+ " so we have to break it in order to keep readability.");
}

public void doNotReplaceIfLiteralsAreEvaluatedToNull(Logger slf4jLog) {
slf4jLog.debug("aa" + "aa" + 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
*/
package org.autorefactor.refactoring.rules.samples_out;

import java.util.List;

import org.slf4j.Logger;

public class LogParametersRatherThanLogMessageSample {
Expand Down Expand Up @@ -93,4 +95,8 @@ public void doNotReplaceConcatenateSplitLiteral(Logger slf4jLog) {
slf4jLog.debug("This text is very long and it can't be kept on a single line"
+ " so we have to break it in order to keep readability.");
}

public void doNotReplaceIfLiteralsAreEvaluatedToNull(Logger slf4jLog) {
slf4jLog.debug("aa" + "aa" + 1);
}
}

0 comments on commit 4f9c5c6

Please sign in to comment.