RFR: 8221580: Confusing diagnostic for assigning a static final field in a constructor

Archie L. Cobbs duke at openjdk.org
Mon Feb 6 15:02:51 UTC 2023


On Fri, 3 Feb 2023 17:33:34 GMT, Archie L. Cobbs <duke at openjdk.org> wrote:

> 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`.

Thanks for the review.

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

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


More information about the compiler-dev mailing list