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

Jan Lahoda jlahoda at openjdk.org
Wed Sep 3 05:54:31 UTC 2025


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.

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

Commit messages:
 - Adding more tests and a comment.
 - 8351260: java.lang.AssertionError: Unexpected type tree: (ERROR) = (ERROR)

Changes: https://git.openjdk.org/jdk/pull/27065/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=27065&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8351260
  Stats: 92 lines in 3 files changed: 90 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/27065.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/27065/head:pull/27065

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


More information about the compiler-dev mailing list