jdk/test/java/util/prefs/RemoveNullKeyCheck.java
author khazra
Wed, 25 Apr 2012 12:31:31 -0700
changeset 12552 06a22aed06d1
child 12681 ebee74a1fd8c
permissions -rw-r--r--
7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx] Summary: Insert null check of argument in remove()'s implementation Reviewed-by: forax, chegar, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12552
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     1
/*
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     4
 *
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     7
 * published by the Free Software Foundation.
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     8
 *
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    13
 * accompanied this code).
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    14
 *
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    18
 *
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    21
 * questions.
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    22
 */
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    23
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    24
/* @test
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    25
 * @bug 7160242
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    26
 * @summary Check if NullPointerException is thrown if the key passed
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    27
 *          to remove() is null.
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    28
 */
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    29
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    30
import java.util.prefs.Preferences;
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    31
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    32
public class RemoveNullKeyCheck {
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    33
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    34
    public static void main(String[] args) throws Exception {
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    35
       try {
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    36
           Preferences node = Preferences.userRoot().node("N1");
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    37
           node.remove(null);
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    38
           throw new RuntimeException("Expected NullPointerException " +
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    39
                                      "not thrown");
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    40
       } catch (NullPointerException npe) {
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    41
           System.out.println("NullPointerException thrown");
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    42
       }
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    43
    }
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    44
}