<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">On 08.01.2015 1:13, Phil Race wrote:<br>
</div>
<blockquote cite="mid:54ADAF7D.10902@oracle.com" type="cite">Its not
clear to me if the bug description is implying an exception was
thrown<br>
</blockquote>
UnsupportedAudioFileException is thrown if the URL/File does not
point to valid audio file data recognized by the specific reader, so
AudioSystem will try to move to the next reader and a leak will
occur.<br>
Actually most of our readers are affected.<br>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<blockquote cite="mid:54ADAF7D.10902@oracle.com" type="cite">Still,
something like what you suggest seems to be needed.
<br>
</blockquote>
right.<br>
<blockquote cite="mid:54ADAF7D.10902@oracle.com" type="cite">
<br>
The owner of this bug is out until next week so I'll let him
comment further
<br>
after his return.
<br>
<br>
-phil.
<br>
<br>
On 01/07/2015 12:42 PM, Mike Clark wrote:
<br>
<blockquote type="cite">Hello all,
<br>
<br>
I wanted to post this as a comment on
<a class="moz-txt-link-freetext" href="https://bugs.openjdk.java.net/browse/JDK-8013586">https://bugs.openjdk.java.net/browse/JDK-8013586</a>, but apparently
getting comment access to that system is a bit of a hurdle.
Anyway. What follows is, I believe, a fix for the
aforementioned bug:
<br>
<br>
There is a file handle leak in some of the subclasses of
javax.sound.sampled.spi.AudioFileReader, such as
com.sun.media.sound.WaveFloatFileReader.
<br>
<br>
Consider com.sun.media.sound.WaveFloatFileReader's method:
<br>
<br>
public AudioInputStream getAudioInputStream(File file)
<br>
throws UnsupportedAudioFileException, IOException {
<br>
return getAudioInputStream(
<br>
new BufferedInputStream(new FileInputStream(file)));
<br>
}
<br>
<br>
See how there is no attempt to close the FileInputStream if an
exception is thrown? A file handle will remain open on the file
until garbage collection is run. Since garbage collection may
never run, the file handle may remain open until the JVM exits.
And on Windows the open file handle prevents the file from being
deleted, which is problematic.
<br>
<br>
Could we fix it by adding a try/catch block?
<br>
<br>
public AudioInputStream getAudioInputStream(File file)
<br>
throws UnsupportedAudioFileException, IOException {
<br>
FileInputStream fis = null;
<br>
try {
<br>
fis = new FileInputStream(file);
<br>
return getAudioInputStream(new
BufferedInputStream(fis));
<br>
} catch(IOException|UnsupportedAudioFileException e) {
<br>
if (fis != null) {
<br>
fis.close();
<br>
}
<br>
throw e;
<br>
}
<br>
}
<br>
<br>
These AudioFileReader subclass methods are usually called by
javax.sound.sampled.AudioSystem.getAudioInputStream(File), which
calls getAudioInputStream(File) on all registered subclasses of
AudioFileReader. As such, all subclasses of AudioFileReader in
the JRE should be reviewed for this problem.
<br>
<br>
best regards,
<br>
-Mike
<br>
<br>
</blockquote>
<br>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">--
Best regards, Sergey. </pre>
</body>
</html>