Andy
Andy

Reputation: 1484

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

Upvotes: 5

Views: 1871

Answers (4)

Andrew Eisenberg
Andrew Eisenberg

Reputation: 28737

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.

Upvotes: 1

COD3BOY
COD3BOY

Reputation: 12092

The list of @SuppressWarnings is compiler specific. In Eclipse,

unused is macro for unusedArgument, unusedImport, unusedLabel, unusedLocal, unusedPrivate and unusedThrown

The whole list is here : the list of valid @SuppressWarnings supported in Eclipse

Upvotes: 2

jonagr
jonagr

Reputation: 73

It's working for me. I'm running Eclipse Indigo like you.

Upvotes: 0

Heiko Schmitz
Heiko Schmitz

Reputation: 330

I just tried and I don't get the "unnecessary..." warning. Are you sure that the warning is issued by the java compiler and not by some other tool such as checkstyle or findbugs?

Anyway, there are few situations, where an unused private method makes sense.

Upvotes: 0

Related Questions