jdk/test/java/util/prefs/CodePointZeroPrefsTest.java
author bpb
Fri, 13 Mar 2015 15:03:42 -0700
changeset 29487 7b3804573b41
parent 29397 65faf3bd73ad
child 30043 b0dd05ec3db1
permissions -rw-r--r--
8075110: (prefs) CodePointZeroPrefsTest fails on certain platforms Summary: Contrain test to the Linux and Solaris OS families Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29397
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     1
/*
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     4
 *
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     8
 *
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    13
 * accompanied this code).
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    14
 *
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    18
 *
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    21
 * questions.
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    22
 */
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    23
import java.lang.reflect.Constructor;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    24
import java.util.prefs.Preferences;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    25
import java.util.prefs.PreferencesFactory;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    26
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    27
/*
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    28
 * @test
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    29
 * @bug 8068373
29487
7b3804573b41 8075110: (prefs) CodePointZeroPrefsTest fails on certain platforms
bpb
parents: 29397
diff changeset
    30
 * @requires os.family == "linux" | os.family == "solaris"
29397
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    31
 * @summary Ensure writing a code point U+0000 null control character is detected.
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    32
 */
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    33
public class CodePointZeroPrefsTest
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    34
{
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    35
    public static void main(String[] args) throws Exception
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    36
    {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    37
        int failures = 0;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    38
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    39
        // Deliberately reflect so you can reproduce it on any platform.
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    40
        Constructor<? extends PreferencesFactory> constructor =
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    41
            Class.forName("java.util.prefs.FileSystemPreferencesFactory").asSubclass(PreferencesFactory.class).getDeclaredConstructor();
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    42
        constructor.setAccessible(true);
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    43
        PreferencesFactory factory = constructor.newInstance();
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    44
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    45
        Preferences node = factory.userRoot().node("com/acme/testing");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    46
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    47
        // legal key and value
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    48
        try {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    49
            node.put("a", "1");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    50
        } catch (IllegalArgumentException iae) {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    51
            System.err.println("Unexpected IllegalArgumentException for legal key");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    52
            failures++;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    53
        }
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    54
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    55
        // illegal key only
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    56
        int numIAEs = 0;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    57
        try {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    58
            node.put("a\u0000b", "1");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    59
            System.err.println("IllegalArgumentException not thrown for illegal key");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    60
            failures++;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    61
        } catch (IllegalArgumentException iae) {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    62
            // do nothing
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    63
        }
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    64
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    65
        // illegal value only
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    66
        numIAEs = 0;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    67
        try {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    68
            node.put("ab", "2\u00003");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    69
            System.err.println("IllegalArgumentException not thrown for illegal value");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    70
            failures++;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    71
        } catch (IllegalArgumentException iae) {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    72
            // do nothing
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    73
        }
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    74
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    75
        // illegal key and value
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    76
        numIAEs = 0;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    77
        try {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    78
            node.put("a\u0000b", "2\u00003");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    79
            System.err.println("IllegalArgumentException not thrown for illegal entry");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    80
            failures++;
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    81
        } catch (IllegalArgumentException iae) {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    82
            // do nothing
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    83
        }
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    84
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    85
        if (failures != 0) {
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    86
            throw new RuntimeException("CodePointZeroPrefsTest failed with "
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    87
                + failures + " errors!");
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    88
        }
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    89
    }
65faf3bd73ad 8068373: (prefs) FileSystemPreferences writes \0 to XML storage, causing loss of all preferences
bpb
parents:
diff changeset
    90
}