Bug 303606

Summary: [compiler] Either 'Exception ... not actually thrown' warning or 'Unnecessary @SuppressWarning("unused")'?
Product: [Eclipse Project] JDT Reporter: Michael Moser <mmo>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: VERIFIED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: Olivier_Thomann
Version: 3.5.1   
Target Milestone: 3.6 M6   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
screen shot of Compiler options - part 1
none
screen shot of Compiler options - part 2 none

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... !?