| Summary: | annotating a field with @SuppressWarnings("rawtypes") blocks warnings about uninitialized final fields for other fields in editor | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | Marcin Grabowski <lamvak> |
| Component: | Core | Assignee: | Satyam Kandula <satyam.kandula> |
| Status: | VERIFIED DUPLICATE | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | srikanth_sankaran, stephan.herrmann |
| Version: | 3.6.2 | ||
| Target Milestone: | 3.8 M5 | ||
| Hardware: | PC | ||
| OS: | Linux | ||
| Whiteboard: | |||
Thanks for the report, but unfortunately I cannot reproduce the problem.
To be fully explicit (your "Class<X>" notation is a bit misleading),
I used this class:
import java.util.List;
public class T {
private final String bar;
@SuppressWarnings("rawtypes")
private final List x;
public String getBar() {
return this.bar;
}
public List getX() {
return this.x;
}
public T() {
}
}
Compiled it with ecj (command line) 3.6.2 and also in the IDE (3.8M4).
In both cases I see three problems:
----------
1. WARNING in T.java (at line 9)
public List getX() {
^^^^
List is a raw type. References to generic type List<E> should be parameterized
----------
2. ERROR in T.java (at line 12)
public T() {
^^^
The blank final field bar may not have been initialized
----------
3. ERROR in T.java (at line 12)
public T() {
^^^
The blank final field x may not have been initialized
----------
3 problems (2 errors, 1 warning)
What am I doing differently?
Is it just the editor, do you see the error in the "Problems View"?
Do you really mean "warning" (vs. "error")?
Thanks for a quick response. And I'm sorry for my previous vague example. Using your code I propose a litte change:
public class T {
public static void main(final String[] args) {
//
}
private final String bar;
public T() {
//
}
public String getBar() {
return this.bar;
}
}
This exact code, when I try to run it (hence the addition of main function), cause two events - one is the underlining of the line with constructor T signature and the other is in deed an entry in "problems view"; both with error of: "The blank final field bar may not have been initialized".
Now i'm not sure if it should be an error or a warning - in general or by default, because I did change some of the warnings to errors in Java -> Compiler -> Errors/Warnings (for the sake of stricter code). It is an error with my settings anyway.
Now, for the following code:
import java.util.List;
public class T {
public static void main(final String[] args) {
//
}
private final String bar;
@SuppressWarnings("rawtypes")
private final Class<List> l;
public T() {
//
}
public String getBar() {
return this.bar;
}
}
I have no notification of any error - neither as a underlining of a line in edit with a side marker, nor by any entry in "problems view".
And it's the same with a getter for l (but I add a suppress warnings on the getter, too) and / or with initialization of this.l = List.class; in body of constructor T().
There are compiler errors, though, when the exact code is compiled in command line.
ecj gives me:
$ ecj -v
Eclipse Compiler for Java (TM) 0.981_R35x, 3.5.2 release, Copyright IBM Corp 2000, 2009. All rights reserved.
$ ecj -6 T.java
----------
1. WARNING in T.java (at line 10)
@SuppressWarnings("rawtypes")
^^^^^^^^^^
Unsupported @SuppressWarnings("rawtypes")
----------
2. WARNING in T.java (at line 11)
private final Class<List> l;
^^^^
List is a raw type. References to generic type List<E> should be parameterized
----------
3. WARNING in T.java (at line 11)
private final Class<List> l;
^
The field T.l is never read locally
----------
4. ERROR in T.java (at line 13)
public T() {
^^^
The blank final field bar may not have been initialized
----------
5. ERROR in T.java (at line 13)
public T() {
^^^
The blank final field l may not have been initialized
----------
5 problems (2 errors, 3 warnings)
Whereas javac:
$ javac -version
javac 1.6.0_22
$ javac T.java
T.java:15: variable bar might not have been initialized
}
^
1 error
And when this code is run as java application it does not show errors in editor / "problems view", but in console gives output on STDERR (red output):
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
at T.main(T.java:4)
There's a side problem of compatibility of SuppressWarnings value markers - my version of eclipse suggests "rawTypes" for a raw type, but as it seems it is not recognised by my standalone ecj.
If there's anything else I could clarify, please let me know.
See also bug 365455 and bug 346175 Satyam, please take a look. Is this issue still open after the most recent patch by you and Olivier ? Yes this is same as bug 346175 and bug 365455. This works fine with the patch there. FYI to reproduce this, you need to do the following compiler problem settings. - Set 'Raw Warnings' to error - Enable 'SuppressWarnings' annotations - Enable 'Suppress optional errors with @SuppressWarnings' - Enable Treat above errors like fatal ..... *** This bug has been marked as a duplicate of bug 346175 *** Verified for 3.8 M5 using build I20120123-1300 |
Consider class: public class Foo { private final String bar; public String getBar() { return this.bar; } public Foo() { } } in java editor there should be a warning marked on the constructor Foo that field bar is final and not initialized but then if we change it as follows: public class Foo { private final String bar; @SuppressWarnings("rawtypes") private final Class<X> x; public String getBar() { return this.bar; } public X getX() { return this.x; } public Foo() { } } , where X is some parametrized class (like e.g. GWT's event class), then adding this @SuppressWarnings("rawtypes") to a fields blocks eclipse editor from showing warning about uninitialized final fields -- Configuration Details -- Product: Eclipse 1.3.2.20110218-0812 (org.eclipse.epp.package.java.product) Installed Features: org.eclipse.jdt 3.6.2.r362_v20101117-0800-7z8XFW6FLFlmjJcvz03jyeFBLS_F