jdk/test/java/util/prefs/RemoveNullKeyCheck.java
author duke
Wed, 05 Jul 2017 22:06:37 +0200
changeset 40471 ad45133ff99e
parent 14694 6d6d54dc0ae1
permissions -rw-r--r--
Merge
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
14694
6d6d54dc0ae1 7197662: (prefs) java/util/prefs/AddNodeChangeListener.java fails by timeout or by "couldn't get file lock"
khazra
parents: 12681
diff changeset
    25
 * @bug 7160242 7165118 7197662
12552
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.
14694
6d6d54dc0ae1 7197662: (prefs) java/util/prefs/AddNodeChangeListener.java fails by timeout or by "couldn't get file lock"
khazra
parents: 12681
diff changeset
    28
 * @run main/othervm -Djava.util.prefs.userRoot=. RemoveNullKeyCheck
12552
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
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    31
import java.util.prefs.Preferences;
12681
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    32
import java.util.prefs.AbstractPreferences;
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    33
import java.util.prefs.BackingStoreException;
12552
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    34
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    35
public class RemoveNullKeyCheck {
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    36
12681
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    37
    private static boolean failed = false;
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    38
12552
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    39
    public static void main(String[] args) throws Exception {
12681
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    40
        checkPreferencesRemove();
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    41
        checkAbstractPreferencesRemove();
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    42
        if (failed) {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    43
            throw new RuntimeException("Expected NullPointerException " +
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    44
                                       "not thrown");
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    45
        }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    46
    }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    47
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    48
    public static void checkPreferencesRemove() {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    49
        try {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    50
            Preferences node = Preferences.userRoot().node("N1");
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    51
            node.remove(null);
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    52
            failed = true;
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    53
        } catch (NullPointerException npe) {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    54
        }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    55
    }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    56
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    57
    public static void checkAbstractPreferencesRemove() {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    58
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    59
        Preferences abstrPrefs = new AbstractPreferences(null, "") {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    60
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    61
            protected void putSpi(String key, String value) {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    62
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    63
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    64
            protected String getSpi(String key) {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    65
                return null;
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    66
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    67
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    68
            protected void removeSpi(String key) {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    69
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    70
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    71
            protected void removeNodeSpi() throws BackingStoreException {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    72
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    73
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    74
            protected String[] keysSpi() throws BackingStoreException {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    75
                return new String[0];
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    76
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    77
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    78
            protected String[] childrenNamesSpi() throws BackingStoreException {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    79
                return new String[0];
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    80
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    81
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    82
            protected AbstractPreferences childSpi(String name) {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    83
                return null;
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    84
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    85
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    86
            protected void syncSpi() throws BackingStoreException {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    87
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    88
            @Override
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    89
            protected void flushSpi() throws BackingStoreException {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    90
            }
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    91
        };
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    92
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    93
        try {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    94
            abstrPrefs.remove(null);
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    95
            failed = true;
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    96
        } catch(NullPointerException npe) {
ebee74a1fd8c 7165118: (prefs) AbstractPreferences.remove(null) does not throw NPE
khazra
parents: 12552
diff changeset
    97
        }
12552
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    98
    }
06a22aed06d1 7160242: (prefs) Preferences.remove(null) does not throw NPE [macosx]
khazra
parents:
diff changeset
    99
}