From f195e24b1983c0a5385847eca218f2f7f9a39c47 Mon Sep 17 00:00:00 2001 From: Jerome Haltom Date: Sun, 21 Jul 2024 21:44:36 -0500 Subject: [PATCH] getAudioInputStream was not closing the stream in case of exception causing the file to remain open and breaking the GetSoundBankSecurityException test which immediately tries to delete it. --- .../sun/media/sound/WaveFloatFileReader.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/jdk/src/share/classes/com/sun/media/sound/WaveFloatFileReader.java b/jdk/src/share/classes/com/sun/media/sound/WaveFloatFileReader.java index 5c816587f34..62eb120f352 100644 --- a/jdk/src/share/classes/com/sun/media/sound/WaveFloatFileReader.java +++ b/jdk/src/share/classes/com/sun/media/sound/WaveFloatFileReader.java @@ -160,12 +160,23 @@ public AudioFileFormat getAudioFileFormat(File file) public AudioInputStream getAudioInputStream(URL url) throws UnsupportedAudioFileException, IOException { - return getAudioInputStream(new BufferedInputStream(url.openStream())); + InputStream stream = url.openStream(); + try { + return getAudioInputStream(new BufferedInputStream(stream)); + } catch (Exception e) { + stream.close(); + throw e; + } } public AudioInputStream getAudioInputStream(File file) throws UnsupportedAudioFileException, IOException { - return getAudioInputStream(new BufferedInputStream(new FileInputStream( - file))); + InputStream stream = new FileInputStream(file); + try { + return getAudioInputStream(new BufferedInputStream(stream)); + } catch (Exception e) { + stream.close(); + throw e; + } } }