Path: blob/master/test/jdk/javax/sound/midi/spi/MidiFileReader/ExpectedNPEOnNull.java
41154 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.io.File;24import java.io.InputStream;25import java.net.URL;2627import javax.sound.midi.MidiSystem;28import javax.sound.midi.spi.MidiFileReader;2930import static java.util.ServiceLoader.load;3132/**33* @test34* @bug 814390935* @author Sergey Bylokhov36*/37public final class ExpectedNPEOnNull {3839public static void main(final String[] args) throws Exception {40testMS();41for (final MidiFileReader mfr : load(MidiFileReader.class)) {42testMFR(mfr);43}44}4546/**47* Tests the part of MidiSystem API, which implemented via MidiFileReader.48*/49private static void testMS() throws Exception {50// MidiSystem#getMidiFileFormat(InputStream)51try {52MidiSystem.getMidiFileFormat((InputStream) null);53throw new RuntimeException("NPE is expected");54} catch (final NullPointerException ignored) {55}56// MidiSystem#getMidiFileFormat(URL)57try {58MidiSystem.getMidiFileFormat((URL) null);59throw new RuntimeException("NPE is expected");60} catch (final NullPointerException ignored) {61}62// MidiSystem#getMidiFileFormat(File)63try {64MidiSystem.getMidiFileFormat((File) null);65throw new RuntimeException("NPE is expected");66} catch (final NullPointerException ignored) {67}68// MidiSystem#getSequence(InputStream)69try {70MidiSystem.getSequence((InputStream) null);71throw new RuntimeException("NPE is expected");72} catch (final NullPointerException ignored) {73}74// MidiSystem#getSequence(URL)75try {76MidiSystem.getSequence((URL) null);77throw new RuntimeException("NPE is expected");78} catch (final NullPointerException ignored) {79}80// MidiSystem#getSequence(File)81try {82MidiSystem.getSequence((File) null);83throw new RuntimeException("NPE is expected");84} catch (final NullPointerException ignored) {85}86}8788/**89* Tests the MidiFileReader API directly.90*/91private static void testMFR(final MidiFileReader mfr) throws Exception {92// MidiFileReader#getMidiFileFormat(InputStream)93try {94mfr.getMidiFileFormat((InputStream) null);95throw new RuntimeException("NPE is expected");96} catch (final NullPointerException ignored) {97}98// MidiFileReader#getMidiFileFormat(URL)99try {100mfr.getMidiFileFormat((URL) null);101throw new RuntimeException("NPE is expected");102} catch (final NullPointerException ignored) {103}104// MidiFileReader#getMidiFileFormat(File)105try {106mfr.getMidiFileFormat((File) null);107throw new RuntimeException("NPE is expected");108} catch (final NullPointerException ignored) {109}110// MidiFileReader#getSequence(InputStream)111try {112mfr.getSequence((InputStream) null);113throw new RuntimeException("NPE is expected");114} catch (final NullPointerException ignored) {115}116// MidiFileReader#getSequence(URL)117try {118mfr.getSequence((URL) null);119throw new RuntimeException("NPE is expected");120} catch (final NullPointerException ignored) {121}122// MidiFileReader#getSequence(File)123try {124mfr.getSequence((File) null);125throw new RuntimeException("NPE is expected");126} catch (final NullPointerException ignored) {127}128}129}130131132