Bug 303606 - [compiler] Either 'Exception ... not actually thrown' warning or 'Unnecessary @SuppressWarning("unused")'?
Summary: [compiler] Either 'Exception ... not actually thrown' warning or 'Unnecessary...
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5.1   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 3.6 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-23 06:47 EST by Michael Moser CLA
Modified: 2010-03-08 14:11 EST (History)
1 user (show)

See Also:


Attachments
screen shot of Compiler options - part 1 (231.59 KB, image/jpeg)
2010-02-26 08:08 EST, Michael Moser CLA
no flags Details
screen shot of Compiler options - part 2 (227.14 KB, image/jpeg)
2010-02-26 08:09 EST, Michael Moser CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Moser CLA 2010-02-23 06:47:01 EST
Build Identifier: Build id: 20090621-0832

I have a type where some method declares an exception to allow derived types to throw that exception. The basic implemenation however just returns null and thus does not actually throw any exception. 

However, when I silence the resulting warning using a @SuppressWarning("unused") annotation then I get another warning stating "Unnecessary @SuppressWarning("unused")". The latter is probably due to the fact, that the compiler recognices, that the throws is NOT unused and hence the annotation is superfluous. 

I append a condensed example that shows the problem below.
How do I phrase this code without getting *any* warning?

Michael

-----------------------------------------
package test;

public class Test
{
	@SuppressWarnings("serial")
	class MyException extends Exception {
		MyException(String msg) {
			super(msg);
		}
	}
	
	class A {
		protected Object foo(Object x) throws MyException {
			return null;
		}
	}

	class B extends A {
		@Override
		protected Object foo(Object x) throws MyException {
			if (x == null) throw new MyException("x is null");
			return x.getClass();
		}
	}
}
-----------------------------------------

Reproducible: Always
Comment 1 Olivier Thomann CLA 2010-02-23 09:04:44 EST
Please provide your compiler options.
Comment 2 Michael Moser CLA 2010-02-26 08:08:54 EST
Created attachment 160295 [details]
screen shot of Compiler options - part 1
Comment 3 Michael Moser CLA 2010-02-26 08:09:29 EST
Created attachment 160296 [details]
screen shot of Compiler options - part 2
Comment 4 Michael Moser CLA 2010-02-26 08:11:48 EST
Sorry for appending this as screenshot, but I found not way to export just the compiler flags. And an exported eclipse pref's file is not only a longish mess but also seems to contain confidential data, like code repository login ids (and credentials?), that I don't want to make public...

M.
Comment 5 Olivier Thomann CLA 2010-02-26 09:45:38 EST
Could you please try with a newer build? I cannot reproduce with I20100224-2242.
I am closing as WORKSFORME.
Please reopen if you see it again with a 3.6 I-build.
Comment 6 Frederic Fusier CLA 2010-03-08 14:11:26 EST
Verified that it works well in 3.5.0, 3.6M5 and 3.6M6. Note that the build id you gave is not the 3.5.0 one as its ID is I20090611-1540... !?