JDK-8035567 : ObjectReference.invokeMethod() on default method throws ClassCastException
  • Type: Bug
  • Component: core-svc
  • Sub-Component: debugger
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-02-21
  • Updated: 2014-05-15
  • Resolved: 2014-05-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u20Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b129)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b69, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
When ObjectReference.invokeMethod() is called with a default method that resolves to an interface implementation as the Method parameter, a ClassCastException is thrown. If the default method resolves to an overriding implementation in a concrete class, everything works as expected.

From 8031195 I see that InterfaceType.invokeMethod() will not be added soon, but the call should still succeed on an appropriate ObjectReference.

At the very least, IllegalArgumentException should be thrown instead, for compatibility with existing tools.

Also, in the future, INVOKE_NONVIRTUAL should be supported for ObjectReference.invokeMethod() when called with a default method.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
compile source code
run:  jdb InvokeMethodBug
do:   stop at InvokeMethodBug:6
        run
        eval p.negate();

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Successful evaluation.
ACTUAL -
jdb reports a ClassCastException

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Here is a stack dump from a similar procedure using the jGRASP debugger:
-------------------------------------------------------------------------------------------------

java.lang.ClassCastException: com.sun.tools.jdi.InterfaceTypeImpl cannot be cast to com.sun.tools.jdi.ClassTypeImpl
	at com.sun.tools.jdi.ObjectReferenceImpl.validateMethodInvocation(ObjectReferenceImpl.java:328)
	at com.sun.tools.jdi.ObjectReferenceImpl.invokeMethod(ObjectReferenceImpl.java:381)
	at grasp.debugger.JdiDebug.handleInvokeMethod(JdiDebug.java:10895)
...

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.util.function.Predicate;

public class InvokeMethodBug {
   public static void main(String[] args) {
      Predicate p = (n)->true;
      p.negate();
   }
}
---------- END SOURCE ----------