RFR: 8297118: Change IncompatibleClassChangeError to MatchException for exhaustive switch statements and switch expressions

Jan Lahoda jlahoda at openjdk.org
Thu Nov 17 13:43:26 UTC 2022


On Thu, 17 Nov 2022 00:54:37 GMT, Joe Darcy <darcy at openjdk.org> wrote:

>> As per recent update of the JEP 433 specification, javac should use MatchException instead of IncompatbileClassChangeError to flag switches over enum values that were exhaustive at compile time, but no longer are exhaustive at runtime. This patch implements that change.
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 131:
> 
>> 129:             options.getBoolean("optimizeOuterThis", false);
>> 130:         disableProtectedAccessors = options.isSet("disableProtectedAccessors");
>> 131:         Source source = Source.instance(context);
> 
> Does this merit addition of a feature-enum constant in the usual way?

I was thinking of this, but opted to reuse the existing feature constant, as this is not a separate user-selectable feature, but rather part of the patterns in switch feature. Also, each feature enum constant must a diagnostic set, and as it would never be part of any diagnostic, it would be impossible to test.

It is possible to have a separate constant if desired, though.

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

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


More information about the compiler-dev mailing list