RFR: 8296010: AssertionError in annotationTargetType [v4]

Jonathan Gibbons jjg at openjdk.org
Thu Feb 16 16:54:29 UTC 2023


On Wed, 1 Feb 2023 14:06:15 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> javac is crashing if a class file is forged so that an annotation can be applicable to an unknown target. It would be equivalent to the following declaration:
>> 
>> 
>> @Target({ElementType.FIELD, ElementType.NO_SUCH})
>> @interface A {}
>> 
>> if the compiler process this source it would issue a compiler error, indicating that symbol `NO_SUCH` cant be found. Currently our class reader just issues a warning and move on. This is OK as it could be that the loaded class won't be used anyway but if this annotation is actually applied to symbol as in:
>> 
>> 
>> class B {
>>     @A Object o;
>> }
>> 
>> then this to my understanding should be a compilation error. Currently javac is crashing and this is not acceptable, so this PR is fixing this issue so that a compilation error is issued instead.
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
> 
>   minor update

Approved, with a minor suggestion to tweak the error message.

src/jdk.compiler/share/classes/com/sun/tools/javac/resources/compiler.properties line 160:

> 158: # 0: type, 1: name
> 159: compiler.err.annotation.unrecognized.attribute.name=\
> 160:     annotation @{0} has an unrecognizable attribute named ''{1}''

"unrecognizable" seems a strange word here;  would "unknown" be a better word?

-------------

Marked as reviewed by jjg (Reviewer).

PR: https://git.openjdk.org/jdk/pull/12241


More information about the compiler-dev mailing list