Skip to content

8385017: Null pointer dereference in java.desktop/share/classes/com/sun/media/sound/ModelByteBuffer.java:204#31299

Open
prrace wants to merge 2 commits into
openjdk:masterfrom
prrace:mbb
Open

8385017: Null pointer dereference in java.desktop/share/classes/com/sun/media/sound/ModelByteBuffer.java:204#31299
prrace wants to merge 2 commits into
openjdk:masterfrom
prrace:mbb

Conversation

@prrace
Copy link
Copy Markdown
Contributor

@prrace prrace commented May 27, 2026

A fix for a theoretical NPE because a method might return null and it is used.



Progress

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

Issue

  • JDK-8385017: Null pointer dereference in java.desktop/share/classes/com/sun/media/sound/ModelByteBuffer.java:204 (Bug - P3)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 31299

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link
Copy Markdown

bridgekeeper Bot commented May 27, 2026

👋 Welcome back prr! 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
Copy Markdown

openjdk Bot commented May 27, 2026

❗ This change is not yet ready to be integrated.
See the Progress checklist in the description for automated requirements.

@openjdk openjdk Bot changed the title 8385017 8385017: Null pointer dereference in java.desktop/share/classes/com/sun/media/sound/ModelByteBuffer.java:204 May 27, 2026
@openjdk openjdk Bot added the client client-libs-dev@openjdk.org label May 27, 2026
@openjdk
Copy link
Copy Markdown

openjdk Bot commented May 27, 2026

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

  • client

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
Copy link
Copy Markdown

openjdk Bot commented May 27, 2026

The total number of required reviews for this PR has been set to 2 based on the presence of this label: client. This can be overridden with the /reviewers command.

@openjdk openjdk Bot added the rfr Pull request is ready for review label May 27, 2026
@@ -201,6 +201,9 @@ public ModelByteBuffer(File file, long offset, long len) {
public void writeTo(OutputStream out) throws IOException {
if (root.file != null && root.buffer == null) {
try (InputStream is = getInputStream()) {
if (is == null) {
throw new IOException("null stream");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was the actual complaint

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That getInputStream method is used in a few other places that can also not be ready for null.
It can return null because it catches the IOException and returns null instead. Maybe it would be better to just throw the IOException there, instead of returning null and then checking and throwing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

But I also noticed this case which I decided to fix too.
However the DataInputStream constructor accepts null .. but the readFully() call will throw an NPE so I had to handle it there since it was not so obvious how to check for null inside the try(..)
I also filed a bug against DataInputStream
https://bugs.openjdk.org/browse/JDK-8385487

@mlbridge
Copy link
Copy Markdown

mlbridge Bot commented May 27, 2026

Webrevs

@@ -209,8 +210,12 @@ public AudioFloatInputStream openStream() {
return AudioFloatInputStream.getInputStream(ais);
}
if (buffer.array() == null) {
InputStream is = buffer.getInputStream();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this seems to be the same "buffer.getInputStream" use above?

@@ -209,8 +210,12 @@ public AudioFloatInputStream openStream() {
return AudioFloatInputStream.getInputStream(ais);
}
if (buffer.array() == null) {
InputStream is = buffer.getInputStream();
if (is == null) {
return null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is only used in SoftAbstractResampler. And when this one returns null, that will throw NPE:

            stream = osc.openStream();
...
            samplerateconv = stream.getFormat().getSampleRate() / outputsamplerate;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

client client-libs-dev@openjdk.org rfr Pull request is ready for review

Development

Successfully merging this pull request may close these issues.

2 participants