Skip to content

Commit 00dbe88

Browse files
Alexei Voitylovgnu-andrew
Alexei Voitylov
authored andcommittedJan 13, 2023
8293742: Better Banking of Sounds
Reviewed-by: mbalao, andrew Backport-of: f1de79f38fcff10ccaf232f79df0a94e84751ff7
1 parent 4f5099e commit 00dbe88

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed
 

‎jdk/src/share/classes/com/sun/media/sound/JARSoundbankReader.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
import java.net.URL;
3333
import java.net.URLClassLoader;
3434
import java.util.ArrayList;
35+
import java.util.Objects;
3536
import javax.sound.midi.InvalidMidiDataException;
3637
import javax.sound.midi.Soundbank;
3738
import javax.sound.midi.spi.SoundbankReader;
@@ -45,6 +46,13 @@
4546
*/
4647
public final class JARSoundbankReader extends SoundbankReader {
4748

49+
/*
50+
* Name of the system property that enables the Jar soundbank loading
51+
* true if jar sound bank is allowed to be loaded
52+
* default is false
53+
*/
54+
private final static String JAR_SOUNDBANK_ENABLED = "jdk.sound.jarsoundbank";
55+
4856
private static boolean isZIP(URL url) {
4957
boolean ok = false;
5058
try {
@@ -68,8 +76,10 @@ private static boolean isZIP(URL url) {
6876

6977
public Soundbank getSoundbank(URL url)
7078
throws InvalidMidiDataException, IOException {
71-
if (!isZIP(url))
79+
Objects.requireNonNull(url);
80+
if (!Boolean.getBoolean(JAR_SOUNDBANK_ENABLED) || !isZIP(url))
7281
return null;
82+
7383
ArrayList<Soundbank> soundbanks = new ArrayList<Soundbank>();
7484
URLClassLoader ucl = URLClassLoader.newInstance(new URL[]{url});
7585
InputStream stream = ucl.getResourceAsStream(
@@ -117,6 +127,7 @@ public Soundbank getSoundbank(InputStream stream)
117127

118128
public Soundbank getSoundbank(File file)
119129
throws InvalidMidiDataException, IOException {
130+
Objects.requireNonNull(file);
120131
return getSoundbank(file.toURI().toURL());
121132
}
122133
}

0 commit comments

Comments
 (0)
Please sign in to comment.