Regression in JDK8 build 78: javac complains about missing Class#isAnnotationPresent

Joe Darcy joe.darcy at oracle.com
Thu Feb 28 22:21:41 PST 2013


On 2/28/2013 6:05 PM, David M. Lloyd wrote:
> On 02/28/2013 07:25 PM, Joe Darcy wrote:
>> As for the technical details of what is going on, the
>> isAnnotationPresent method in the java.lang.reflect.AnnotatedElement
>> interface has been turned into a default method:
>>
>>       http://bugs.sun.com/view_bug.do?bug_id=8007113
>>
>> This change was introduced in b77 and allows some sharing of code among
>> the various classes implementing AnnotatedElement, including
>> java.lang.Class, java.lang.reflect.{Method, Constructor}.
>>
>> For reasons I'll describe shortly, when compiling under a -source
>> setting earlier than source 8, code that references isAnnotationPresent
>> in the implementing classes (or the declaring interface) will not see
>> the method as being present. Code that does not reference this method
>> will continue to compile under "-source OLD -target OLD" (with the usual
>> caveats) and code that references this method will see the method as
>> expected under -source 8.
>
> Is this something which only occurs at compile time, or will runtime 
> code which does invokevirtual on Class#isAnnotationPresent() blow up 
> with the same sort of exception?

This situation is only a problem if you compile with a source/target 
that is downrev with respect to the classes on the bootclasspath. If you 
compile with a consistent source / target / bootclasspath you are fine 
and if you run old class files on JDK 8 you are also fine.

>   If so then the method ought to be retained on this class, with an 
> upcall to the default implementation.
>
> Do we have any sort of document which covers runtime (binary) 
> compatibility considerations for 8 in general, or the new lambda 
> functionality in particular?
>

I expect there will be updates to JLS chapter 13 to cover changed binary 
compatibility considerations. Of course default methods are intended to 
allow smoother evolution of interfaces. The hiccup here is where an 
existing interface method was replaced by a default one AND not 
compiling under source 8 where default methods are fully visible to the 
code being compiled.

Cheers,

-Joe




More information about the compiler-dev mailing list