<div dir="ltr">Hello!<div><br></div><div>I stumbled on the following issue. Let's consider this Java file:</div><div><br></div><div>package com.example;<br><br>import java.lang.annotation.Retention;<br>import java.lang.annotation.Target;<br>import java.util.function.Function;<br><br>import static java.lang.annotation.ElementType.TYPE_USE;<br>import static java.lang.annotation.RetentionPolicy.RUNTIME;<br><br>@Retention(value=RUNTIME)<br>@Target(value={TYPE_USE})<br>@interface Anno {<br>}<br>public class TestClass {<br>    public static void main(String[] args) {<br>        Function<Integer, String> f = (@Anno var val ) -> Integer.toHexString(val);<br>        System.out.println(f.apply(10));<br>    }<br>}</div><div><br></div><div>As you can see, there's a TYPE_USE annotation which is applied to the lambda parameter declared with 'var' keyword. If I understand JLS 9.7.4 [1] correctly, this should not be legal:</div><div><br></div><div>> If the annotation appears before a void method declaration or a variable declaration that uses var (§14.4, §15.27.1), then there is no closest type. If the annotation's interface is deemed to apply only to the type which is closest to the annotation, a compile-time error occurs.</div><br><div>However, javac accepts this code. I tried different versions between Java 11 and Java 25, and the result is the same: the file is compiled successfully. However, the TestClass.class file contains no references to the Anno annotation at all, despite it having the RUNTIME retention. So it looks like the annotation is silently ignored.</div><div><br></div><div>One thing that confuses me is that the Eclipse compiler (ecj-4.34.jar) also accepts this code. However, it generates a RuntimeVisibleTypeAnnotations attribute for the Anno annotation. So either both compilers accept this code incorrectly, or my understanding of the specification is wrong. </div><div><br></div><div>Could you please take a look at the javac issue? I'd be happy to be corrected if I misunderstood the specification. Thank you in advance!</div><div><br></div><div>Tagir Valeev</div><div><br></div><div>[1] <a href="https://docs.oracle.com/javase/specs/jls/se25/html/jls-9.html#jls-9.7.4">https://docs.oracle.com/javase/specs/jls/se25/html/jls-9.html#jls-9.7.4</a></div></div>