From mike.yawn at oracle.com Fri Jan 23 12:00:35 2015 From: mike.yawn at oracle.com (Mike Yawn) Date: Fri, 23 Jan 2015 07:00:35 -0500 Subject: Issue with ObjectReferenceImpl.invokeMethod in jdk8 Message-ID: <54C237E3.9020502@oracle.com> (cross posting from serviceability-dev list; I was told I might have better luck here so apologies to anyone getting duplicates) I'm seeing a regression moving from JDK7 to JDK8u40 with the invocation of a method in an annotation from a debugger. I have a simple annotation class with two methods. There is a unit test that retrieves the annotations (getDeclaredAnnotations()). After retrieving the annotations, I try to call ObjectReference.invokeMethod() to invoke each of the annotation's methods. In JDK7 this worked; in JDK8 it fails with an IllegalAccessException: "Not a default method". I've looked at the source for com.sun.tools.jdi.ObjectReferenceImpl and see significant changes between JDK7 and JDK8 due to the introduction of interface methods in JDK8. In JDK7, all methods were class (as opposed to interface) methods and the validation of the annotation methods was successful. In JDK8, validateMethodInvocation has been rewritten to be a small method that forwards the validation to one of two new methods, validateClassMethodInvocation or validateIFaceMethodInvocation. The implementation of validateClassMethodInvocation appears to be the same as the pre-JDK8 validateMethodInvocation -- validation that the annotation method would pass. However, the annotation method is being treated as an interface method (because method.declaringType() instanceof InterfaceTypeImpl is true) and going through validateIFaceMethodInvocation. The test there is that method.isDefault() -- and the annotation method returns false, thus the exception is thrown. I'm not sure what the correct behavior is here, but there are a couple of possibilities: - If annotation classes were treated as classes, rather than interfaces, then we'd go through the same validation as before and this would work. - Alternately. if methods on annotations were considered default methods, then we'd pass the new validation. (The annotations do have a "default" value specified, but not all annotation methods will, so this seems a less satisfactory solution) - Or, the validateIFaceMethodInvocation may need a special test for annotation methods and validate them differently than interface methods. Do I need to file a bug for this, or is this mailing list a better place to report/discuss the issue, or am I doing something wrong that I just got away with in JDK7 but JDK8 is closing a loophole, so to speak? Thanks, Mike Yawn