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

Jan Lahoda jlahoda at openjdk.org
Mon Sep 8 06:36:18 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.

This pull request has now been integrated.

Changeset: f9dc640e
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/f9dc640ef07ea5569b3581360041db2bb7e30c40
Stats:     92 lines in 3 files changed: 90 ins; 0 del; 2 mod

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

Reviewed-by: vromero

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

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


More information about the compiler-dev mailing list