8201279: javax.sound tests should not set java.home system property
Reviewed-by: prr, rriggs
--- a/src/java.desktop/share/classes/com/sun/media/sound/JDK13Services.java Fri May 25 16:23:17 2018 -0700
+++ b/src/java.desktop/share/classes/com/sun/media/sound/JDK13Services.java Tue May 29 11:22:21 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -63,13 +63,6 @@
public final class JDK13Services {
/**
- * Filename of the properties file for default provider properties. This
- * file is searched in the subdirectory "conf" of the JRE directory (this
- * behaviour is hardcoded).
- */
- private static final String PROPERTIES_FILENAME = "sound.properties";
-
- /**
* Properties loaded from the properties file for default provider
* properties.
*/
@@ -195,7 +188,7 @@
private static synchronized Properties getProperties() {
if (properties == null) {
properties = new Properties();
- JSSecurityManager.loadProperties(properties, PROPERTIES_FILENAME);
+ JSSecurityManager.loadProperties(properties);
}
return properties;
}
--- a/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java Fri May 25 16:23:17 2018 -0700
+++ b/src/java.desktop/share/classes/com/sun/media/sound/JSSecurityManager.java Tue May 29 11:22:21 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -25,10 +25,10 @@
package com.sun.media.sound;
-import java.io.BufferedInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
+import java.io.Reader;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
@@ -52,16 +52,6 @@
private JSSecurityManager() {
}
- /** Checks if the VM currently has a SecurityManager installed.
- * Note that this may change over time. So the result of this method
- * should not be cached.
- *
- * @return true if a SecurityManger is installed, false otherwise.
- */
- private static boolean hasSecurityManager() {
- return (System.getSecurityManager() != null);
- }
-
static void checkRecordPermission() throws SecurityException {
if(Printer.trace) Printer.trace("JSSecurityManager.checkRecordPermission()");
SecurityManager sm = System.getSecurityManager();
@@ -70,69 +60,48 @@
}
}
- /** Load properties from a file.
- This method tries to load properties from the filename give into
- the passed properties object.
- If the file cannot be found or something else goes wrong,
- the method silently fails.
- @param properties The properties bundle to store the values of the
- properties file.
- @param filename The filename of the properties file to load. This
- filename is interpreted as relative to the subdirectory "conf" in
- the JRE directory.
+ /**
+ * Load properties from a file.
+ * <p>
+ * This method tries to load properties from the filename give into the
+ * passed properties object. If the file cannot be found or something else
+ * goes wrong, the method silently fails.
+ * <p>
+ * If the file referenced in "javax.sound.config.file" property exists and
+ * the user has an access to it, then it will be loaded, otherwise default
+ * configuration file "JAVA_HOME/conf/sound.properties" will be loaded.
+ *
+ * @param properties the properties bundle to store the values of the
+ * properties file
*/
- static void loadProperties(final Properties properties,
- final String filename) {
- if(hasSecurityManager()) {
- try {
- // invoke the privileged action using 1.2 security
- PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
- @Override
- public Void run() {
- loadPropertiesImpl(properties, filename);
- return null;
- }
- };
- AccessController.doPrivileged(action);
- if(Printer.debug)Printer.debug("Loaded properties with JDK 1.2 security");
- } catch (Exception e) {
- if(Printer.debug)Printer.debug("Exception loading properties with JDK 1.2 security");
- // try without using JDK 1.2 security
- loadPropertiesImpl(properties, filename);
+ static void loadProperties(final Properties properties) {
+ final String customFile = AccessController.doPrivileged(
+ (PrivilegedAction<String>) () -> System.getProperty(
+ "javax.sound.config.file"));
+ if (customFile != null) {
+ if (loadPropertiesImpl(properties, customFile)) {
+ return;
}
- } else {
- // not JDK 1.2 security, assume we already have permission
- loadPropertiesImpl(properties, filename);
}
+ AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+ final String home = System.getProperty("java.home");
+ if (home == null) {
+ throw new Error("Can't find java.home ??");
+ }
+ loadPropertiesImpl(properties, home, "conf", "sound.properties");
+ return null;
+ });
}
- private static void loadPropertiesImpl(Properties properties,
- String filename) {
- if(Printer.trace)Printer.trace(">> JSSecurityManager: loadPropertiesImpl()");
- String fname = System.getProperty("java.home");
- try {
- if (fname == null) {
- throw new Error("Can't find java.home ??");
- }
- File f = new File(fname, "conf");
- f = new File(f, filename);
- fname = f.getCanonicalPath();
- InputStream in = new FileInputStream(fname);
- BufferedInputStream bin = new BufferedInputStream(in);
- try {
- properties.load(bin);
- } finally {
- if (in != null) {
- in.close();
- }
- }
- } catch (Throwable t) {
- if (Printer.trace) {
- System.err.println("Could not load properties file \"" + fname + "\"");
- t.printStackTrace();
- }
+ private static boolean loadPropertiesImpl(final Properties properties,
+ String first, String... more) {
+ final Path fname = Paths.get(first, more);
+ try (final Reader reader = Files.newBufferedReader(fname)) {
+ properties.load(reader);
+ return true;
+ } catch (final Throwable t) {
+ return false;
}
- if(Printer.trace)Printer.trace("<< JSSecurityManager: loadPropertiesImpl() completed");
}
/** Create a Thread in the current ThreadGroup.
--- a/src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java Fri May 25 16:23:17 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java Tue May 29 11:22:21 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -66,7 +66,9 @@
* Properties can be used to specify default MIDI devices. Both system
* properties and a properties file are considered. The "sound.properties"
* properties file is read from an implementation-specific location (typically
- * it is the {@code conf} directory in the Java installation directory). If a
+ * it is the {@code conf} directory in the Java installation directory).
+ * The optional "javax.sound.config.file" system property can be used to specify
+ * the properties file that will be read as the initial configuration. If a
* property exists both as a system property and in the properties file, the
* system property takes precedence. If none is specified, a suitable default is
* chosen among the available devices. The syntax of the properties file is
--- a/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Fri May 25 16:23:17 2018 -0700
+++ b/src/java.desktop/share/classes/javax/sound/sampled/AudioSystem.java Tue May 29 11:22:21 2018 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -64,7 +64,9 @@
* Both system properties and a properties file are considered. The
* "sound.properties" properties file is read from an implementation-specific
* location (typically it is the {@code conf} directory in the Java installation
- * directory). If a property exists both as a system property and in the
+ * directory). The optional "javax.sound.config.file" system property can be
+ * used to specify the properties file that will be read as the initial
+ * configuration. If a property exists both as a system property and in the
* properties file, the system property takes precedence. If none is specified,
* a suitable default is chosen among the available devices. The syntax of the
* properties file is specified in
--- a/test/jdk/javax/sound/midi/MidiSystem/DefaultProperties.java Fri May 25 16:23:17 2018 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.File;
-
-import com.sun.media.sound.JDK13Services;
-
-/**
- * @test
- * @bug 4776511
- * @summary RFE: Setting the default MixerProvider. Test the retrieving and
- * parsing of properties. This is a part of the test for 4776511.
- * @run main/othervm DefaultProperties
- * @modules java.desktop/com.sun.media.sound
- */
-public class DefaultProperties {
-
- private static final Class[] lineTypeClasses = {
- javax.sound.midi.Receiver.class,
- javax.sound.midi.Transmitter.class,
- javax.sound.midi.Sequencer.class,
- javax.sound.midi.Synthesizer.class,
- };
-
- public static void main(String[] args) throws Exception {
- boolean allOk = true;
- File file = new File(System.getProperty("test.src", "."), "testdata");
- System.setProperty("java.home", file.getCanonicalPath());
-
- for (int i = 0; i < lineTypeClasses.length; i++) {
- Class cls = lineTypeClasses[i];
- String propertyName = cls.getName();
- String result;
- String provClassName;
- String instanceName;
-
- // properties file, both provider class name and instance name
- provClassName = "xyz";
- instanceName = "123";
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + " failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (! instanceName.equals(result)) {
- out("type " + cls + " failed: instance name should be '" +
- instanceName + "' but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, provider class name only, no trailing hash
- provClassName = "abc";
- System.setProperty(propertyName, provClassName);
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + " failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (result != null) {
- out("type " + cls + " failed: instance name should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, provider class name only, trailing hash
- provClassName = "def";
- System.setProperty(propertyName, provClassName + "#");
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + " failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (result != null) {
- out("type " + cls + " failed: instance name should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, instance name only
- instanceName = "ghi";
- System.setProperty(propertyName, "#" + instanceName);
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (result != null) {
- out("type " + cls + " failed: provider class should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (! instanceName.equals(result)) {
- out("type " + cls + " failed: instance name should be '" +
- instanceName + "' but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, both provider class and instance name
- provClassName = "jkl";
- instanceName = "mno";
- System.setProperty(propertyName, provClassName + "#" + instanceName);
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + "failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (! instanceName.equals(result)) {
- out("type " + cls + "failed: instance name should be '" +
- instanceName + "' but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, empty
- System.setProperty(propertyName, "");
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (result != null) {
- out("type " + cls + " failed: provider class should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (result != null) {
- out("type " + cls + "failed: instance name should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
- }
- if (! allOk) {
- throw new Exception("Test failed");
- } else {
- out("Test passed");
- }
- }
-
- private static void out(String message) {
- System.out.println(message);
- }
-}
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/midi/MidiSystem/DefaultProperties/DefaultProperties.java Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,167 @@
+/*
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.nio.file.Paths;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511 8201279
+ * @summary RFE: Setting the default MixerProvider. Test the retrieving and
+ * parsing of properties. This is a part of the test for 4776511.
+ * @run main/othervm DefaultProperties
+ * @run main/othervm/policy=java.policy DefaultProperties
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class DefaultProperties {
+
+ private static final Class[] lineTypeClasses = {
+ javax.sound.midi.Receiver.class,
+ javax.sound.midi.Transmitter.class,
+ javax.sound.midi.Sequencer.class,
+ javax.sound.midi.Synthesizer.class,
+ };
+
+ public static void main(String[] args) throws Exception {
+ boolean allOk = true;
+ String path = Paths.get(System.getProperty("test.src", "."),
+ "testdata", "conf", "sound.properties")
+ .toAbsolutePath().normalize().toString();
+ System.setProperty("javax.sound.config.file", path);
+
+ for (int i = 0; i < lineTypeClasses.length; i++) {
+ Class cls = lineTypeClasses[i];
+ String propertyName = cls.getName();
+ String result;
+ String provClassName;
+ String instanceName;
+
+ // properties file, both provider class name and instance name
+ provClassName = "xyz";
+ instanceName = "123";
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + " failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (! instanceName.equals(result)) {
+ out("type " + cls + " failed: instance name should be '" +
+ instanceName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, provider class name only, no trailing hash
+ provClassName = "abc";
+ System.setProperty(propertyName, provClassName);
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + " failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: instance name should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, provider class name only, trailing hash
+ provClassName = "def";
+ System.setProperty(propertyName, provClassName + "#");
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + " failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: instance name should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, instance name only
+ instanceName = "ghi";
+ System.setProperty(propertyName, "#" + instanceName);
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: provider class should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (! instanceName.equals(result)) {
+ out("type " + cls + " failed: instance name should be '" +
+ instanceName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, both provider class and instance name
+ provClassName = "jkl";
+ instanceName = "mno";
+ System.setProperty(propertyName, provClassName + "#" + instanceName);
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + "failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (! instanceName.equals(result)) {
+ out("type " + cls + "failed: instance name should be '" +
+ instanceName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, empty
+ System.setProperty(propertyName, "");
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: provider class should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + "failed: instance name should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+ }
+ if (! allOk) {
+ throw new Exception("Test failed");
+ } else {
+ out("Test passed");
+ }
+ }
+
+ private static void out(String message) {
+ System.out.println(message);
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/midi/MidiSystem/DefaultProperties/DefaultPropertiesNegative.java Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.nio.file.Paths;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 8201279
+ * @summary this test checks that "javax.sound.config.file" will be ignored if
+ * the user has no access to the properties file
+ * @run main/othervm/policy=negative.policy DefaultPropertiesNegative
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class DefaultPropertiesNegative {
+
+ private static final Class[] lineTypeClasses = {
+ javax.sound.midi.Receiver.class,
+ javax.sound.midi.Transmitter.class,
+ javax.sound.midi.Sequencer.class,
+ javax.sound.midi.Synthesizer.class,
+ };
+
+ public static void main(String[] args) throws Exception {
+ boolean allOk = true;
+ String path = Paths.get(System.getProperty("test.src", "."),
+ "testdata", "conf", "sound.properties")
+ .toAbsolutePath().normalize().toString();
+ System.setProperty("javax.sound.config.file", path);
+
+ for (int i = 0; i < lineTypeClasses.length; i++) {
+ Class cls = lineTypeClasses[i];
+ // properties file, both provider class name and instance name
+ String result = JDK13Services.getDefaultProviderClassName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: provider class should be 'null' "
+ + "but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: instance name should be 'null' "
+ + "but is '" + result + "'!");
+ allOk = false;
+ }
+ }
+ if (! allOk) {
+ throw new Exception("Test failed");
+ } else {
+ out("Test passed");
+ }
+ }
+
+ private static void out(String message) {
+ System.out.println(message);
+ }
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/midi/MidiSystem/DefaultProperties/java.policy Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,10 @@
+grant {
+ permission java.util.PropertyPermission "javax.sound.config.file", "write";
+ permission java.util.PropertyPermission "test.src", "read";
+ permission java.util.PropertyPermission "javax.sound.midi.Receiver", "write";
+ permission java.util.PropertyPermission "javax.sound.midi.Transmitter", "write";
+ permission java.util.PropertyPermission "javax.sound.midi.Sequencer", "write";
+ permission java.util.PropertyPermission "javax.sound.midi.Synthesizer", "write";
+ permission java.lang.RuntimePermission "accessClassInPackage.com.sun.media.sound";
+ permission java.io.FilePermission "${test.src}/testdata/conf/sound.properties", "read";
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/midi/MidiSystem/DefaultProperties/negative.policy Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,5 @@
+grant {
+ permission java.util.PropertyPermission "javax.sound.config.file", "write";
+ permission java.util.PropertyPermission "test.src", "read";
+ permission java.lang.RuntimePermission "accessClassInPackage.com.sun.media.sound";
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/midi/MidiSystem/DefaultProperties/testdata/conf/sound.properties Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+javax.sound.midi.Receiver=xyz#123
+javax.sound.midi.Transmitter=xyz#123
+javax.sound.midi.Sequencer=xyz#123
+javax.sound.midi.Synthesizer=xyz#123
--- a/test/jdk/javax/sound/midi/MidiSystem/testdata/conf/sound.properties Fri May 25 16:23:17 2018 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#
-# Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-javax.sound.midi.Receiver=xyz#123
-javax.sound.midi.Transmitter=xyz#123
-javax.sound.midi.Sequencer=xyz#123
-javax.sound.midi.Synthesizer=xyz#123
--- a/test/jdk/javax/sound/sampled/AudioSystem/DefaultProperties.java Fri May 25 16:23:17 2018 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*
- * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-import java.io.File;
-
-import com.sun.media.sound.JDK13Services;
-
-/**
- * @test
- * @bug 4776511
- * @build DefaultProperties
- * @run main/othervm DefaultProperties
- * @summary RFE: Setting the default MixerProvider. Test the retrieving and
- * parsing of properties.
- * @modules java.desktop/com.sun.media.sound
- */
-public class DefaultProperties {
-
- private static final Class[] lineTypeClasses = {
- javax.sound.sampled.SourceDataLine.class,
- javax.sound.sampled.TargetDataLine.class,
- javax.sound.sampled.Clip.class,
- javax.sound.sampled.Port.class,
- };
-
- public static void main(String[] args) throws Exception {
- boolean allOk = true;
- File file = new File(System.getProperty("test.src", "."), "testdata");
- System.setProperty("java.home", file.getCanonicalPath());
-
- for (int i = 0; i < lineTypeClasses.length; i++) {
- Class cls = lineTypeClasses[i];
- String propertyName = cls.getName();
- String result;
- String provClassName;
- String instanceName;
-
- // properties file, both provider class name and instance name
- provClassName = "xyz";
- instanceName = "123";
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + " failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (! instanceName.equals(result)) {
- out("type " + cls + " failed: instance name should be '" +
- instanceName + "' but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, provider class name only, no trailing hash
- provClassName = "abc";
- System.setProperty(propertyName, provClassName);
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + " failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (result != null) {
- out("type " + cls + " failed: instance name should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, provider class name only, trailing hash
- provClassName = "def";
- System.setProperty(propertyName, provClassName + "#");
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + " failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (result != null) {
- out("type " + cls + " failed: instance name should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, instance name only
- instanceName = "ghi";
- System.setProperty(propertyName, "#" + instanceName);
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (result != null) {
- out("type " + cls + " failed: provider class should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (! instanceName.equals(result)) {
- out("type " + cls + " failed: instance name should be '" +
- instanceName + "' but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, both provider class and instance name
- provClassName = "jkl";
- instanceName = "mno";
- System.setProperty(propertyName, provClassName + "#" + instanceName);
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (! provClassName.equals(result)) {
- out("type " + cls + " failed: provider class should be '" +
- provClassName + "' but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (! instanceName.equals(result)) {
- out("type " + cls + " failed: instance name should be '" +
- instanceName + "' but is '" + result + "'!");
- allOk = false;
- }
-
- // system property, empty
- System.setProperty(propertyName, "");
- result = JDK13Services.getDefaultProviderClassName(cls);
- if (result != null) {
- out("type " + cls + " failed: provider class should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
- result = JDK13Services.getDefaultInstanceName(cls);
- if (result != null) {
- out("type " + cls + " failed: instance name should be " +
- "null but is '" + result + "'!");
- allOk = false;
- }
- }
- if (! allOk) {
- throw new Exception("Test failed");
- } else {
- out("Test passed");
- }
- }
-
- private static void out(String message) {
- System.out.println(message);
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/sampled/AudioSystem/DefaultProperties/DefaultProperties.java Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,166 @@
+/*
+ * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.nio.file.Paths;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 4776511 8201279
+ * @run main/othervm DefaultProperties
+ * @run main/othervm/policy=java.policy DefaultProperties
+ * @summary RFE: Setting the default MixerProvider. Test the retrieving and
+ * parsing of properties.
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class DefaultProperties {
+
+ private static final Class[] lineTypeClasses = {
+ javax.sound.sampled.SourceDataLine.class,
+ javax.sound.sampled.TargetDataLine.class,
+ javax.sound.sampled.Clip.class,
+ javax.sound.sampled.Port.class,
+ };
+
+ public static void main(String[] args) throws Exception {
+ boolean allOk = true;
+ String path = Paths.get(System.getProperty("test.src", "."),
+ "testdata", "conf", "sound.properties")
+ .toAbsolutePath().normalize().toString();
+ System.setProperty("javax.sound.config.file", path);
+
+ for (int i = 0; i < lineTypeClasses.length; i++) {
+ Class cls = lineTypeClasses[i];
+ String propertyName = cls.getName();
+ String result;
+ String provClassName;
+ String instanceName;
+
+ // properties file, both provider class name and instance name
+ provClassName = "xyz";
+ instanceName = "123";
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + " failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (! instanceName.equals(result)) {
+ out("type " + cls + " failed: instance name should be '" +
+ instanceName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, provider class name only, no trailing hash
+ provClassName = "abc";
+ System.setProperty(propertyName, provClassName);
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + " failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: instance name should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, provider class name only, trailing hash
+ provClassName = "def";
+ System.setProperty(propertyName, provClassName + "#");
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + " failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: instance name should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, instance name only
+ instanceName = "ghi";
+ System.setProperty(propertyName, "#" + instanceName);
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: provider class should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (! instanceName.equals(result)) {
+ out("type " + cls + " failed: instance name should be '" +
+ instanceName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, both provider class and instance name
+ provClassName = "jkl";
+ instanceName = "mno";
+ System.setProperty(propertyName, provClassName + "#" + instanceName);
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (! provClassName.equals(result)) {
+ out("type " + cls + " failed: provider class should be '" +
+ provClassName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (! instanceName.equals(result)) {
+ out("type " + cls + " failed: instance name should be '" +
+ instanceName + "' but is '" + result + "'!");
+ allOk = false;
+ }
+
+ // system property, empty
+ System.setProperty(propertyName, "");
+ result = JDK13Services.getDefaultProviderClassName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: provider class should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: instance name should be " +
+ "null but is '" + result + "'!");
+ allOk = false;
+ }
+ }
+ if (! allOk) {
+ throw new Exception("Test failed");
+ } else {
+ out("Test passed");
+ }
+ }
+
+ private static void out(String message) {
+ System.out.println(message);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/sampled/AudioSystem/DefaultProperties/DefaultPropertiesNegative.java Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.nio.file.Paths;
+
+import com.sun.media.sound.JDK13Services;
+
+/**
+ * @test
+ * @bug 8201279
+ * @run main/othervm/policy=negative.policy DefaultPropertiesNegative
+ * @summary this test checks that "javax.sound.config.file" will be ignored if
+ * the user has no access to the properties file
+ * @modules java.desktop/com.sun.media.sound
+ */
+public class DefaultPropertiesNegative {
+
+ private static final Class[] lineTypeClasses = {
+ javax.sound.sampled.SourceDataLine.class,
+ javax.sound.sampled.TargetDataLine.class,
+ javax.sound.sampled.Clip.class,
+ javax.sound.sampled.Port.class,
+ };
+
+ public static void main(String[] args) throws Exception {
+ boolean allOk = true;
+ String path = Paths.get(System.getProperty("test.src", "."),
+ "testdata", "conf", "sound.properties")
+ .toAbsolutePath().normalize().toString();
+ System.setProperty("javax.sound.config.file", path);
+
+ for (int i = 0; i < lineTypeClasses.length; i++) {
+ Class cls = lineTypeClasses[i];
+ // properties file, both provider class name and instance name
+ String result = JDK13Services.getDefaultProviderClassName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: provider class should be 'null' "
+ + "but is '" + result + "'!");
+ allOk = false;
+ }
+ result = JDK13Services.getDefaultInstanceName(cls);
+ if (result != null) {
+ out("type " + cls + " failed: instance name should be 'null' "
+ + "but is '" + result + "'!");
+ allOk = false;
+ }
+ }
+ if (! allOk) {
+ throw new Exception("Test failed");
+ } else {
+ out("Test passed");
+ }
+ }
+
+ private static void out(String message) {
+ System.out.println(message);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/sampled/AudioSystem/DefaultProperties/java.policy Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,10 @@
+grant {
+ permission java.util.PropertyPermission "javax.sound.config.file", "write";
+ permission java.util.PropertyPermission "test.src", "read";
+ permission java.util.PropertyPermission "javax.sound.sampled.SourceDataLine", "write";
+ permission java.util.PropertyPermission "javax.sound.sampled.TargetDataLine", "write";
+ permission java.util.PropertyPermission "javax.sound.sampled.Clip", "write";
+ permission java.util.PropertyPermission "javax.sound.sampled.Port", "write";
+ permission java.lang.RuntimePermission "accessClassInPackage.com.sun.media.sound";
+ permission java.io.FilePermission "${test.src}/testdata/conf/sound.properties", "read";
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/sampled/AudioSystem/DefaultProperties/negative.policy Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,5 @@
+grant {
+ permission java.util.PropertyPermission "javax.sound.config.file", "write";
+ permission java.util.PropertyPermission "test.src", "read";
+ permission java.lang.RuntimePermission "accessClassInPackage.com.sun.media.sound";
+};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/javax/sound/sampled/AudioSystem/DefaultProperties/testdata/conf/sound.properties Tue May 29 11:22:21 2018 -0700
@@ -0,0 +1,27 @@
+#
+# Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+#
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+#
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+#
+
+javax.sound.sampled.SourceDataLine=xyz#123
+javax.sound.sampled.TargetDataLine=xyz#123
+javax.sound.sampled.Clip=xyz#123
+javax.sound.sampled.Port=xyz#123
--- a/test/jdk/javax/sound/sampled/AudioSystem/testdata/conf/sound.properties Fri May 25 16:23:17 2018 -0700
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-#
-# Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-javax.sound.sampled.SourceDataLine=xyz#123
-javax.sound.sampled.TargetDataLine=xyz#123
-javax.sound.sampled.Clip=xyz#123
-javax.sound.sampled.Port=xyz#123