jdk/test/java/util/PriorityQueue/NoNulls.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 5467 0cfa1c70b5ab
child 8580 d1585a92e376
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     1
/*
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     3
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     6
 * published by the Free Software Foundation.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     7
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    12
 * accompanied this code).
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    13
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    17
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5467
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5467
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5467
diff changeset
    20
 * questions.
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    21
 */
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    22
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    23
/*
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    27
 * file:
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    28
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    29
 * Written by Martin Buchholz with assistance from members of JCP JSR-166
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    31
 * http://creativecommons.org/licenses/publicdomain
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    32
 */
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    33
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    34
/*
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    35
 * @test
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    36
 * @bug 6950540
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    37
 * @summary Attempt to add a null throws NullPointerException
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    38
 */
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    39
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    40
import java.util.ArrayList;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    41
import java.util.Arrays;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    42
import java.util.Comparator;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    43
import java.util.Collection;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    44
import java.util.Collections;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    45
import java.util.PriorityQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    46
import java.util.SortedSet;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    47
import java.util.TreeSet;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    48
import java.util.concurrent.ArrayBlockingQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    49
import java.util.concurrent.LinkedBlockingDeque;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    50
import java.util.concurrent.LinkedBlockingQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    51
import java.util.concurrent.PriorityBlockingQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    52
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    53
public class NoNulls {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    54
    void test(String[] args) throws Throwable {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    55
        final Comparator<String> nullTolerantComparator
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    56
            = new Comparator<>() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    57
            public int compare(String x, String y) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    58
                return (x == null ? -1 :
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    59
                        y == null ? 1 :
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    60
                        x.compareTo(y));
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    61
            }};
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    62
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    63
        final SortedSet<String> nullSortedSet
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    64
            = new TreeSet<>(nullTolerantComparator);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    65
        nullSortedSet.add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    66
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    67
        final PriorityQueue<String> nullPriorityQueue
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    68
            = new PriorityQueue<>() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    69
            public Object[] toArray() { return new Object[] { null };}};
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    70
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    71
        final Collection<String> nullCollection = new ArrayList<>();
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    72
        nullCollection.add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    73
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    74
        THROWS(NullPointerException.class,
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    75
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    76
                   new PriorityQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    77
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    78
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    79
                   new PriorityBlockingQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    80
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    81
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    82
                   new ArrayBlockingQueue<String>(10, false, nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    83
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    84
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    85
                   new ArrayBlockingQueue<String>(10, true, nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    86
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    87
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    88
                   new LinkedBlockingQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    89
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    90
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    91
                   new LinkedBlockingDeque<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    92
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    93
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    94
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    95
                   new PriorityQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    96
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    97
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    98
                   new PriorityBlockingQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    99
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   100
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   101
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   102
                   new PriorityQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   103
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   104
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   105
                   new PriorityBlockingQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   106
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   107
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   108
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   109
                   new PriorityQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   110
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   111
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   112
                   new PriorityBlockingQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   113
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   114
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   115
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   116
                   new PriorityQueue<String>(nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   117
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   118
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   119
                   new PriorityBlockingQueue<String>(nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   120
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   121
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   122
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   123
                   new PriorityQueue<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   124
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   125
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   126
                   new PriorityBlockingQueue<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   127
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   128
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   129
                   new ArrayBlockingQueue<String>(10, false).add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   130
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   131
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   132
                   new ArrayBlockingQueue<String>(10, true).add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   133
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   134
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   135
                   new LinkedBlockingQueue<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   136
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   137
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   138
                   new LinkedBlockingDeque<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   139
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   140
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   141
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   142
                   new PriorityQueue<String>().offer(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   143
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   144
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   145
                   new PriorityBlockingQueue<String>().offer(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   146
               }});
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   147
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   148
        nullSortedSet.add("foo");
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   149
        nullCollection.add("foo");
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   150
        THROWS(NullPointerException.class,
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   151
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   152
                   new PriorityQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   153
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   154
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   155
                   new PriorityBlockingQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   156
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   157
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   158
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   159
                   new PriorityQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   160
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   161
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   162
                   new PriorityBlockingQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   163
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   164
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   165
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   166
                   new PriorityQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   167
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   168
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   169
                   new PriorityBlockingQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   170
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   171
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   172
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   173
                   new PriorityQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   174
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   175
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   176
                   new PriorityBlockingQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   177
               }});
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   178
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   179
    }
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   180
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   181
    //--------------------- Infrastructure ---------------------------
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   182
    volatile int passed = 0, failed = 0;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   183
    void pass() {passed++;}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   184
    void fail() {failed++; Thread.dumpStack();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   185
    void fail(String msg) {System.err.println(msg); fail();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   186
    void unexpected(Throwable t) {failed++; t.printStackTrace();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   187
    void check(boolean cond) {if (cond) pass(); else fail();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   188
    void equal(Object x, Object y) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   189
        if (x == null ? y == null : x.equals(y)) pass();
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   190
        else fail(x + " not equal to " + y);}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   191
    public static void main(String[] args) throws Throwable {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   192
        new NoNulls().instanceMain(args);}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   193
    public void instanceMain(String[] args) throws Throwable {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   194
        try {test(args);} catch (Throwable t) {unexpected(t);}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   195
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   196
        if (failed > 0) throw new AssertionError("Some tests failed");}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   197
    abstract class F {abstract void f() throws Throwable;}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   198
    void THROWS(Class<? extends Throwable> k, F... fs) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   199
        for (F f : fs)
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   200
            try {f.f(); fail("Expected " + k.getName() + " not thrown");}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   201
            catch (Throwable t) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   202
                if (k.isAssignableFrom(t.getClass())) pass();
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   203
                else unexpected(t);}}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   204
}