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

Redundant generic bridges are generated in some cases

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u85, 8, 9
    • tools

      A and B are symmetric: A's nested class extends B, B's nested class extends A. Depending on the order of compilation a bridge method is generated in A$Nested or B$Nested, but not both.

      $ cat I.java
      interface I<T> {
        void f(T t);
      }
      $ cat A.java
      class A implements I<Number> {
        public void f(Number x) {}
        static class Nested extends B {
        }
      }
      $ cat B.java
      class B implements I<Number> {
        public void f(Number x) {}
        static class Nested extends A {
        }
      }

      # pass A.java to javac first, A$Nested has a bridge method

      $ rm -f *.class
      $ javac I.java A.java B.java
      $ javap -private 'A$Nested'
      Compiled from "A.java"
      class A$Nested extends B {
        A$Nested();
        public void f(java.lang.Object);
      }
      $ javap -private 'B$Nested'
      Compiled from "B.java"
      class B$Nested extends A {
        B$Nested();
      }

      # pass B.java to javac first, B$Nested has a bridge method

      $ rm -f *.class
      $ javac I.java B.java A.java
      $ javap -private 'A$Nested'
      Compiled from "A.java"
      class A$Nested extends B {
        A$Nested();
      }
      $ javap -private 'B$Nested'
      Compiled from "B.java"
      class B$Nested extends A {
        B$Nested();
        public void f(java.lang.Object);
      }

            mcimadamore Maurizio Cimadamore
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: