[java-inspections] IDEA-380849 "Result of method call ignored" does not suppress newer AssertJ org.assertj.core.annotation.CanIgnoreReturnValue

(cherry picked from commit 43390d23feddef2549fa4be09c2328149df8ea77)

IJ-CR-183645

GitOrigin-RevId: 30af068386be165d3cf135c95d0048552ca97108
This commit is contained in:
Mikhail Pyltsin
2025-12-02 16:42:32 +00:00
committed by intellij-monorepo-bot
parent 6d1000e6ff
commit 1d7bcd8ef2
2 changed files with 33 additions and 1 deletions
@@ -37,7 +37,9 @@ import java.util.regex.Pattern;
public final class MethodUtils {
private static final Set<String> CAN_IGNORE_RETURN_VALUE_ANNOTATIONS = Set.of(
"org.assertj.core.util.CanIgnoreReturnValue", "com.google.errorprone.annotations.CanIgnoreReturnValue");
"org.assertj.core.util.CanIgnoreReturnValue",
"org.assertj.core.annotation.CanIgnoreReturnValue",
"com.google.errorprone.annotations.CanIgnoreReturnValue");
private MethodUtils() {}
@@ -129,6 +129,15 @@ public class IgnoreResultOfCallInspectionTest extends LightJavaInspectionTestCas
@Retention(value=CLASS)
public @interface CanIgnoreReturnValue{}
""",
"""
package org.assertj.core.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target({CONSTRUCTOR,METHOD,PACKAGE,TYPE})
public @interface CanIgnoreReturnValue{}
""",
"""
package org.apache.commons.lang3;
public class Validate {
@@ -338,6 +347,27 @@ public class IgnoreResultOfCallInspectionTest extends LightJavaInspectionTestCas
""");
}
public void testCanIgnoreReturnValue4() {
doTest("""
import org.assertj.core.annotation.CanIgnoreReturnValue;
import javax.annotation.CheckReturnValue;
@CheckReturnValue
class Test {
int lookAtMe() { return 1; }
@CanIgnoreReturnValue
int ignoreMe() { return 2; }
void run() {
/*Result of 'Test.lookAtMe()' is ignored*/lookAtMe/**/(); // Bad! This line should produce a warning.
ignoreMe(); // OK. This line should *not* produce a warning.
}
}""");
}
public void testCustomCheckReturnValue() {
doTest("""
import a.CheckReturnValue;