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

8308167: SequencedMap::firstEntry throws NPE when first entry has null key or value #14278

Conversation

stuart-marks
Copy link
Member

@stuart-marks stuart-marks commented Jun 2, 2023

Create and use new NullableKeyValueHolder class to accommodate map entries whose key or value might be null.


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-8308167: SequencedMap::firstEntry throws NPE when first entry has null key or value

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14278

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14278.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 2, 2023

👋 Welcome back smarks! 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
Copy link

openjdk bot commented Jun 2, 2023

@stuart-marks The following label will be automatically applied to this pull request:

  • core-libs

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 core-libs core-libs-dev@openjdk.org label Jun 2, 2023
@stuart-marks stuart-marks marked this pull request as ready for review June 2, 2023 06:35
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 2, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 2, 2023

Webrevs

Copy link
Member

@bchristi-git bchristi-git left a comment

Choose a reason for hiding this comment

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

Changes look good.

An observation:
TreeMap implements SequencedMap, and I see that its firstEntry() and related methods use AbstractMap.SimpleImmutableEntry (via exportEntry()), despite it being serializable. However, this is long-standing code (from 1.6, perhaps?), and TreeMap is itself serializable. So, leaving it as is seems the right thing to do.

Comment on lines +41 to +65
* This class is not exported. Instances are created by various Map implementations
* when they need a Map.Entry that isn't connected to the Map.
*
* <p>This class differs from AbstractMap.SimpleImmutableEntry in that it is not
* serializable and that it is final. This class differs from java.util.KeyValueHolder
* in that the key and value are nullable.
*
* <p>In principle this class could be a variation on KeyValueHolder. However,
* making that class selectively support nullable keys and values is quite intricate.
* Various specifications (such as Map.ofEntries and Map.entry) specify non-nullability
* of the key and the value. Map.Entry.copyOf also requires non-null keys and values;
* but it simply passes through KeyValueHolder instances, assuming their keys and values
* are non-nullable. If a KVH with nullable keys and values were introduced, some way
* to distinguish it would be necessary. This could be done by introducing a subclass
* (requiring KVH to be made non-final) or by introducing some kind of "mode" field
* (potentially increasing the size of every KVH instance, though another field could
* probably fit into the object's padding in most JVMs.) More critically, a mode field
* would have to be checked in all the right places to get the right behavior.
*
* <p>A longer range possibility is to selectively relax the restrictions against nulls in
* Map.entry and Map.Entry.copyOf. This would also require some intricate specification
* changes and corresponding implementation changes (e.g., the implementations backing
* Map.of might still need to reject nulls, and so would Map.ofEntries) but allowing
* a Map.Entry itself to contain nulls seems beneficial in general. If this is done,
* merging KeyValueHolder and NullableKeyValueHolder should be reconsidered.
Copy link
Member

Choose a reason for hiding this comment

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

I think having this background and explanation in the docs for this internal class is fine.
IMO, this information would also be useful to have in the bug report.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add a note to the bug report pointing to this rationale.

@openjdk
Copy link

openjdk bot commented Jun 5, 2023

@stuart-marks 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:

8308167: SequencedMap::firstEntry throws NPE when first entry has null key or value

Reviewed-by: bchristi

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

  • b3c9d67: 8309136: [JVMCI] add -XX:+UseGraalJIT flag
  • 98b53c0: 8306112: Implementation of JEP 445: Unnamed Classes and Instance Main Methods (Preview)
  • e970ddb: 8309170: CDS archive heap is always relocated for larger heap
  • 4b8922f: 8308842: Consolidate exceptions thrown from Class-File API
  • 2b38343: 8309416: Misstatement in semantics of methods in javax.lang.model.ElementFilter
  • 73352b6: 8280994: [XWayland] Drag and Drop does not work in java -> wayland app direction
  • 5cd8af7: 8308726: RISC-V: avoid unnecessary slli in the vectorized arraycopy stubs for bytes
  • 80232b7: 8308969: make test-prebuilt doesn't return the correct exit code
  • 6d511f1: 8309129: AArch64: guarantee(T != T2S) failed: "incorrect arrangement" after JDK-8307795
  • 9be5769: 8291966: SwitchBootstrap.typeSwitch could be faster
  • ... and 80 more: https://git.openjdk.org/jdk/compare/de7fd1c3061cfbfdbd5d7cc2b1ba0ee8d432ee0a...master

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 5, 2023
@stuart-marks
Copy link
Member Author

Thanks for looking at this.

Yeah, the serializability of various Entry objects that are exposed through the APIs is all over the map, so to speak. Note that entries obtained from the entrySet() of HashMap and TreeMap are not serializable. These are actual internal nodes of the respective Map implementations. But TreeMap uses AbstractMap.SimpleImmutableEntry in several places to disconnect the returned entry from the map, and that class is serializable. Oh well. (And yes that code dated back to the beginning of the available OpenJDK history, which puts it at JDK 1.6 or at least certainly before 7.)

@stuart-marks
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 6, 2023

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

  • 4b15349: 8304438: jcmd JVMTI.agent_load should obey EnableDynamicAgentLoading
  • b3c9d67: 8309136: [JVMCI] add -XX:+UseGraalJIT flag
  • 98b53c0: 8306112: Implementation of JEP 445: Unnamed Classes and Instance Main Methods (Preview)
  • e970ddb: 8309170: CDS archive heap is always relocated for larger heap
  • 4b8922f: 8308842: Consolidate exceptions thrown from Class-File API
  • 2b38343: 8309416: Misstatement in semantics of methods in javax.lang.model.ElementFilter
  • 73352b6: 8280994: [XWayland] Drag and Drop does not work in java -> wayland app direction
  • 5cd8af7: 8308726: RISC-V: avoid unnecessary slli in the vectorized arraycopy stubs for bytes
  • 80232b7: 8308969: make test-prebuilt doesn't return the correct exit code
  • 6d511f1: 8309129: AArch64: guarantee(T != T2S) failed: "incorrect arrangement" after JDK-8307795
  • ... and 81 more: https://git.openjdk.org/jdk/compare/de7fd1c3061cfbfdbd5d7cc2b1ba0ee8d432ee0a...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 6, 2023

@stuart-marks Pushed as commit 6d155a4.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

2 participants