Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

JDK-8289894: A NullPointerException thrown from guard expression #120

Closed
wants to merge 1 commit into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Jul 7, 2022

Consider the following code:

public class SwitchGuard {
    public static void main(String... args) {
        test(null);
    }
    private static void test(Object o) {
        switch (o) {
            case null, String s when s.isEmpty() -> System.err.println("OK.");
            default -> {}
        }
    }
}

In the current specification, the guard should not be invoked when o is null, but javac will invoke it, for historical reasons.

Also, as opposed to JDK 18/JEP 420, case null, <pattern> is allowed for parenthesized pattern when the parenthesized pattern encloses (directly or via other parenthesized patterns) a type pattern.

The patch proposed here strives to fix both of these problems.


Progress

  • 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

Issue

  • JDK-8289894: A NullPointerException thrown from guard expression

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk19 pull/120/head:pull/120
$ git checkout pull/120

Update a local copy of the PR:
$ git checkout pull/120
$ git pull https://git.openjdk.org/jdk19 pull/120/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 120

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk19/pull/120.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 7, 2022

👋 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 Jul 7, 2022
@openjdk
Copy link

openjdk bot commented Jul 7, 2022

@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 compiler-dev@openjdk.org label Jul 7, 2022
@mlbridge
Copy link

mlbridge bot commented Jul 7, 2022

Webrevs

@biboudis
Copy link
Member

biboudis commented Jul 8, 2022

LGTM 🎉

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 sensible

@openjdk
Copy link

openjdk bot commented Jul 8, 2022

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

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

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

8289894: A NullPointerException thrown from guard expression

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 9 new commits pushed to the master branch:

  • 460d879: 8289601: SegmentAllocator::allocateUtf8String(String str) should be clarified for strings containing \0
  • 732f106: 8289223: Canonicalize header ids in foreign API javadocs
  • ea21c46: 8289799: Build warning in methodData.cpp memset zero-length parameter
  • 6428607: 8289030: [macos] app image signature invalid when creating DMG or PKG
  • 1304390: 8289951: ProblemList jdk/jfr/api/consumer/TestRecordingFileWrite.java on linux-x64 and macosx-x64
  • 11319c2: 8278469: Test java/nio/channels/FileChannel/LargeGatheringWrite.java times out
  • 3212dc9: 8289486: Improve XSLT XPath operators count efficiency
  • a8eb728: 8289779: Map::replaceAll javadoc has redundant @throws clauses
  • 889150b: 8289558: Need spec clarification of j.l.foreign.*Layout

Please see this link for an up-to-date comparison between the source branch of this pull request and the master branch.
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 Jul 8, 2022
@lahodaj
Copy link
Contributor Author

lahodaj commented Jul 11, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Jul 11, 2022

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

  • b542bcb: 8289729: G1: Incorrect verification logic in G1ConcurrentMark::clear_next_bitmap
  • c86c51c: 8282071: Update java.xml module-info
  • 9981c85: 8290033: ProblemList serviceability/jvmti/GetLocalVariable/GetLocalWithoutSuspendTest.java on windows-x64 in -Xcomp mode
  • c142fbb: 8289697: buffer overflow in MTLVertexCache.m: MTLVertexCache_AddGlyphQuad
  • eeaf0bb: 8289872: wrong wording in @param doc for HashMap.newHashMap et. al.
  • 460d879: 8289601: SegmentAllocator::allocateUtf8String(String str) should be clarified for strings containing \0
  • 732f106: 8289223: Canonicalize header ids in foreign API javadocs
  • ea21c46: 8289799: Build warning in methodData.cpp memset zero-length parameter
  • 6428607: 8289030: [macos] app image signature invalid when creating DMG or PKG
  • 1304390: 8289951: ProblemList jdk/jfr/api/consumer/TestRecordingFileWrite.java on linux-x64 and macosx-x64
  • ... and 4 more: https://git.openjdk.org/jdk19/compare/8dd94a2c14f7456b3eaf3e02f38d9e114eb8acc3...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jul 11, 2022

@lahodaj Pushed as commit 25f4b04.

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
3 participants