JDK-8078256 : Javac uses instantiated signatures when merging abstract most-specific methods
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 8-pool
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-04-20
  • Updated: 2015-04-21
  • Resolved: 2015-04-21
Related Reports
Duplicate :  
Relates :  
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.



Comments
1. Run the attached test case (Bug.java). 2. Checked this with JDK 8u40, 8u45, 8u60 ea b10 and 9 ea b60 in Windows 7 and Linux (64-bit). 8u40: FAIL 8u45: FAIL 8u60 ea b10: FAIL 9 ea b60: Ok 3. Output with JDK 8u45: --------------------------------------------------------------------------------------------------------------------------------------------------- >java Bug Exception in thread "main" java.lang.NoSuchMethodError: Bug$Child.process()Ljava/lang/String; at Bug.main(Bug.java:26) --------------------------------------------------------- Output with JDK 9 ea b60: --------------------------------------- >java Bug null ----------------------------------------------------------------------------------------------------------------------------------------------- Conclusion: Based upon above results, the issue is reproducible with JDK 8u45 and 8u60 ea b10. This is fixed in JDK 9 ea b60 though as claimed by the submitter.
21-04-2015