Currently annotations on local variables do not exist
beyond the source code.
However, the JLS defines no special processing of the local variable annotation. So IMHO the fact that the local variable annotation are not processed according to their Retention Policy is a bug in a java compiler.
There is a limitation being exposed here, but no bug. The limitation
is in the classfile format. There was no straightforward way to
represent local variables and their annotations, so no such
representation was defined. Accordingly, the JLS 3 says this about
annotation types with RUNTIME retention:
"An annotation on a local variable declaration is never
retained in the binary representation."
There was no straightforward way to represent local variables and their
annotations, so no such representation was defined.
To me, that's a completely bogus argument. Sun easily could have defined another attribute, similar to the LocalVariableTable, that contains information about a local variable and its annotation.
I was really excited about all the possibilities of Java annotations... until I noticed this grave oversight.
Using material Sun provided under the Java Research License (JRL), I have developed a modified version of the Java compiler that encodes annotations on local variables into class files.
For more information, I would like to direct your attention to the following thread on this forum: