8143909: Behavior of null arguments not specified in javax.sound.midi.spi
Summary: The specification change was reviewed by Florian Bomers also
Reviewed-by: amenkov
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDeviceProvider.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/AbstractMidiDeviceProvider.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015, 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,11 @@
package com.sun.media.sound;
+import java.util.Objects;
+
import javax.sound.midi.MidiDevice;
import javax.sound.midi.spi.MidiDeviceProvider;
-
/**
* Super class for MIDI input or output device provider.
*
@@ -127,7 +128,8 @@
}
@Override
- public final MidiDevice getDevice(MidiDevice.Info info) {
+ public final MidiDevice getDevice(final MidiDevice.Info info) {
+ Objects.requireNonNull(info);
if (info instanceof Info) {
readDeviceInfos();
MidiDevice[] devices = getDeviceCache();
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, 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
@@ -22,6 +22,7 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
+
package com.sun.media.sound;
import java.io.BufferedReader;
@@ -32,6 +33,8 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
+import java.util.Objects;
+
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;
@@ -112,6 +115,7 @@
public Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(stream);
return null;
}
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/RealTimeSequencerProvider.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/RealTimeSequencerProvider.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2015, 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,6 +25,8 @@
package com.sun.media.sound;
+import java.util.Objects;
+
import javax.sound.midi.MidiDevice;
import javax.sound.midi.spi.MidiDeviceProvider;
@@ -42,6 +44,7 @@
@Override
public MidiDevice getDevice(final MidiDevice.Info info) {
+ Objects.requireNonNull(info);
if (RealTimeSequencer.info.equals(info)) {
return new RealTimeSequencer();
}
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftProvider.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/SoftProvider.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2015, 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,6 +25,8 @@
package com.sun.media.sound;
+import java.util.Objects;
+
import javax.sound.midi.MidiDevice;
import javax.sound.midi.spi.MidiDeviceProvider;
@@ -42,6 +44,7 @@
@Override
public MidiDevice getDevice(final MidiDevice.Info info) {
+ Objects.requireNonNull(info);
if (SoftSynthesizer.info.equals(info)) {
return new SoftSynthesizer();
}
--- a/jdk/src/java.desktop/share/classes/com/sun/media/sound/StandardMidiFileWriter.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/com/sun/media/sound/StandardMidiFileWriter.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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,21 +25,22 @@
package com.sun.media.sound;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.SequenceInputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
import java.io.InputStream;
-import java.io.IOException;
import java.io.OutputStream;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.io.SequenceInputStream;
+import java.util.Objects;
import javax.sound.midi.InvalidMidiDataException;
+import javax.sound.midi.MetaMessage;
import javax.sound.midi.MidiEvent;
-import javax.sound.midi.MetaMessage;
import javax.sound.midi.Sequence;
import javax.sound.midi.ShortMessage;
import javax.sound.midi.SysexMessage;
@@ -115,24 +116,16 @@
return typesArray;
}
- public boolean isFileTypeSupported(int type) {
- for(int i=0; i<types.length; i++) {
- if( type == types[i] ) {
- return true;
- }
+ public int write(Sequence in, int type, OutputStream out) throws IOException {
+ Objects.requireNonNull(out);
+ if (!isFileTypeSupported(type, in)) {
+ throw new IllegalArgumentException("Could not write MIDI file");
}
- return false;
- }
-
- public int write(Sequence in, int type, OutputStream out) throws IOException {
byte [] buffer = null;
int bytesRead = 0;
long bytesWritten = 0;
- if( !isFileTypeSupported(type,in) ) {
- throw new IllegalArgumentException("Could not write MIDI file");
- }
// First get the fileStream from this sequence
InputStream fileStream = getFileStream(type,in);
if (fileStream == null) {
@@ -149,6 +142,7 @@
}
public int write(Sequence in, int type, File out) throws IOException {
+ Objects.requireNonNull(in);
FileOutputStream fos = new FileOutputStream(out); // throws IOException
int bytesWritten = write( in, type, fos );
fos.close();
--- a/jdk/src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/sound/midi/MidiSystem.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -35,6 +35,7 @@
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Objects;
import java.util.Properties;
import java.util.Set;
@@ -179,10 +180,12 @@
* due to resource restrictions
* @throws IllegalArgumentException if the info object does not represent a
* MIDI device installed on the system
+ * @throws NullPointerException if {@code info} is {@code null}
* @see #getMidiDeviceInfo
*/
public static MidiDevice getMidiDevice(final MidiDevice.Info info)
throws MidiUnavailableException {
+ Objects.requireNonNull(info);
for (final MidiDeviceProvider provider : getMidiDeviceProviders()) {
if (provider.isDeviceSupported(info)) {
return provider.getDevice(info);
@@ -447,11 +450,13 @@
* @throws InvalidMidiDataException if the stream does not point to valid
* MIDI soundbank data recognized by the system
* @throws IOException if an I/O error occurred when loading the soundbank
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
- public static Soundbank getSoundbank(InputStream stream)
- throws InvalidMidiDataException, IOException {
+ public static Soundbank getSoundbank(final InputStream stream)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(stream);
SoundbankReader sp = null;
Soundbank s = null;
@@ -479,9 +484,11 @@
* @throws InvalidMidiDataException if the URL does not point to valid MIDI
* soundbank data recognized by the system
* @throws IOException if an I/O error occurred when loading the soundbank
+ * @throws NullPointerException if {@code url} is {@code null}
*/
- public static Soundbank getSoundbank(URL url)
- throws InvalidMidiDataException, IOException {
+ public static Soundbank getSoundbank(final URL url)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(url);
SoundbankReader sp = null;
Soundbank s = null;
@@ -509,9 +516,11 @@
* @throws InvalidMidiDataException if the {@code File} does not point to
* valid MIDI soundbank data recognized by the system
* @throws IOException if an I/O error occurred when loading the soundbank
+ * @throws NullPointerException if {@code file} is {@code null}
*/
- public static Soundbank getSoundbank(File file)
- throws InvalidMidiDataException, IOException {
+ public static Soundbank getSoundbank(final File file)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(file);
SoundbankReader sp = null;
Soundbank s = null;
@@ -556,13 +565,15 @@
* MIDI file data recognized by the system
* @throws IOException if an I/O exception occurs while accessing the
* stream
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see #getMidiFileFormat(URL)
* @see #getMidiFileFormat(File)
* @see InputStream#markSupported
* @see InputStream#mark
*/
- public static MidiFileFormat getMidiFileFormat(InputStream stream)
- throws InvalidMidiDataException, IOException {
+ public static MidiFileFormat getMidiFileFormat(final InputStream stream)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(stream);
List<MidiFileReader> providers = getMidiFileReaders();
MidiFileFormat format = null;
@@ -602,11 +613,13 @@
* @throws InvalidMidiDataException if the URL does not point to valid MIDI
* file data recognized by the system
* @throws IOException if an I/O exception occurs while accessing the URL
+ * @throws NullPointerException if {@code url} is {@code null}
* @see #getMidiFileFormat(InputStream)
* @see #getMidiFileFormat(File)
*/
- public static MidiFileFormat getMidiFileFormat(URL url)
- throws InvalidMidiDataException, IOException {
+ public static MidiFileFormat getMidiFileFormat(final URL url)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(url);
List<MidiFileReader> providers = getMidiFileReaders();
MidiFileFormat format = null;
@@ -646,11 +659,13 @@
* @throws InvalidMidiDataException if the {@code File} does not point to
* valid MIDI file data recognized by the system
* @throws IOException if an I/O exception occurs while accessing the file
+ * @throws NullPointerException if {@code file} is {@code null}
* @see #getMidiFileFormat(InputStream)
* @see #getMidiFileFormat(URL)
*/
- public static MidiFileFormat getMidiFileFormat(File file)
- throws InvalidMidiDataException, IOException {
+ public static MidiFileFormat getMidiFileFormat(final File file)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(file);
List<MidiFileReader> providers = getMidiFileReaders();
MidiFileFormat format = null;
@@ -699,11 +714,13 @@
* @throws InvalidMidiDataException if the stream does not point to valid
* MIDI file data recognized by the system
* @throws IOException if an I/O exception occurs while accessing the stream
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
- public static Sequence getSequence(InputStream stream)
- throws InvalidMidiDataException, IOException {
+ public static Sequence getSequence(final InputStream stream)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(stream);
List<MidiFileReader> providers = getMidiFileReaders();
Sequence sequence = null;
@@ -743,9 +760,11 @@
* @throws InvalidMidiDataException if the URL does not point to valid MIDI
* file data recognized by the system
* @throws IOException if an I/O exception occurs while accessing the URL
+ * @throws NullPointerException if {@code url} is {@code null}
*/
- public static Sequence getSequence(URL url)
- throws InvalidMidiDataException, IOException {
+ public static Sequence getSequence(final URL url)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(url);
List<MidiFileReader> providers = getMidiFileReaders();
Sequence sequence = null;
@@ -787,9 +806,11 @@
* @throws InvalidMidiDataException if the File does not point to valid MIDI
* file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
- public static Sequence getSequence(File file)
- throws InvalidMidiDataException, IOException {
+ public static Sequence getSequence(final File file)
+ throws InvalidMidiDataException, IOException {
+ Objects.requireNonNull(file);
List<MidiFileReader> providers = getMidiFileReaders();
Sequence sequence = null;
@@ -870,8 +891,10 @@
* @param sequence the sequence for which MIDI file type support is queried
* @return the set of unique supported file types. If no file types are
* supported, returns an array of length 0.
+ * @throws NullPointerException if {@code sequence} is {@code null}
*/
- public static int[] getMidiFileTypes(Sequence sequence) {
+ public static int[] getMidiFileTypes(final Sequence sequence) {
+ Objects.requireNonNull(sequence);
List<MidiFileWriter> providers = getMidiFileWriters();
Set<Integer> allTypes = new HashSet<>();
@@ -903,8 +926,11 @@
* @param sequence the sequence for which file writing support is queried
* @return {@code true} if the file type is supported for this sequence,
* otherwise {@code false}
+ * @throws NullPointerException if {@code sequence} is {@code null}
*/
- public static boolean isFileTypeSupported(int fileType, Sequence sequence) {
+ public static boolean isFileTypeSupported(final int fileType,
+ final Sequence sequence) {
+ Objects.requireNonNull(sequence);
List<MidiFileWriter> providers = getMidiFileWriters();
@@ -929,10 +955,15 @@
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file format is not supported by
* the system
+ * @throws NullPointerException if {@code in} or {@code out} are
+ * {@code null}
* @see #isFileTypeSupported(int, Sequence)
* @see #getMidiFileTypes(Sequence)
*/
- public static int write(Sequence in, int fileType, OutputStream out) throws IOException {
+ public static int write(final Sequence in, final int fileType,
+ final OutputStream out) throws IOException {
+ Objects.requireNonNull(in);
+ Objects.requireNonNull(out);
List<MidiFileWriter> providers = getMidiFileWriters();
//$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
@@ -963,10 +994,15 @@
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file type is not supported by the
* system
+ * @throws NullPointerException if {@code in} or {@code out} are
+ * {@code null}
* @see #isFileTypeSupported(int, Sequence)
* @see #getMidiFileTypes(Sequence)
*/
- public static int write(Sequence in, int type, File out) throws IOException {
+ public static int write(final Sequence in, final int type, final File out)
+ throws IOException {
+ Objects.requireNonNull(in);
+ Objects.requireNonNull(out);
List<MidiFileWriter> providers = getMidiFileWriters();
//$$fb 2002-04-17: Fix for 4635287: Standard MidiFileWriter cannot write empty Sequences
--- a/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/MidiDeviceProvider.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -26,6 +26,7 @@
package javax.sound.midi.spi;
import java.util.Arrays;
+import java.util.Objects;
import javax.sound.midi.MidiDevice;
@@ -46,8 +47,10 @@
* is queried
* @return {@code true} if the specified device is supported, otherwise
* {@code false}
+ * @throws NullPointerException if {@code info} is {@code null}
*/
public boolean isDeviceSupported(final MidiDevice.Info info) {
+ Objects.requireNonNull(info);
return Arrays.asList(getDeviceInfo()).contains(info);
}
@@ -67,6 +70,7 @@
* @throws IllegalArgumentException if the info object specified does not
* match the info object for a device supported by this
* {@code MidiDeviceProvider}
+ * @throws NullPointerException if {@code info} is {@code null}
*/
public abstract MidiDevice getDevice(MidiDevice.Info info);
}
--- a/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileReader.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileReader.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -60,6 +60,7 @@
* @throws InvalidMidiDataException if the stream does not point to valid
* MIDI file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
@@ -76,6 +77,7 @@
* @throws InvalidMidiDataException if the URL does not point to valid MIDI
* file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code url} is {@code null}
*/
public abstract MidiFileFormat getMidiFileFormat(URL url)
throws InvalidMidiDataException, IOException;
@@ -90,6 +92,7 @@
* @throws InvalidMidiDataException if the {@code File} does not point to
* valid MIDI file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
public abstract MidiFileFormat getMidiFileFormat(File file)
throws InvalidMidiDataException, IOException;
@@ -110,6 +113,7 @@
* @throws InvalidMidiDataException if the stream does not point to valid
* MIDI file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code stream} is {@code null}
* @see InputStream#markSupported
* @see InputStream#mark
*/
@@ -126,6 +130,7 @@
* @throws InvalidMidiDataException if the URL does not point to valid MIDI
* file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code url} is {@code null}
*/
public abstract Sequence getSequence(URL url)
throws InvalidMidiDataException, IOException;
@@ -141,6 +146,7 @@
* @throws InvalidMidiDataException if the {@code File} does not point to
* valid MIDI file data recognized by the system
* @throws IOException if an I/O exception occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
public abstract Sequence getSequence(File file)
throws InvalidMidiDataException, IOException;
--- a/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/MidiFileWriter.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -58,6 +58,7 @@
* queried
* @return array of file types. If no file types are supported, returns an
* array of length 0.
+ * @throws NullPointerException if {@code sequence} is {@code null}
*/
public abstract int[] getMidiFileTypes(Sequence sequence);
@@ -88,6 +89,7 @@
* @param sequence the sequence for which file writing support is queried
* @return {@code true} if the file type is supported for this sequence,
* otherwise {@code false}
+ * @throws NullPointerException if {@code sequence} is {@code null}
*/
public boolean isFileTypeSupported(int fileType, Sequence sequence) {
@@ -111,6 +113,8 @@
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file type is not supported by
* this file writer
+ * @throws NullPointerException if {@code in} or {@code out} are
+ * {@code null}
* @see #isFileTypeSupported(int, Sequence)
* @see #getMidiFileTypes(Sequence)
*/
@@ -129,6 +133,8 @@
* @throws IOException if an I/O exception occurs
* @throws IllegalArgumentException if the file type is not supported by
* this file writer
+ * @throws NullPointerException if {@code in} or {@code out} are
+ * {@code null}
* @see #isFileTypeSupported(int, Sequence)
* @see #getMidiFileTypes(Sequence)
*/
--- a/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/SoundbankReader.java Wed Dec 09 18:12:49 2015 +0300
+++ b/jdk/src/java.desktop/share/classes/javax/sound/midi/spi/SoundbankReader.java Wed Dec 09 18:56:59 2015 +0300
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -52,6 +52,7 @@
* @throws InvalidMidiDataException if the URL does not point to valid MIDI
* soundbank data recognized by this soundbank reader
* @throws IOException if an I/O error occurs
+ * @throws NullPointerException if {@code url} is {@code null}
*/
public abstract Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException;
@@ -64,6 +65,7 @@
* @throws InvalidMidiDataException if the stream does not point to valid
* MIDI soundbank data recognized by this soundbank reader
* @throws IOException if an I/O error occurs
+ * @throws NullPointerException if {@code stream} is {@code null}
*/
public abstract Soundbank getSoundbank(InputStream stream)
throws InvalidMidiDataException, IOException;
@@ -76,6 +78,7 @@
* @throws InvalidMidiDataException if the file does not point to valid MIDI
* soundbank data recognized by this soundbank reader
* @throws IOException if an I/O error occurs
+ * @throws NullPointerException if {@code file} is {@code null}
*/
public abstract Soundbank getSoundbank(File file)
throws InvalidMidiDataException, IOException;
--- a/jdk/test/javax/sound/midi/MidiDeviceProvider/FakeInfo.java Wed Dec 09 18:12:49 2015 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2015, 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.util.Collection;
-import java.util.HashSet;
-
-import javax.sound.midi.MidiDevice;
-import javax.sound.midi.MidiDevice.Info;
-import javax.sound.midi.MidiSystem;
-import javax.sound.midi.MidiUnavailableException;
-import javax.sound.midi.spi.MidiDeviceProvider;
-
-import static java.util.ServiceLoader.load;
-
-/**
- * @test
- * @bug 8059743
- * @summary MidiDeviceProvider shouldn't returns incorrect results in case of
- * some unknown MidiDevice.Info
- * @author Sergey Bylokhov
- */
-public final class FakeInfo {
-
- private static final class Fake extends Info {
-
- Fake() {
- super("a", "b", "c", "d");
- }
- }
-
- public static void main(final String[] args) {
- final Info fake = new Fake();
- // MidiSystem API
- try {
- MidiSystem.getMidiDevice(fake);
- throw new RuntimeException("IllegalArgumentException expected");
- } catch (final MidiUnavailableException e) {
- throw new RuntimeException("IllegalArgumentException expected", e);
- } catch (final IllegalArgumentException ignored) {
- // expected
- }
- // MidiDeviceProvider API
- final Collection<String> errors = new HashSet<>();
- for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
- try {
- if (mdp.isDeviceSupported(fake)) {
- throw new RuntimeException("fake is supported");
- }
- final MidiDevice device = mdp.getDevice(fake);
- System.err.println("MidiDevice: " + device);
- throw new RuntimeException("IllegalArgumentException expected");
- } catch (final IllegalArgumentException e) {
- errors.add(e.getMessage());
- }
- }
- if (errors.size() != 1) {
- throw new RuntimeException("Wrong number of messages:" + errors);
- }
- }
-}
--- a/jdk/test/javax/sound/midi/MidiDeviceProvider/NullInfo.java Wed Dec 09 18:12:49 2015 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2014, 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.util.Collection;
-import java.util.HashSet;
-
-import javax.sound.midi.MidiDevice;
-import javax.sound.midi.MidiSystem;
-import javax.sound.midi.MidiUnavailableException;
-import javax.sound.midi.spi.MidiDeviceProvider;
-
-import static java.util.ServiceLoader.load;
-
-/**
- * @test
- * @bug 8058115
- * @summary MidiDeviceProvider shouldn't returns incorrect results or throw NPE
- * in case of null MidiDevice.Info
- * @author Sergey Bylokhov
- */
-public final class NullInfo {
-
- public static void main(final String[] args) {
- // MidiSystem API
- try {
- MidiSystem.getMidiDevice(null);
- throw new RuntimeException("IllegalArgumentException expected");
- } catch (final MidiUnavailableException e) {
- throw new RuntimeException("IllegalArgumentException expected", e);
- } catch (final IllegalArgumentException ignored) {
- // expected
- }
- // MidiDeviceProvider API
- final Collection<String> errors = new HashSet<>();
- for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
- try {
- if (mdp.isDeviceSupported(null)) {
- throw new RuntimeException("null is supported");
- }
- final MidiDevice device = mdp.getDevice(null);
- System.err.println("MidiDevice: " + device);
- throw new RuntimeException("IllegalArgumentException expected");
- } catch (final IllegalArgumentException e) {
- errors.add(e.getMessage());
- }
- }
- if (errors.size() != 1) {
- throw new RuntimeException("Wrong number of messages:" + errors);
- }
- }
-}
--- a/jdk/test/javax/sound/midi/MidiDeviceProvider/UnsupportedInfo.java Wed Dec 09 18:12:49 2015 +0300
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,59 +0,0 @@
-/*
- * Copyright (c) 2014, 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 javax.sound.midi.MidiDevice;
-import javax.sound.midi.MidiSystem;
-import javax.sound.midi.spi.MidiDeviceProvider;
-
-import static java.util.ServiceLoader.load;
-
-/**
- * @test
- * @bug 8058115
- * @summary MidiDeviceProvider shouldn't returns incorrect results in case of
- * unsupported MidiDevice.Info
- * @author Sergey Bylokhov
- */
-public final class UnsupportedInfo {
-
- public static void main(final String[] args) {
- final MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
- for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
- for (final MidiDevice.Info info : infos) {
- if (mdp.isDeviceSupported(info)) {
- if (mdp.getDevice(info) == null) {
- throw new RuntimeException("MidiDevice is null");
- }
- } else {
- try {
- mdp.getDevice(info);
- throw new RuntimeException(
- "IllegalArgumentException expected");
- } catch (final IllegalArgumentException ignored) {
- // expected
- }
- }
- }
- }
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/spi/MidiDeviceProvider/ExpectedNPEOnNull.java Wed Dec 09 18:56:59 2015 +0300
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2015, 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.util.Objects;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.spi.MidiDeviceProvider;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8143909
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ public static void main(final String[] args) throws Exception {
+ testMS();
+ for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
+ testMDP(mdp);
+ }
+ testMDP(customMDP);
+ }
+
+ /**
+ * Tests the part of MidiSystem API, which implemented via
+ * MidiDeviceProvider.
+ */
+ private static void testMS() throws Exception {
+ // MidiSystem#getMidiDevice(MidiDevice.Info)
+ try {
+ MidiSystem.getMidiDevice(null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ /**
+ * Tests the MidiDeviceProvider API directly.
+ */
+ private static void testMDP(final MidiDeviceProvider mdp) throws Exception {
+ // MidiDeviceProvider#isDeviceSupported(Info)
+ try {
+ mdp.isDeviceSupported(null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiDeviceProvider#getDevice(Info)
+ try {
+ mdp.getDevice(null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ /**
+ * Tests some default implementation of MidiDeviceProvider API, using the
+ * custom {@code MidiDeviceProvider}, which support nothing.
+ */
+ static MidiDeviceProvider customMDP = new MidiDeviceProvider() {
+ @Override
+ public MidiDevice.Info[] getDeviceInfo() {
+ return new MidiDevice.Info[0];
+ }
+
+ @Override
+ public MidiDevice getDevice(MidiDevice.Info info) {
+ Objects.requireNonNull(info);
+ return null;
+ }
+ };
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/spi/MidiDeviceProvider/FakeInfo.java Wed Dec 09 18:56:59 2015 +0300
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015, 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.util.Collection;
+import java.util.HashSet;
+
+import javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiDevice.Info;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.MidiUnavailableException;
+import javax.sound.midi.spi.MidiDeviceProvider;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8059743
+ * @summary MidiDeviceProvider shouldn't returns incorrect results in case of
+ * some unknown MidiDevice.Info
+ * @author Sergey Bylokhov
+ */
+public final class FakeInfo {
+
+ private static final class Fake extends Info {
+
+ Fake() {
+ super("a", "b", "c", "d");
+ }
+ }
+
+ public static void main(final String[] args) {
+ final Info fake = new Fake();
+ // MidiSystem API
+ try {
+ MidiSystem.getMidiDevice(fake);
+ throw new RuntimeException("IllegalArgumentException expected");
+ } catch (final MidiUnavailableException e) {
+ throw new RuntimeException("IllegalArgumentException expected", e);
+ } catch (final IllegalArgumentException ignored) {
+ // expected
+ }
+ // MidiDeviceProvider API
+ final Collection<String> errors = new HashSet<>();
+ for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
+ try {
+ if (mdp.isDeviceSupported(fake)) {
+ throw new RuntimeException("fake is supported");
+ }
+ final MidiDevice device = mdp.getDevice(fake);
+ System.err.println("MidiDevice: " + device);
+ throw new RuntimeException("IllegalArgumentException expected");
+ } catch (final IllegalArgumentException e) {
+ errors.add(e.getMessage());
+ }
+ }
+ if (errors.size() != 1) {
+ throw new RuntimeException("Wrong number of messages:" + errors);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/spi/MidiDeviceProvider/UnsupportedInfo.java Wed Dec 09 18:56:59 2015 +0300
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014, 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 javax.sound.midi.MidiDevice;
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.spi.MidiDeviceProvider;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8058115
+ * @summary MidiDeviceProvider shouldn't returns incorrect results in case of
+ * unsupported MidiDevice.Info
+ * @author Sergey Bylokhov
+ */
+public final class UnsupportedInfo {
+
+ public static void main(final String[] args) {
+ final MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
+ for (final MidiDeviceProvider mdp : load(MidiDeviceProvider.class)) {
+ for (final MidiDevice.Info info : infos) {
+ if (mdp.isDeviceSupported(info)) {
+ if (mdp.getDevice(info) == null) {
+ throw new RuntimeException("MidiDevice is null");
+ }
+ } else {
+ try {
+ mdp.getDevice(info);
+ throw new RuntimeException(
+ "IllegalArgumentException expected");
+ } catch (final IllegalArgumentException ignored) {
+ // expected
+ }
+ }
+ }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/spi/MidiFileReader/ExpectedNPEOnNull.java Wed Dec 09 18:56:59 2015 +0300
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2015, 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 java.io.InputStream;
+import java.net.URL;
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.spi.MidiFileReader;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8143909
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ public static void main(final String[] args) throws Exception {
+ testMS();
+ for (final MidiFileReader mfr : load(MidiFileReader.class)) {
+ testMFR(mfr);
+ }
+ }
+
+ /**
+ * Tests the part of MidiSystem API, which implemented via MidiFileReader.
+ */
+ private static void testMS() throws Exception {
+ // MidiSystem#getMidiFileFormat(InputStream)
+ try {
+ MidiSystem.getMidiFileFormat((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiSystem#getMidiFileFormat(URL)
+ try {
+ MidiSystem.getMidiFileFormat((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiSystem#getMidiFileFormat(File)
+ try {
+ MidiSystem.getMidiFileFormat((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiSystem#getSequence(InputStream)
+ try {
+ MidiSystem.getSequence((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiSystem#getSequence(URL)
+ try {
+ MidiSystem.getSequence((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiSystem#getSequence(File)
+ try {
+ MidiSystem.getSequence((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ /**
+ * Tests the MidiFileReader API directly.
+ */
+ private static void testMFR(final MidiFileReader mfr) throws Exception {
+ // MidiFileReader#getMidiFileFormat(InputStream)
+ try {
+ mfr.getMidiFileFormat((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiFileReader#getMidiFileFormat(URL)
+ try {
+ mfr.getMidiFileFormat((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiFileReader#getMidiFileFormat(File)
+ try {
+ mfr.getMidiFileFormat((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiFileReader#getSequence(InputStream)
+ try {
+ mfr.getSequence((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiFileReader#getSequence(URL)
+ try {
+ mfr.getSequence((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiFileReader#getSequence(File)
+ try {
+ mfr.getSequence((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/spi/MidiFileWriter/ExpectedNPEOnNull.java Wed Dec 09 18:56:59 2015 +0300
@@ -0,0 +1,215 @@
+/*
+ * Copyright (c) 2015, 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 java.io.OutputStream;
+import java.util.Objects;
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.Sequence;
+import javax.sound.midi.spi.MidiFileWriter;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8143909
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ public static void main(final String[] args) throws Exception {
+ testMS();
+ for (final MidiFileWriter mfw : load(MidiFileWriter.class)) {
+ testMFW(mfw);
+ }
+ testMFW(customMFW);
+ }
+
+ /**
+ * Tests the part of MidiSystem API, which implemented via MidiFileWriter.
+ */
+ private static void testMS() throws Exception {
+ // MidiSystem#getMidiFileTypes(Sequence)
+ try {
+ MidiSystem.getMidiFileTypes(null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+
+ // MidiSystem#isFileTypeSupported(int, Sequence)
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ MidiSystem.isFileTypeSupported(type, null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ // MidiSystem#write(Sequence, int, OutputStream)
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ MidiSystem.write(null, type, new NullOutputStream());
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ MidiSystem.write(new Sequence(0, 0), type, (OutputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ MidiSystem.write(null, type, (OutputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ // MidiSystem#write(Sequence, int, File)
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ MidiSystem.write(null, type, new File(""));
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ MidiSystem.write(new Sequence(0, 0), type, (File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ MidiSystem.write(null, type, (File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+
+ /**
+ * Tests the MidiFileWriter API directly.
+ */
+ private static void testMFW(final MidiFileWriter mfw) throws Exception {
+ // MidiFileWriter#getMidiFileTypes(Sequence)
+ try {
+ mfw.getMidiFileTypes(null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiFileWriter#isFileTypeSupported(int, Sequence)
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ mfw.isFileTypeSupported(type, null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ // MidiFileWriter#write(Sequence, int, OutputStream)
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ mfw.write(null, type, new NullOutputStream());
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ mfw.write(new Sequence(0, 0), type, (OutputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ mfw.write(null, type, (OutputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ // MidiFileWriter#write(Sequence, int, File)
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ mfw.write(null, type, new File(""));
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ mfw.write(new Sequence(0, 0), type, (File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ for (final int type : MidiSystem.getMidiFileTypes()) {
+ try {
+ mfw.write(null, type, (File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+ }
+ /**
+ * Tests some default implementation of MidiFileWriter API, using the custom
+ * {@code MidiFileWriter}, which support nothing.
+ */
+ static MidiFileWriter customMFW = new MidiFileWriter() {
+ @Override
+ public int[] getMidiFileTypes() {
+ return new int[0];
+ }
+
+ @Override
+ public int[] getMidiFileTypes(Sequence sequence) {
+ Objects.requireNonNull(sequence);
+ return new int[0];
+ }
+
+ @Override
+ public int write(Sequence in, int fileType, OutputStream out) {
+ Objects.requireNonNull(in);
+ Objects.requireNonNull(out);
+ return 0;
+ }
+
+ @Override
+ public int write(Sequence in, int fileType, File out) {
+ Objects.requireNonNull(in);
+ Objects.requireNonNull(out);
+ return 0;
+ }
+ };
+
+ private static final class NullOutputStream extends OutputStream {
+
+ @Override
+ public void write(final int b) {
+ //do nothing
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/sound/midi/spi/SoundbankReader/ExpectedNPEOnNull.java Wed Dec 09 18:56:59 2015 +0300
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2015, 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 java.io.InputStream;
+import java.net.URL;
+
+import javax.sound.midi.MidiSystem;
+import javax.sound.midi.spi.SoundbankReader;
+
+import static java.util.ServiceLoader.load;
+
+/**
+ * @test
+ * @bug 8143909
+ * @author Sergey Bylokhov
+ */
+public final class ExpectedNPEOnNull {
+
+ public static void main(final String[] args) throws Exception {
+ testMS();
+ for (final SoundbankReader sbr : load(SoundbankReader.class)) {
+ testSBR(sbr);
+ }
+ }
+
+ /**
+ * Tests the part of MidiSystem API, which implemented via SoundbankReader.
+ */
+ private static void testMS() throws Exception {
+ // MidiSystem#getSoundbank(InputStream)
+ try {
+ MidiSystem.getSoundbank((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiSystem#getSoundbank(URL)
+ try {
+ MidiSystem.getSoundbank((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // MidiSystem#getSoundbank(File)
+ try {
+ MidiSystem.getSoundbank((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+
+ /**
+ * Tests the SoundbankReader API directly.
+ */
+ private static void testSBR(final SoundbankReader sbr) throws Exception {
+ // SoundbankReader#getSoundbank(InputStream)
+ try {
+ sbr.getSoundbank((InputStream) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // SoundbankReader#getSoundbank(URL)
+ try {
+ sbr.getSoundbank((URL) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ // SoundbankReader#getSoundbank(File)
+ try {
+ sbr.getSoundbank((File) null);
+ throw new RuntimeException("NPE is expected");
+ } catch (final NullPointerException ignored) {
+ }
+ }
+}