jdk/test/javax/sound/sampled/spi/AudioFileReader/ExpectedNPEOnNull.java
author serb
Mon, 31 Oct 2016 14:50:09 +0300
changeset 41905 e8e5df013c6e
parent 34412 bed825be8cd8
permissions -rw-r--r--
8167615: Opensource unit/regression tests for JavaSound Reviewed-by: amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34412
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     1
/*
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     4
 *
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     8
 *
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    13
 * accompanied this code).
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    14
 *
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    18
 *
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    21
 * questions.
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    22
 */
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    23
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    24
import java.io.File;
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    25
import java.io.InputStream;
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    26
import java.net.URL;
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    27
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    28
import javax.sound.sampled.AudioSystem;
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    29
import javax.sound.sampled.spi.AudioFileReader;
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    30
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    31
import static java.util.ServiceLoader.load;
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    32
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    33
/**
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    34
 * @test
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    35
 * @bug 8135100
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    36
 * @author Sergey Bylokhov
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    37
 */
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    38
public final class ExpectedNPEOnNull {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    39
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    40
    public static void main(final String[] args) throws Exception {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    41
        testAS();
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    42
        testAFR();
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    43
    }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    44
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    45
    /**
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    46
     * Tests the part of AudioSystem API, which implemented via AudioFileReader.
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    47
     */
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    48
    private static void testAS() throws Exception {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    49
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    50
        try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    51
            AudioSystem.getAudioFileFormat((InputStream) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    52
            throw new RuntimeException("NPE is expected");
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    53
        } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    54
        }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    55
        try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    56
            AudioSystem.getAudioFileFormat((URL) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    57
            throw new RuntimeException("NPE is expected");
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    58
        } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    59
        }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    60
        try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    61
            AudioSystem.getAudioFileFormat((File) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    62
            throw new RuntimeException("NPE is expected");
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    63
        } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    64
        }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    65
        try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    66
            AudioSystem.getAudioInputStream((InputStream) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    67
            throw new RuntimeException("NPE is expected");
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    68
        } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    69
        }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    70
        try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    71
            AudioSystem.getAudioInputStream((URL) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    72
            throw new RuntimeException("NPE is expected");
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    73
        } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    74
        }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    75
        try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    76
            AudioSystem.getAudioInputStream((File) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    77
            throw new RuntimeException("NPE is expected");
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    78
        } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    79
        }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    80
    }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    81
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    82
    /**
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    83
     * Tests the AudioFileReader API directly.
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    84
     */
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    85
    private static void testAFR() throws Exception {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    86
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    87
        for (final AudioFileReader afr : load(AudioFileReader.class)) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    88
            try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    89
                afr.getAudioFileFormat((InputStream) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    90
                throw new RuntimeException("NPE is expected: " + afr);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    91
            } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    92
            }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    93
            try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    94
                afr.getAudioFileFormat((URL) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    95
                throw new RuntimeException("NPE is expected: " + afr);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    96
            } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    97
            }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    98
            try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
    99
                afr.getAudioFileFormat((File) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   100
                throw new RuntimeException("NPE is expected: " + afr);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   101
            } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   102
            }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   103
            try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   104
                afr.getAudioInputStream((InputStream) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   105
                throw new RuntimeException("NPE is expected: " + afr);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   106
            } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   107
            }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   108
            try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   109
                afr.getAudioInputStream((URL) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   110
                throw new RuntimeException("NPE is expected: " + afr);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   111
            } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   112
            }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   113
            try {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   114
                afr.getAudioInputStream((File) null);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   115
                throw new RuntimeException("NPE is expected: " + afr);
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   116
            } catch (final NullPointerException ignored) {
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   117
            }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   118
        }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   119
    }
bed825be8cd8 8135100: Behavior of null arguments not specified in javax.sound.sampled.spi
serb
parents:
diff changeset
   120
}