1 /* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import java.io.File; 25 import java.io.InputStream; 26 import java.net.URL; 27 28 import javax.sound.midi.MidiSystem; 29 import javax.sound.midi.spi.SoundbankReader; 30 31 import static java.util.ServiceLoader.load; 32 33 /** 34 * @test 35 * @bug 8143909 36 * @author Sergey Bylokhov 37 */ 38 public final class ExpectedNPEOnNull { 39 40 public static void main(final String[] args) throws Exception { 41 testMS(); 42 for (final SoundbankReader sbr : load(SoundbankReader.class)) { 43 testSBR(sbr); 44 } 45 } 46 47 /** 48 * Tests the part of MidiSystem API, which implemented via SoundbankReader. 49 */ 50 private static void testMS() throws Exception { 51 // MidiSystem#getSoundbank(InputStream) 52 try { 53 MidiSystem.getSoundbank((InputStream) null); 54 throw new RuntimeException("NPE is expected"); 55 } catch (final NullPointerException ignored) { 56 } 57 // MidiSystem#getSoundbank(URL) 58 try { 59 MidiSystem.getSoundbank((URL) null); 60 throw new RuntimeException("NPE is expected"); 61 } catch (final NullPointerException ignored) { 62 } 63 // MidiSystem#getSoundbank(File) 64 try { 65 MidiSystem.getSoundbank((File) null); 66 throw new RuntimeException("NPE is expected"); 67 } catch (final NullPointerException ignored) { 68 } 69 } 70 71 /** 72 * Tests the SoundbankReader API directly. 73 */ 74 private static void testSBR(final SoundbankReader sbr) throws Exception { 75 // SoundbankReader#getSoundbank(InputStream) 76 try { 77 sbr.getSoundbank((InputStream) null); 78 throw new RuntimeException("NPE is expected"); 79 } catch (final NullPointerException ignored) { 80 } 81 // SoundbankReader#getSoundbank(URL) 82 try { 83 sbr.getSoundbank((URL) null); 84 throw new RuntimeException("NPE is expected"); 85 } catch (final NullPointerException ignored) { 86 } 87 // SoundbankReader#getSoundbank(File) 88 try { 89 sbr.getSoundbank((File) null); 90 throw new RuntimeException("NPE is expected"); 91 } catch (final NullPointerException ignored) { 92 } 93 } 94 }