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

Javac uses instantiated signatures when merging abstract most-specific methods

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 8-pool
    • Fix Version/s: None
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_7

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_05"
      Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      We were trying to upgrade from Java 7 to Java 8. The code compiled fine, but one of the unit tests failed. After debugging and searching the internet, I found that someone else ran into this problem using open JDK. They were also upgrading from open JDK 7 to open JDK 8. They filed a bug, and it was fixed in open JDK 9. It doesn't appear to have been back ported to version 8.

      Here's the bug report:

      https://bugs.openjdk.java.net/browse/JDK-8064803


      I took the code that they posted for reproducing the problem and sure enough, I got the same result. It compiles, but doesn't run. I tried Java 7 v60, it compiled and ran. I tried Java 8 v5, v31, and the pre-release of 60v, they all compiled, but they all failed to run.


      REGRESSION. Last worked in version 7u75

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_60"
      Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
      Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create two Interfaces that use generics.
      In both both interfaces, define one or more methods whose return type is the generic.
      Write a third Interface that uses the generic and extends the other two interfaces.
      Don't define any methods in the third interface. That is, do NOT redefine the methods that are in the other two interfaces.
      Last, define a class that implements the third interface.

      The code will compile, but will fail to run when it attempts to execute one of the methods that returns a generic type.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The program runs and completes printing "null".
      ACTUAL -
      The program failed to run with an error message.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      This is the run time error:

      Exception in thread "main" java.lang.NoSuchMethodError: Bug$Child.process()Ljava/lang/String;
              at Bug.main(Bug.java:28)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.Collection;
      import java.util.Iterator;
      import java.util.List;
      import java.util.ListIterator;

      public class Bug
      {
          public static interface ParentA<T> {
              T process() throws Exception;
          }

          public static interface ParentB<T> {
              T process() throws Exception;
          }

          public static interface Child<T> extends ParentA<T>, ParentB<T> {
          }

          public static class ChildImpl<T> implements Child<T> {
              @Override
              public T process() { return null; }
          }
          
         public static void main(String[] args) throws Exception {
              Child<String> child = new ChildImpl<String>();
              String result = child.process();
              System.err.println(result);
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      A workaround:

      Inside the third interface, define the methods that are defined in the other two interfaces.

      That is, if you change the code so that the Child interface defines the method

               T process() throws Exception;

      Then the problem stops.


        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: