RFR: 8221580: Confusing diagnostic for assigning a static final field in a constructor
Archie L. Cobbs
duke at openjdk.org
Fri Feb 3 17:41:31 UTC 2023
When a program attempts to assign a value to a final field, javac reports `cannot assign a value to final variable x`.
If the field is `static`, the exact same error message is used, which can be confusing, because no mention is made of the field's `static`ness.
This change does two things:
* Refactor the error message so that arbitrary modifiers can be included, instead of hard-wiring `final`
* Include both `static final` in the error message in the case of `static final` variables.
So for a `static final` field the error is now `cannot assign a value to static final variable x`.
-------------
Commit messages:
- Distinguish static fields in "can't assign to final variable" error message.
- Refactor error message to display arbitrary modifiers, not just 'final'.
Changes: https://git.openjdk.org/jdk/pull/12411/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=12411&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8221580
Stats: 25 lines in 11 files changed: 10 ins; 0 del; 15 mod
Patch: https://git.openjdk.org/jdk/pull/12411.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/12411/head:pull/12411
PR: https://git.openjdk.org/jdk/pull/12411
More information about the compiler-dev
mailing list