Bug 75490

Summary: Referencing a static inner class (that extends Exception) in an interface from another class results in a compile time error
Product: [Eclipse Project] JDT Reporter: Michael Bradburn <michaelpb78>
Component: CoreAssignee: JDT-Core-Inbox <jdt-core-inbox>
Status: RESOLVED INVALID QA Contact:
Severity: blocker    
Priority: P3 CC: kanishka_liyanage
Version: 3.0   
Target Milestone: 3.1 M3   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Michael Bradburn CLA 2004-10-01 15:06:27 EDT
Hi,
First of all, I started out using build 3.1 M1 and then went back to 3.0.1 but
encountered the same problem.  I have an interface that contains an embedded
static class, which extends Exception, like this:

public interface I
{
  public static class MyException extends Exception
  {
  }
}

and another class that has a method that throws that exception like this:

public class A
{
  protected void test() throws I$MyException
  {
  }
}

but when I try to build the project in either build of eclipse, I get the
following compile time error:

The exception type I$MyException cannot be referenced using its binary name.

even though the interface compiles correctly and I can see that
I$MyException.class exists.  The compiler does, however, give this warning when
I compile the interface:

The serializable class MyException does not declare a static final
serialVersionUID field of type long.

I doubt that this is causing the problem, though.  This does compile when I use
javac (through ant) and JBuilder and I know that it is legal in the Java
language.  I am trying to migrate from JBuilder to eclipse.  All of this source
is older stuff and I did not write the interface and class that is causing this
problem.  At the same time, I should't have to go back to modify it (even if it
is bad) to work with an IDE.
Comment 1 Rafael Chaves CLA 2004-10-01 15:12:21 EDT
Aren't inner types supposed to be referenced using OuterClass.InnerClass
(instead of OuterClass$InnerClass)?
Comment 2 Olivier Thomann CLA 2004-10-01 15:41:33 EDT
I don't understand how you can compile this code with javac. I tried version
1.3.1, 1.4.2_05 and 1.5.0 and all of them fail with:

symbol  : class I$MyException
location: class p1.A
perchance you meant 'I.MyException'
        protected void test() throws I$MyException {
                                     ^
1 error

or:
p1/A.java:4: cannot resolve symbol
symbol  : class I$MyException
location: class p1.A
        protected void test() throws I$MyException {
                                     ^
1 error

It doesn't compile. If you replace I$MyException with I.MyException, then it
works fine on Eclipse and any javac version.
I also tried jikes 1.21 and it fails.

Close as INVALID.
Comment 3 Michael Bradburn CLA 2004-10-01 16:35:25 EDT
It does compile as outer$inner if you compile outside of eclipse (such as by
invoking javac at a prompt).  Just compile I first and then A without using an
IDE.  I guess this really isn't that important since the person who wrote this
code did it in a non-standard way and I should just fix the code.  It would be
interesting to find out why it doesn't work in eclipse, though.
Comment 4 Philipe Mulet CLA 2004-10-01 19:16:53 EDT
Our compiler doesn't allow to use member types with binary names, as per spec.
Looks like other compilers let it go thru.
Comment 5 Olivier Thomann CLA 2005-01-10 15:46:00 EST
*** Bug 82487 has been marked as a duplicate of this bug. ***