Path: blob/master/test/jdk/javax/sound/sampled/spi/AudioFileReader/ExpectedNPEOnNull.java
40527 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.sampled.AudioSystem;28import javax.sound.sampled.spi.AudioFileReader;2930import static java.util.ServiceLoader.load;3132/**33* @test34* @bug 813510035* @author Sergey Bylokhov36*/37public final class ExpectedNPEOnNull {3839public static void main(final String[] args) throws Exception {40testAS();41testAFR();42}4344/**45* Tests the part of AudioSystem API, which implemented via AudioFileReader.46*/47private static void testAS() throws Exception {4849try {50AudioSystem.getAudioFileFormat((InputStream) null);51throw new RuntimeException("NPE is expected");52} catch (final NullPointerException ignored) {53}54try {55AudioSystem.getAudioFileFormat((URL) null);56throw new RuntimeException("NPE is expected");57} catch (final NullPointerException ignored) {58}59try {60AudioSystem.getAudioFileFormat((File) null);61throw new RuntimeException("NPE is expected");62} catch (final NullPointerException ignored) {63}64try {65AudioSystem.getAudioInputStream((InputStream) null);66throw new RuntimeException("NPE is expected");67} catch (final NullPointerException ignored) {68}69try {70AudioSystem.getAudioInputStream((URL) null);71throw new RuntimeException("NPE is expected");72} catch (final NullPointerException ignored) {73}74try {75AudioSystem.getAudioInputStream((File) null);76throw new RuntimeException("NPE is expected");77} catch (final NullPointerException ignored) {78}79}8081/**82* Tests the AudioFileReader API directly.83*/84private static void testAFR() throws Exception {8586for (final AudioFileReader afr : load(AudioFileReader.class)) {87try {88afr.getAudioFileFormat((InputStream) null);89throw new RuntimeException("NPE is expected: " + afr);90} catch (final NullPointerException ignored) {91}92try {93afr.getAudioFileFormat((URL) null);94throw new RuntimeException("NPE is expected: " + afr);95} catch (final NullPointerException ignored) {96}97try {98afr.getAudioFileFormat((File) null);99throw new RuntimeException("NPE is expected: " + afr);100} catch (final NullPointerException ignored) {101}102try {103afr.getAudioInputStream((InputStream) null);104throw new RuntimeException("NPE is expected: " + afr);105} catch (final NullPointerException ignored) {106}107try {108afr.getAudioInputStream((URL) null);109throw new RuntimeException("NPE is expected: " + afr);110} catch (final NullPointerException ignored) {111}112try {113afr.getAudioInputStream((File) null);114throw new RuntimeException("NPE is expected: " + afr);115} catch (final NullPointerException ignored) {116}117}118}119}120121122