Search code examples
javaeclipseaspectjsuppress-warnings

Eclipse: contradicting warnings


Here's the code snippet:

class MyClass {
    private native void foo();
}

For the above, Eclipse (namely, 3.7.0) gives a warning

The method foo() from the type MyClass is never used locally

Alright, but when I try to suppress the warning:

class MyClass {
    @SuppressWarnings("unused")
    private native void foo();
}

It complains

Unnecesary @SuppressWarnings("unused")

So, is there any way to make it stop complaining?

Update

Sorry for the incomplete information - this warning is only displayed in an AspectJ project. Once I create a simple Java project and put my class in it, all works fine.

As far as I understand, AspectJ uses its own compiler, so this warning must be generated by it. I'm using AspectJ Development Tools plug-in:

Version: 2.1.3.e37x-20110628-1900
AspectJ version: 1.6.12.20110613132200

Solution

  • Inside of a Java project, this produces no warnings:

    class MyClass {
        private native void foo();
    }
    

    This, however, produces a Unnecessary @SuppressWarnings("unused") warning:

    class MyClass {
        @SuppressWarnings("unused")
        private native void foo();
    }
    

    Inside of an AspectJ project, the first example produces a The method foo() from the type MyClass is never used locally warning and the second example produces the same warning as in a Java project. This is likely an AspectJ bug. I'd recommend raising an issue on the AspectJ bugzilla.

    https://bugs.eclipse.org/bugs/

    The AspectJ compiler is a fork of the JDT compiler from Eclipse 3.3. So, it is likely that this bug was originally in Eclipse 3.3. Now that Java 7 is available, AspectJ will likely migrate to being Eclipse 3.7 or 3.8 based and it will pick up the fix from the JDT compiler. But it is worth raising a bug anyway.