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

javac inconsistently numbers anonymous classes used for final static variables

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.3.1
    • 1.3.0
    • tools
    • ladybird
    • generic
    • generic
    • Verified



        Name: skT45625 Date: 12/11/2000


        java version "1.3.0"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
        Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)



        Given this class:

            import java.util.Comparator;
            import java.util.TreeSet;

            public class InnerBug
            {
        static One makeOne()
        {
        return new One();
        }

        private static class One
        {
        public TreeSet set = new TreeSet(HASH_COMPARATOR);
        }

        private final static Comparator HASH_COMPARATOR =
        new Comparator()
        {
        public int compare(Object object1, Object object2)
        {
        int hash1 = object1.hashCode();
        int hash2 = object2.hashCode();
        if (hash1 < hash2)
        return -1;
        if (hash2 < hash1)
        return 1;
        return 0;
        }
        };
            }

        The 1.3 version of javac generates the following three class files:

            InnerBug.class
            InnerBug$2.class
            InnerBug$One.class

        Note that InnerBug$2 was created, and not InnerBug$1.

        On the other hand, the class files for InnerBug and InnerBug.One both
        refer to InnerBug$1. For example, javap -private InnerBug says:

            Compiled from InnerBug.java
            public class InnerBug extends java.lang.Object {
                private static final java.util.Comparator HASH_COMPARATOR;
                public InnerBug();
                static InnerBug.One makeOne();
                public static void main(java.lang.String[]);
                static java.util.Comparator access$100();
                static {};
                private static class InnerBug. One extends java.lang.Object
                /* ACC_SUPER bit NOT set */
            {
                    public java.util.TreeSet set;
                    private InnerBug.One();
                    InnerBug.One(InnerBug$1);
                }
            }

        Note that the constructor for the inner class One takes as its argument
        an instance of InnerBug$1, a class which does not exist.

        Nonetheless, class InnerBug and InnerBug$One both verify properly, and
        adding a simple main method to InnerBug:

            public static void main(String[] args)
            {
        One one = makeOne();
        for (int i = 0; i < args.length; i++)
        one.set.add(args[i]);

        java.util.Iterator it = one.set.iterator();
        while (it.hasNext()) {
        Object next = it.next();
        System.out.println(next + " // " + next.hashCode());
        }
            }

        allows it to run without raising any type conflict errors when invoking
        the InnerBug.One constructor.

        It appears that InnerBug$1 and InnerBug$2 are meant to be the same
        class, the implementation of the Comparator interface.

        This bug does not occur with javac 1.2.2. It does appear, in 1.3, on
        both Solaris (SPARC) and Linux (x86).
        (Review ID: 113623)
        ======================================================================

              gafter Neal Gafter (Inactive)
              skondamasunw Suresh Kondamareddy (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: