<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello,<br>
<br>
Could you please review the following fix for the bug.<br>
<br>
Bug: <a class="moz-txt-link-freetext" href="https://bugs.openjdk.java.net/browse/JDK-8168751">https://bugs.openjdk.java.net/browse/JDK-8168751</a><br>
Webrev: <a class="moz-txt-link-freetext" href="http://cr.openjdk.java.net/~alitvinov/8168751/jdk9/webrev.00">http://cr.openjdk.java.net/~alitvinov/8168751/jdk9/webrev.00</a><br>
<br>
The bug consists in the fact that after many repetitive sequential
calls to the methods "loop()", "stop()" on the same instance of
"java.applet.AudioClip" at some moment two threads with the name
"Direct Clip", which play this "AudioClip" instance, are created and
start existing in parallel, what makes the being played clip sound
as corrupted.<br>
<br>
"Direct Clip" thread is represented by the instance variable
"com.sun.media.sound.DirectAudioDevice.DirectClip.thread", is
created in the method
"com.sun.media.sound.DirectAudioDevice.DirectClip.open()" and is
stopped by assigning "null" value to "DirectClip.thread" instance
variable in the method
"com.sun.media.sound.DirectAudioDevice.DirectClip.implClose()".<br>
<br>
THE DEFINED ROOT CAUSES OF THE BUG:<br>
<br>
1. The fact that "DirectClip.thread" instance variable is not
thread-safe. There is a possibility that null value assigned to it
in one thread through the former mentioned "DirectClip.implClose()"
method does not become visible for the running "Direct Clip" thread
in the method "DirectClip.run()".<br>
<br>
2. In the method "DirectClip.run()" not taking into account the fact
that a new "Direct Clip" thread could have already been started and
assigned to "DirectClip.thread" instance variable after the call to
"DirectClip.implClose()", by the moment when "DirectClip.thread"
value is checked for null in "DirectClip.run()" method, or by the
moment when the previous "Direct Clip" thread is awakened and
continues execution after the following code block in
"DirectClip.run()" from the file
"jdk/src/java.desktop/share/classes/com/sun/media/sound/DirectAudioDevice.java".<br>
<br>
<pre>1354 try {
1355 lock.wait();
<span class="changed">1356 } catch(InterruptedException ie) {}</span></pre>
<br>
THE SOLUTION:<br>
The solution is based on correction of the listed above 2 root
causes of the bug.<br>
<br>
Thank you,<br>
Anton<br>
</body>
</html>