rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

org.openrewrite.staticanalysis.RemoveUnusedPrivateMethods ignores class level @SuppressWarnings("unused")

Open blipper opened this issue 11 months ago • 1 comments

What version of OpenRewrite are you using?

6.6.3

How are you running OpenRewrite?

What is the smallest, simplest way to reproduce the problem?

@SuppressWarnings("unused")
class A {
    @SuppressWarnings("unused")
    private static void foo() {
    }

    private void bar() {
    }

}

What did you expect to see?

@SuppressWarnings("unused")
class A {
    @SuppressWarnings("unused")
    private static void foo() {
    }

    private void bar() {
    }

}

What did you see instead?

@SuppressWarnings("unused")
class A {
    @SuppressWarnings("unused")
    private static void foo() {
    }

}

The looks like that https://github.com/openrewrite/rewrite-static-analysis/blob/main/src/main/java/org/openrewrite/staticanalysis/RemoveUnusedPrivateMethods.java#L62 doesn't look at the class level annotation and is also just assuming that any class annotation means don't do anything. IT should look for @SuppressWarnings("unused") at the class level.

What is the full stack trace of any errors you encountered?

stacktrace output here

Are you interested in contributing a fix to OpenRewrite?

blipper avatar Mar 05 '24 22:03 blipper