RFR: 8295024: Cyclic constructor error is non-deterministic and inconsistent
Archie L. Cobbs
duke at openjdk.org
Wed Oct 12 14:32:43 UTC 2022
This patch addresses two related issues that cause javac's reporting of recursive constructor errors to be non-deterministic.
The first issue is caused by the use of a `HashMap` when finding cycles in the graph of constructor invocations. This causes non-determinism in which constructor is identified as the "culprit" for the purposes of error reporting. The obvious fix here is to use a `LinkedHashMap` instead.
The second problem is caused by how the error's source code location is found via `TreeInfo.diagnosticPositionFor()`. That method searches the AST for a node matching the constructor's `Symbol`, but both the constructor declaration and all of its invocations will match that `Symbol`, and so whichever of those happens first in the source code wins.
The fix adds an optional filter parameter to `TreeInfo.diagnosticPositionFor()`, and then uses it to match only the constructor invocation. Reporting the invocation instead of the declaration is preferred because it provides more specific information about exactly how the recursion occurs. Put another way, when identifying a cycle in a graph, reporting an edge is more helpful than reporting a node.
-------------
Commit messages:
- 8295024: Cyclic constructor error is non-deterministic and inconsistent
Changes: https://git.openjdk.org/jdk/pull/10679/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=10679&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8295024
Stats: 103 lines in 4 files changed: 76 ins; 0 del; 27 mod
Patch: https://git.openjdk.org/jdk/pull/10679.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/10679/head:pull/10679
PR: https://git.openjdk.org/jdk/pull/10679
More information about the compiler-dev
mailing list