5

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
Andy
  • 1,454
  • 17
  • 33

4 Answers4

2

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

Community
  • 1
  • 1
COD3BOY
  • 11,964
  • 1
  • 38
  • 56
  • Just to be more precise, @SuppressWarnings is not specific to Eclipse. However, the list of warnings suppressed by that annotation is compiler specific. – Andrew Eisenberg Oct 14 '11 at 15:00
1

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.

Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • Yep, it seems like an Eclipse/AspectJ bug, so I've filed an issue: https://bugs.eclipse.org/bugs/show_bug.cgi?id=213755. – Andy Oct 14 '11 at 11:16
0

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.

Heiko Schmitz
  • 300
  • 1
  • 4
  • Unfortunately, it is indeed a case when there's no way to avoid declaring unused private method. – Andy Oct 13 '11 at 14:53
0

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

jonagr
  • 73
  • 6