Integrated: 8221580: Confusing diagnostic for assigning a static final field in a constructor
Archie L. Cobbs
duke at openjdk.org
Mon Feb 6 18:26:00 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`.
This pull request has now been integrated.
Changeset: 8c01b6e6
Author: Archie L. Cobbs <archie.cobbs at gmail.com>
Committer: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/8c01b6e66b1ce9f9df5a1d12c8717a9e3322948a
Stats: 25 lines in 11 files changed: 10 ins; 0 del; 15 mod
8221580: Confusing diagnostic for assigning a static final field in a constructor
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/12411
More information about the compiler-dev
mailing list