Bug 361115 - @SuppressWarnings will suppress optional errors, but code will not be generated
Summary: @SuppressWarnings will suppress optional errors, but code will not be generated
Status: VERIFIED DUPLICATE of bug 346175
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Satyam Kandula CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-17 05:57 EDT by Thomas Thrien CLA
Modified: 2012-01-24 06:39 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Thrien CLA 2011-10-17 05:57:12 EDT
Build Identifier: 20110916-0149

Assume the following class (comments and imports were stripped because they will not add to the understanding):

    public final class LogLevel extends Level
    {
	@SuppressWarnings( "hiding" )
	public final static Level ALL = Level.ALL;

	public final static Level AUDIT = new LogLevel( "AUDIT", 2000 );

	@SuppressWarnings( "hiding" )
	public final static Level CONFIG = Level.CONFIG;

	public final static Level DEBUG = new LogLevel( "DEBUG", Level.FINER.intValue() );

	public final static Level ENTRY = new LogLevel( "ENTRY", Level.FINEST.intValue() );

	public final static Level ERROR = new LogLevel( "ERROR", 1200 );

	public final static Level EXIT = new LogLevel( "EXIT", Level.FINEST.intValue() );

	@SuppressWarnings( "hiding" )
	public final static Level FINE = Level.FINE;

	@SuppressWarnings( "hiding" )
	public final static Level FINER = Level.FINER;

	@SuppressWarnings( "hiding" )
	public final static Level FINEST = Level.FINEST;

	@SuppressWarnings( "hiding" )
	public final static Level INFO = Level.INFO;

	public final static Level INIT = new LogLevel( "INIT", 850 );

	@SuppressWarnings( "hiding" )
	public final static Level OFF = Level.OFF;

	@SuppressWarnings( "hiding" )
	public final static Level SEVERE = Level.SEVERE;

	public final static Level SETUP = new LogLevel( "SETUP", 890 );

	public final static Level SHUTDOWN = new LogLevel( "SHUTDOWN", 890 );

	public final static Level TRACE = new LogLevel( "TRACE", Level.FINEST.intValue() );

	public final static Level VERBOSE = new LogLevel( "VERBOSE", Level.FINE.intValue() );

	@SuppressWarnings( "hiding" )
	public final static Level WARNING = Level.WARNING;

	private static final long serialVersionUID = -3872433371275614712L;

	private LogLevel( final String name, final int value )
	{
	    super( name, value, "ResBundle" );
	}
    }

The class add some new log levels to the JDK logging. It will also repeat the standard levels, as convenience: so I can statically import just LogLevel.* to have all log levels available at once.

The "copies" of the standard log levels (like SEVERE) will hide the "originals". In my original Eclipse settings, "hiding" should cause an error (Project|Properties - Java Compiler|Errors/Warnings - Name shadowing and conflicts - Field declaration hides another field or variable); in addition, I activated that @SuppressWarnings should suppress optional errors (Project|Properties - Java Compiler|Errors/Warnings - Annotations - Suppress optional errors with '@SuppressWarnings') and that errors should make the compiled code not executable (Project|Properties - Java Compiler|Errors/Warnings - Treat above errors like fatal compiler errors (make compiled code not executable)).

Everything works fine until I moved to Indigo SR1. From that time onwards, accessing one of the constants in LogLevel returned null. As you might imagine, it drove me crazy that a line like 

LogLevel.SEVERE.intValue()

caused a NullPointerException.

Obviously will "Suppress optional Errors" only suppress the error message and the generation of the compiling problem exception for an optional error, but the compiled code is still not executable - and this without any warning at generation time ...

Reproducible: Always

Steps to Reproduce:
See above
Comment 1 Ayushman Jain CLA 2011-10-17 07:12:59 EDT
(In reply to comment #0)
> Everything works fine until I moved to Indigo SR1. From that time onwards,
> accessing one of the constants in LogLevel returned null. As you might imagine,
> it drove me crazy that a line like 
> 
> LogLevel.SEVERE.intValue()
> 
> caused a NullPointerException.

I did not get an NPE but got a "Unresolved compilation problem" instead on running the program (Adding a main method to your class). This works fine in 3.6.2 though.

However, not sure whether this is a bug because even java 7 refuses to run this class.
Comment 2 Thomas Thrien CLA 2011-10-17 07:30:26 EDT
(In reply to comment #1)
> (In reply to comment #0)
> > Everything works fine ...
> 
> I did not get an NPE but got a "Unresolved compilation problem" instead on
> running the program (Adding a main method to your class). This works fine in
> 3.6.2 though.
> 
> However, not sure whether this is a bug because even java 7 refuses to run this
> class.

Accessing the LogLevel class from another class that have the main() would give you the NPE.

But I should add that the problem shows up when running the program from inside Eclipse, either as JUnit test or as application. Compiling the stuff with Maven or Ant and running it outside of Eclipse always worked fine.

Furthermore the nature of the bug is that there is no code generated WITHOUT any message; the problem will only revealed by running the code.

As a workaround, setting "Hiding" to Warning instead of Error would work fine.
Comment 3 Satyam Kandula CLA 2012-01-05 23:51:12 EST
The patch in bug 346175 fixes this problem. The option to Suppress optional errors  is introduced in 3.6 and the problem exists since then.

*** This bug has been marked as a duplicate of bug 346175 ***
Comment 4 Stephan Herrmann CLA 2012-01-24 06:39:26 EST
Verified for 3.8 M5 using build I20120123-1300