RFR: 8351260: java.lang.AssertionError: Unexpected type tree: (ERROR) = (ERROR)

Vicente Romero vromero at openjdk.org
Thu Sep 4 22:28:34 UTC 2025


On Wed, 3 Sep 2025 05:48:51 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Consider a very broken declaration like this:
> 
> void test(List<@AlphaChars <@StringLength(int value = 5)String> s){ 
> 
> 
> after seeing `@AlphaChars`, javac will try to parse `<@StringLength(int value = 5)String>` as a type, and assign the annotation to the type. But, the text does not parse as a type well (partly due to the `int value = 5`), and the parsing will proceed in an expression mode. Then a search for target type is performed to attach the annotation, and that fails, as the expression tree is not expected to be part of the type.
> 
> The main proposal here is to wrap the badly parsed type in an `Erroneous` tree. The overall error recovery then seems to handle the situation well.
> 
> The situation produces quite a few error reports, but it is not clear if this situation (esp. the nested `int value = 5`) is common enough to stretch the parsing error recovery capabilities to accommodate this code.

lgtm

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/27065#pullrequestreview-3187407459


More information about the compiler-dev mailing list