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

JDI ObjectReferenceImpl.invokeMethod() validation fails for virtual invocations of method with declaring type being an interface

    XMLWordPrintable

Details

    • b08
    • Verified

    Backports

      Description

        Bug came in through another system. Bug Description:

        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.

        Attachments

          Issue Links

            Activity

              People

                jbachorik Jaroslav Bachorík
                shadowbug Shadow Bug
                Votes:
                0 Vote for this issue
                Watchers:
                9 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: