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 24import java.io.File; 25import java.io.InputStream; 26import java.net.URL; 27 28import javax.sound.sampled.AudioSystem; 29import javax.sound.sampled.spi.AudioFileReader; 30 31import static java.util.ServiceLoader.load; 32 33/** 34 * @test 35 * @bug 8135100 36 * @author Sergey Bylokhov 37 */ 38public final class ExpectedNPEOnNull { 39 40 public static void main(final String[] args) throws Exception { 41 testAS(); 42 testAFR(); 43 } 44 45 /** 46 * Tests the part of AudioSystem API, which implemented via AudioFileReader. 47 */ 48 private static void testAS() throws Exception { 49 50 try { 51 AudioSystem.getAudioFileFormat((InputStream) null); 52 throw new RuntimeException("NPE is expected"); 53 } catch (final NullPointerException ignored) { 54 } 55 try { 56 AudioSystem.getAudioFileFormat((URL) null); 57 throw new RuntimeException("NPE is expected"); 58 } catch (final NullPointerException ignored) { 59 } 60 try { 61 AudioSystem.getAudioFileFormat((File) null); 62 throw new RuntimeException("NPE is expected"); 63 } catch (final NullPointerException ignored) { 64 } 65 try { 66 AudioSystem.getAudioInputStream((InputStream) null); 67 throw new RuntimeException("NPE is expected"); 68 } catch (final NullPointerException ignored) { 69 } 70 try { 71 AudioSystem.getAudioInputStream((URL) null); 72 throw new RuntimeException("NPE is expected"); 73 } catch (final NullPointerException ignored) { 74 } 75 try { 76 AudioSystem.getAudioInputStream((File) null); 77 throw new RuntimeException("NPE is expected"); 78 } catch (final NullPointerException ignored) { 79 } 80 } 81 82 /** 83 * Tests the AudioFileReader API directly. 84 */ 85 private static void testAFR() throws Exception { 86 87 for (final AudioFileReader afr : load(AudioFileReader.class)) { 88 try { 89 afr.getAudioFileFormat((InputStream) null); 90 throw new RuntimeException("NPE is expected: " + afr); 91 } catch (final NullPointerException ignored) { 92 } 93 try { 94 afr.getAudioFileFormat((URL) null); 95 throw new RuntimeException("NPE is expected: " + afr); 96 } catch (final NullPointerException ignored) { 97 } 98 try { 99 afr.getAudioFileFormat((File) null); 100 throw new RuntimeException("NPE is expected: " + afr); 101 } catch (final NullPointerException ignored) { 102 } 103 try { 104 afr.getAudioInputStream((InputStream) null); 105 throw new RuntimeException("NPE is expected: " + afr); 106 } catch (final NullPointerException ignored) { 107 } 108 try { 109 afr.getAudioInputStream((URL) null); 110 throw new RuntimeException("NPE is expected: " + afr); 111 } catch (final NullPointerException ignored) { 112 } 113 try { 114 afr.getAudioInputStream((File) null); 115 throw new RuntimeException("NPE is expected: " + afr); 116 } catch (final NullPointerException ignored) { 117 } 118 } 119 } 120} 121