diff --git a/src/main/java/org/openrewrite/java/logging/slf4j/StripToStringFromArguments.java b/src/main/java/org/openrewrite/java/logging/slf4j/StripToStringFromArguments.java index a541e4d3..0c3eb1fe 100644 --- a/src/main/java/org/openrewrite/java/logging/slf4j/StripToStringFromArguments.java +++ b/src/main/java/org/openrewrite/java/logging/slf4j/StripToStringFromArguments.java @@ -78,7 +78,7 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation m, ExecutionC J.MethodInvocation toStringInvocation = (J.MethodInvocation) arg; if (TO_STRING_MATCHER.matches(toStringInvocation.getMethodType()) && toStringInvocation.getSelect() != null && - !(firstFormatArgIndex == lastArgIndex && TypeUtils.isAssignableTo("java.lang.Throwable", toStringInvocation.getSelect().getType()))) { + !(index == lastArgIndex && TypeUtils.isAssignableTo("java.lang.Throwable", toStringInvocation.getSelect().getType()))) { // Strip the `.toString()` call return toStringInvocation.getSelect().withPrefix(toStringInvocation.getPrefix()); } diff --git a/src/test/java/org/openrewrite/java/logging/slf4j/StripToStringFromArgumentsTest.java b/src/test/java/org/openrewrite/java/logging/slf4j/StripToStringFromArgumentsTest.java index 59fd43ca..0fd96e9a 100644 --- a/src/test/java/org/openrewrite/java/logging/slf4j/StripToStringFromArgumentsTest.java +++ b/src/test/java/org/openrewrite/java/logging/slf4j/StripToStringFromArgumentsTest.java @@ -57,7 +57,7 @@ record TestCase(String originalArgs, String expectedArgs) { ", exception, o1"), new TestCase( ", o1, exception.toString()", - ", o1, exception") + ", o1, exception.toString()") ); return Stream.of("trace", "debug", "info", "warn", "error")