Skip to content

Commit

Permalink
Do not parameterize throwable argument
Browse files Browse the repository at this point in the history
Fixes #131
  • Loading branch information
timtebeek committed Feb 19, 2024
1 parent 886d914 commit b2b39d5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
.contextSensitive()
.build()
.apply(new Cursor(getCursor().getParent(), m), m.getCoordinates().replaceArguments(), newArgList.toArray());
} else if (logMsg instanceof J.Identifier && TypeUtils.isAssignableTo("java.lang.Throwable", logMsg.getType()) ) {
return m;
} else if (!TypeUtils.isString(logMsg.getType()) && logMsg.getType() instanceof JavaType.Class) {
StringBuilder messageBuilder = new StringBuilder("\"{}\"");
m.getArguments().forEach(arg -> messageBuilder.append(", #{any()}"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,30 @@ static void method(Logger logger, String numberString) {
);
}

@Test
@Issue("https://github.com/openrewrite/rewrite-logging-frameworks/issues/131")
void throwableSingleParameter() {
rewriteRun(
spec -> spec.recipe(new ParameterizedLogging("org.apache.logging.log4j.Logger error(..)", false)),
//language=java
java(
"""
import org.apache.logging.log4j.Logger;
class Test {
static void method(Logger logger, String numberString) {
try {
Integer i = Integer.valueOf(numberString);
} catch (Exception e) {
logger.error(e);
}
}
}
"""
)
);
}

@Issue("https://github.com/openrewrite/rewrite-logging-frameworks/issues/58")
@Test
void methodInvocationReturnTypeIsString() {
Expand Down

0 comments on commit b2b39d5

Please sign in to comment.