Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/test/java/util/prefs/RemoveNullKeyCheck.java
+++ new/test/java/util/prefs/RemoveNullKeyCheck.java
1 1 /*
2 2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 */
23 23
24 24 /* @test
25 - * @bug 7160242
25 + * @bug 7160242 7165118
26 26 * @summary Check if NullPointerException is thrown if the key passed
27 27 * to remove() is null.
28 28 */
29 29
30 30 import java.util.prefs.Preferences;
31 +import java.util.prefs.AbstractPreferences;
32 +import java.util.prefs.BackingStoreException;
31 33
32 34 public class RemoveNullKeyCheck {
33 35
36 + private static boolean failed = false;
37 +
34 38 public static void main(String[] args) throws Exception {
35 - try {
36 - Preferences node = Preferences.userRoot().node("N1");
37 - node.remove(null);
38 - throw new RuntimeException("Expected NullPointerException " +
39 - "not thrown");
40 - } catch (NullPointerException npe) {
41 - System.out.println("NullPointerException thrown");
42 - }
39 + checkPreferencesRemove();
40 + checkAbstractPreferencesRemove();
41 + if (failed) {
42 + throw new RuntimeException("Expected NullPointerException " +
43 + "not thrown");
44 + }
43 45 }
46 +
47 + public static void checkPreferencesRemove() {
48 + try {
49 + Preferences node = Preferences.userRoot().node("N1");
50 + node.remove(null);
51 + failed = true;
52 + } catch (NullPointerException npe) {
53 + }
54 + }
55 +
56 + public static void checkAbstractPreferencesRemove() {
57 +
58 + Preferences abstrPrefs = new AbstractPreferences(null, "") {
59 + @Override
60 + protected void putSpi(String key, String value) {
61 + }
62 + @Override
63 + protected String getSpi(String key) {
64 + return null;
65 + }
66 + @Override
67 + protected void removeSpi(String key) {
68 + }
69 + @Override
70 + protected void removeNodeSpi() throws BackingStoreException {
71 + }
72 + @Override
73 + protected String[] keysSpi() throws BackingStoreException {
74 + return new String[0];
75 + }
76 + @Override
77 + protected String[] childrenNamesSpi() throws BackingStoreException {
78 + return new String[0];
79 + }
80 + @Override
81 + protected AbstractPreferences childSpi(String name) {
82 + return null;
83 + }
84 + @Override
85 + protected void syncSpi() throws BackingStoreException {
86 + }
87 + @Override
88 + protected void flushSpi() throws BackingStoreException {
89 + }
90 + };
91 +
92 + try {
93 + abstrPrefs.remove(null);
94 + failed = true;
95 + } catch(NullPointerException npe) {
96 + }
97 + }
44 98 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX