JDK-5086027 : Inner class of generic class cannot extend Throwable
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 5.0u1
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_9
  • CPU: sparc
  • Submitted: 2004-08-12
  • Updated: 2017-05-16
  • Resolved: 2006-02-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6 b73Fixed
Related Reports
Relates :  
Description
Consider the three attached java files.
If you compile them one at a time they will all compile and the app will run.
However if you compile them en-masse you'll get nonsensical error messages:

damavand: rm *.class
damavand: javac -g Stack.java
damavand: javac -g EmbellishedStack.java
damavand: javac -g Test.java
damavand: javac -g *.java
Stack.java:26: unreported exception Stack.UnderflowException; must be caught or declared to be thrown
            throw new UnderflowException();
            ^
Stack.java:34: unreported exception Stack.UnderflowException; must be caught or declared to be thrown
            throw new UnderflowException();
            ^

This is actually on:
damavand: java -version
java version "1.5.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b56)
Java HotSpot(TM) Client VM (build 1.5.0-beta3-b56, mixed mode, sharing)

Comments
SUGGESTED FIX Webrev of changes: http://sa.sfbay/projects/langtools/bugid_summary.pl?bugid=5086027
14-02-2006

EVALUATION As the problem is really that inner classes may not extend Throwable, I have changed the synopsis.
03-01-2006

EVALUATION As the fix involves rejecting more program, this might have a compatibility impact.
03-01-2006

WORK AROUND The exception subclass is an inner class, make it a static nested class instead by adding the keyword "static".
03-01-2006

CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: dragon mustang
08-09-2004

EVALUATION Yes, this is a bug. It appears that the compilation order is important. Here is a simpler example: $ cat A.java class A<T> extends B<T> { void m() { } } $ cat B.java class B<T> { class X extends Exception { } void m() throws X { throw new X(); } } $ javac A.java B.java B.java:4: unreported exception B.X; must be caught or declared to be thrown throw new X(); ^ 1 error ###@###.### 2004-08-12 Neal Gafter points out that the problem is that X is a generic class (it is a non-static member of a generic class). Generic classes are not allowed to extend Throwable, so the compiler should actually reject B.java. However, the reported error appears to be wrong. Also, the error is not reported if B.java is compiled alone. ###@###.### 2004-08-12
12-08-2004