<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Hello Bjorn,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
In JVMS 4.7, there's a minor provision right above this table <a href="https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.7-300" title="https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.7-300">
https://docs.oracle.com/javase/specs/jvms/se23/html/jvms-4.html#jvms-4.7-300</a>:</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
> An implementation of the Java Virtual Machine may use the information that these attributes contain, or otherwise must silently ignore these attributes.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
This means that if an annotation class is absent, the JVM will never fail. (In fact, a missing annotation interface means that the attribute itself is still conformant.) Otherwise, the JVM doesn't care about the annotations.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
The annotation parsing is handled by core libraries, specifically, core reflection. The specification for parsing is available at
<a href="https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/reflect/AnnotatedElement.html" id="OWA68b299ac-dc03-83de-2fa1-d24bbaa7635a" class="OWAAutoLink">
https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/lang/reflect/AnnotatedElement.html</a></div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
It appears that this specification does not mention what happens when the annotation interface of an annotation in the class file attribute cannot be found. The reference implementation omits such annotations:
<a href="https://github.com/openjdk/jdk/blob/fc7244da96a9423146c4a46bcc3bbfc205900c3b/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java#L185" id="OWA36b77b6a-2430-80f3-a146-c7e1c6c61c0e" class="OWAAutoLink">
https://github.com/openjdk/jdk/blob/fc7244da96a9423146c4a46bcc3bbfc205900c3b/src/java.base/share/classes/sun/reflect/annotation/AnnotationParser.java#L185</a> and is verified by a
<code>MissingTest.java</code></div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
For history, per <a href="https://bugs.openjdk.org/browse/JDK-6322301">https://bugs.openjdk.org/browse/JDK-6322301</a> it seems that ignoring is the correct way; but people seem to just have forgotten to add it to the specification of AnnotatedElement.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
So, in conclusion, skipping is the right way and enforced by tests. We probably should make it to the core reflection specification. Please send future discussion to the core-libs-dev list, as this problem now becomes specific to core reflection.</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Regards,</div>
<div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
Chen</div>
<div id="appendonsend"></div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> jdk-dev <jdk-dev-retn@openjdk.org> on behalf of Björn Kautler <Bjoern@kautler.net><br>
<b>Sent:</b> Monday, October 7, 2024 9:45 AM<br>
<b>To:</b> jdk-dev@openjdk.org <jdk-dev@openjdk.org><br>
<b>Subject:</b> Specification of handling of absent annotations at runtime</font>
<div> </div>
</div>
<div>
<div dir="ltr">Hi
<div><br>
</div>
<div>Is there somewhere some definition how a JRE has to handle absent annotation classes at runtime?<br>
All JREs I know just skip annotations if their class is not present at runtime.<br>
But as far as I have seen neither the JLS nor the JVMS define how the situation has to be handled.<br>
Can anyone tell me, whether there is some specification or JCK rule or similar that definitely defines that this is the way how absent annotation classes have to be handled?<br>
<br>
Cheers</div>
<div>Björn</div>
<div><br>
</div>
</div>
</div>
</body>
</html>