Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6356636

Compiler fails to read signatures of inner classes with non-generic outer instance leading to crash

XMLWordPrintable

    • b85
    • generic, x86
    • generic, linux, windows_xp
    • Verified

        FULL PRODUCT VERSION :
        java version "1.5.0_05"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
        Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode, sharing)


        ADDITIONAL OS VERSION INFORMATION :
        Linux bass 2.4.31 #9 Sun Jun 26 22:44:43 MSD 2005 i686 i686 i386 GNU/Linux
        Linux desperado 2.6.13-suspend2-r4 #3 SMP Fri Sep 16 12:13:52 MSD 2005 i686 AMD Athlon(TM) XP 2400+ AuthenticAMD GNU/Linux
        SunOS aldan 5.9 Generic_117171-17 sun4u sparc SUNW,Ultra-5_10
        Windows XP

        A DESCRIPTION OF THE PROBLEM :
        A certain piece of code (attached below) involving inheritance and generics can't be compiled with javac: it reports an internal NullPointerException.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Just try to compile the code attached.

        Important: the code should be organized into 2 packages (just like in the example atached). If you merge everything to a single package, you won't get any error.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The code should be compiled cleanly.
        ACTUAL -
        Compiler crashes with an internal error.

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        An exception has occurred in the compiler (1.5.0_05). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you.
        java.lang.NullPointerException
                at com.sun.tools.javac.code.Types$IsSameTypeFcn.visitClassType(Types.java:652)
                at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:482)
                at com.sun.tools.javac.code.Types$IsSameTypeFcn.isSameType(Types.java:601)
                at com.sun.tools.javac.code.Types$IsSameTypeFcn.visitClassType(Types.java:674)
                at com.sun.tools.javac.code.Type$ClassType.accept(Type.java:482)
                at com.sun.tools.javac.code.Types$IsSameTypeFcn.isSameType(Types.java:601)
                at com.sun.tools.javac.code.Types.isSameType(Types.java:591)
                at com.sun.tools.javac.code.Types.covariantReturnType(Types.java:2645)
                at com.sun.tools.javac.code.Types.resultSubtype(Types.java:2607)
                at com.sun.tools.javac.code.Types.returnTypeSubstitutable(Types.java:2615)
                at com.sun.tools.javac.code.Symbol$MethodSymbol.overrides(Symbol.java:814)
                at com.sun.tools.javac.code.Symbol$MethodSymbol.implementation(Symbol.java:866)
                at com.sun.tools.javac.comp.Check.firstUndef(Check.java:1354)
                at com.sun.tools.javac.comp.Check.firstUndef(Check.java:1367)
                at com.sun.tools.javac.comp.Check.checkAllDefined(Check.java:1319)
                at com.sun.tools.javac.comp.Attr.attribClassBody(Attr.java:2436)
                at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2406)
                at com.sun.tools.javac.comp.Attr.attribClass(Attr.java:2355)
                at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:444)
                at com.sun.tools.javac.main.Main.compile(Main.java:592)
                at com.sun.tools.javac.main.Main.compile(Main.java:544)
                at com.sun.tools.javac.Main.compile(Main.java:67)
                at com.sun.tools.javac.Main.main(Main.java:52)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        ---- BEGIN a/AbstractFoo.java ----
        package a;

        public class AbstractFoo {
        public class InnerFoo<T> {}
        }
        ---- END a/AbstractFoo.java ----
        ---- BEGIN a/Bar.java ----
        package a;

        import a.AbstractFoo.InnerFoo;

        public interface Bar {
        InnerFoo<String> getInnerFoo();
        }
        ---- END a/Bar.java ----
        ---- BEGIN b/Foo.java ----
        package b;

        import a.*;

        public final class Foo extends AbstractFoo implements Bar {
        public InnerFoo<String> getInnerFoo() {
        return null;
        }
        }
        ---- END b/Foo.java ----
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        There're three possible workarounds:

        either abandon generalization of an inner class: a.AbstractFoo.InnerFoo instead of a.AbstractFoo.InnerFoo<T>,

        or declare inner class static (though it may be never referenced from the static context),

        or move the descendant class (b.Foo) to the package where its superclass and superinterface reside (a).
        .

              vchoudhaorcl Vaibhav Choudhary (Inactive)
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: