RFR: 8279673: AudioClip.play doesn't work due to NullPointerException when creating DataPusher

Sergey Bylokhov serb at openjdk.java.net
Mon Jan 10 11:06:09 UTC 2022


On Sun, 14 Nov 2021 20:02:27 GMT, Andrey Turbanov <duke at openjdk.java.net> wrote:

> There is possible NPE, when trying to play AudioClip
> 
> import java.applet.AudioClip;
> import java.io.IOException;
> import java.net.URL;
> 
> 
> public class AudioNpe {
>     public static void main(String[] args) throws IOException, InterruptedException {
>         URL url = new URL("https://file-examples-com.github.io/uploads/2017/11/file_example_WAV_1MG.wav");
>         AudioClip content = (AudioClip)url.getContent();
>         content.play();
> 
>         Thread.sleep(10000L);
>     }
> }
> 
> 
> 	  at java.lang.Thread.<init>(Thread.java:393)
> 	  at java.lang.Thread.<init>(Thread.java:760)
> 	  at com.sun.media.sound.JSSecurityManager.createThread(JSSecurityManager.java:115)
> 	  at com.sun.media.sound.DataPusher.start(DataPusher.java:117)
> 	  - locked <0x955> (a com.sun.media.sound.DataPusher)
> 	  at com.sun.media.sound.JavaSoundAudioClip.startImpl(JavaSoundAudioClip.java:202)
> 	  - locked <0x95e> (a com.sun.media.sound.JavaSoundAudioClip)
> 	  at com.sun.media.sound.JavaSoundAudioClip.play(JavaSoundAudioClip.java:152)
> 	  at main.java.AudioNpe.main(AudioNpe.java:12)
> 
> 
> It happens because of bug in `com.sun.media.sound.JSSecurityManager#createThread` implementation: variable `String name`, which supposed to be used - actually unused and `null` thread name is passed to `Thread` constructor.
> 
> After fix - audio clip plays without problems.

As a test, you can use the logic similar to this one: https://github.com/openjdk/jdk/blob/bd92674be563ad291990216b7cdf061c498f5dd3/test/jdk/javax/sound/sampled/Clip/AutoCloseTimeCheck.java#L50
Just the file should be big enough (>1MB) to provoke the usage of DataPusher instead of "in memory clip".

@turbanoff do you plan to update the PR?

src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java line 115:

> 113:                                final boolean doStart)
> 114:     {
> 115:         String name = (threadName != null) ? threadName : "JSSM Thread";

Probably it will be better to leave this check as is, and just use the "name" var as a parameter to the new Thread, so it will prevent any similar issues in the future.

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

PR: https://git.openjdk.java.net/jdk/pull/6382



More information about the client-libs-dev mailing list