Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8311038: Incorrect exhaustivity computation #14711

wants to merge 1 commit into from


Copy link

@lahodaj lahodaj commented Jun 29, 2023

Consider this code:

public class Test {

    record Rec(Object t) {}

    private void test2() {
        Rec r = new Rec("test");
        int res = switch (r) {
            case Rec(String x): {
                yield x.length();
            case Rec(Object x): {
                yield -3;


It is obviously exhaustive (there's Rec(Object x), which is unconditional on Rec), but javac fails to compile this code:

/tmp/ error: the switch expression does not cover all possible input values
        int res = switch (r) {
1 error

The cause seems to be that when binding patterns for the (nested) String and Object are reduced, they are reduced to String and ConstantDesc, which is no longer exhaustive for Object.

This is a result of this code:

if (types.isSubtype(types.erasure(perm.type),

which is intended to help with patterns that don't stand directly in the selector's hierarchy, like:
public void testComplexSubTypes5(Path base) throws Exception {

where I3 is only related to the selector (I) via a permitted subtype.

Part of the problem is that Object is removed from the pattern set - adding ConstantDesc is not a problem. The proposal in this patch is to keep supertypes of the type that is being added in the pattern set. This will lead to pattern set ConstantDesc, Object and String, which should be OK for correctness, although generally enhancing the pattern set might slow down the processing.

There are two complicating factors, which make the observed bug surprising and difficult to diagnose:

  • if (in this example) ConstantDesc has not been completed yet, .isSealed() will return false for it, and the code will compile. This may happen when x.length() is removed/replaced in the example. This patch proposes to complete the Symbols before checking for sealedness.
  • it appears to be difficult to reproduce with a synthetic testcase, due to variations in ordering in maps. Hence this patch is using String in the testcase, as opposed to a test-only class.


  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue


  • JDK-8311038: Incorrect exhaustivity computation (Bug - P2)



Using git

Checkout this PR locally:
$ git fetch pull/14711/head:pull/14711
$ git checkout pull/14711

Update a local copy of the PR:
$ git checkout pull/14711
$ git pull pull/14711/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14711

View PR using the GUI difftool:
$ git pr show -t 14711

Using diff file

Download this PR as a diff file:


Link to Webrev Comment

Copy link

bridgekeeper bot commented Jun 29, 2023

👋 Welcome back jlahoda! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 29, 2023
Copy link

openjdk bot commented Jun 29, 2023

@lahodaj The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler label Jun 29, 2023
Copy link

mlbridge bot commented Jun 29, 2023


Copy link

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good

Copy link

openjdk bot commented Jun 29, 2023

@lahodaj This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file for details.

After integration, the commit message for the final commit will be:

8311038: Incorrect exhaustivity computation

Reviewed-by: vromero

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 102 new commits pushed to the master branch:

  • 05c2b6c: 8309979: BootstrapMethods attribute is missing in class files recreated by SA
  • 20f7d05: 8310502: Optimization for j.l.Long.fastUUID()
  • 07734f6: 8310848: Convert ClassDesc and MethodTypeDesc to be stored in static final fields
  • e5744b8: 8310919: runtime/ErrorHandling/ times out due to core dumps taking a long time on OSX
  • 98a954e: 8308286: Fix clang warnings in linux code
  • f842ec4: 8305667: Some fonts installed in user directory are not detected on Windows
  • 690d626: 8307927: C2: "malformed control flow" with irreducible loop
  • be64d3a: 8310299: C2: 8275201 broke constant folding of array store check in some cases
  • b2eae16: 8295191: IR framework timeout options expect ms instead of s
  • af319d9: 8311064: Windows builds fail without precompiled headers after JDK-8310728
  • ... and 92 more:

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Jun 29, 2023
Copy link
Contributor Author

lahodaj commented Jul 14, 2023


Copy link

openjdk bot commented Jul 14, 2023

Going to push as commit bbb7ce5.
Since your change was applied there have been 227 commits pushed to the master branch:

  • 2e12a12: 8281658: Add a security category to the java -XshowSettings option
  • 43099a8: 8311647: Memory leak in Java_jdk_internal_org_jline_terminal_impl_jna_linux_CLibraryImpl_ttyname_1r
  • c7c6d47: 6355567: AdobeMarkerSegment causes failure to read valid JPEG
  • af7f95e: 8310070: Test: javax/net/ssl/DTLS/ timed out
  • c710e71: 8311102: Write annotations in the classfile dumped by SA
  • 61932f4: 8244289: fatal error: Possible safepoint reached by thread that does not allow it
  • 8c9d091: 8308047: java/util/concurrent/ScheduledThreadPoolExecutor/ timed out and also had jcmd pipe errors
  • b587fc5: 8312013: avoid warning: 'linux' is not defined on AIX
  • 135f64e: 8311583: tableswitch broken by JDK-8310577
  • 6895deb: 8311536: JFR TestNativeMemoryUsageEvents fails in huge pages configuration
  • ... and 217 more:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Jul 14, 2023
@openjdk openjdk bot closed this Jul 14, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Jul 14, 2023
Copy link

openjdk bot commented Jul 14, 2023

@lahodaj Pushed as commit bbb7ce5.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Copy link
Contributor Author

lahodaj commented Jul 14, 2023

/backport jdk21

Copy link

openjdk bot commented Jul 14, 2023

@lahodaj the backport was successfully created on the branch lahodaj-backport-bbb7ce51 in my personal fork of openjdk/jdk21. To create a pull request with this backport targeting openjdk/jdk21:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit bbb7ce51 from the openjdk/jdk repository.

The commit being backported was authored by Jan Lahoda on 14 Jul 2023 and was reviewed by Vicente Romero.


If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21:

$ git fetch lahodaj-backport-bbb7ce51:lahodaj-backport-bbb7ce51
$ git checkout lahodaj-backport-bbb7ce51
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push lahodaj-backport-bbb7ce51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
compiler integrated Pull request has been integrated
2 participants