Skip to content

Commit 104e925

Browse files
author
Brian Burkhalter
committedApr 5, 2021
8264512: jdk/test/jdk/java/util/prefs/ExportNode.java relies on default platform encoding
Reviewed-by: naoto
1 parent a0ec2cb commit 104e925

File tree

1 file changed

+39
-18
lines changed

1 file changed

+39
-18
lines changed
 

‎test/jdk/java/util/prefs/ExportNode.java

+39-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -30,25 +30,46 @@
3030
* @run main/othervm -Djava.util.prefs.userRoot=. ExportNode
3131
* @author Konstantin Kladko
3232
*/
33-
import java.util.prefs.*;
34-
import java.io.*;
33+
34+
import java.io.ByteArrayOutputStream;
35+
import java.io.IOException;
36+
import java.util.prefs.BackingStoreException;
37+
import java.util.prefs.Preferences;
3538

3639
public class ExportNode {
40+
private static final String NODE_NAME_1 = "ExportNodeTestName1";
41+
private static final String NODE_NAME_2 = "ExportNodeTestName2";
42+
3743
public static void main(String[] args) throws
38-
BackingStoreException, IOException {
39-
Preferences N1 = Preferences.userRoot().node("ExportNodeTest1");
40-
N1.put("ExportNodeTestName1","ExportNodeTestValue1");
41-
Preferences N2 = N1.node("ExportNodeTest2");
42-
N2.put("ExportNodeTestName2","ExportNodeTestValue2");
43-
ByteArrayOutputStream exportStream = new ByteArrayOutputStream();
44-
N2.exportNode(exportStream);
45-
46-
// Removal of preference node should always succeed on Solaris/Linux
47-
// by successfully acquiring the appropriate file lock (4947349)
48-
N1.removeNode();
49-
50-
if (((exportStream.toString()).lastIndexOf("ExportNodeTestName2")== -1) ||
51-
((exportStream.toString()).lastIndexOf("ExportNodeTestName1")!= -1)) {
52-
}
44+
BackingStoreException, IOException {
45+
Preferences N1 = Preferences.userRoot().node("ExportNodeTest1");
46+
N1.put(NODE_NAME_1,"ExportNodeTestValue1");
47+
Preferences N2 = N1.node("ExportNodeTest2");
48+
N2.put(NODE_NAME_2,"ExportNodeTestValue2");
49+
ByteArrayOutputStream exportStream = new ByteArrayOutputStream();
50+
N2.exportNode(exportStream);
51+
52+
// Removal of preference node should always succeed on Solaris/Linux
53+
// by successfully acquiring the appropriate file lock (4947349)
54+
N1.removeNode();
55+
56+
String streamAsString = exportStream.toString("UTF-8");
57+
58+
StringBuilder sb = null;
59+
if (streamAsString.lastIndexOf(NODE_NAME_2) == -1) {
60+
if (sb == null)
61+
sb = new StringBuilder();
62+
sb.append(NODE_NAME_2 + " should have been found");
63+
}
64+
if (streamAsString.lastIndexOf(NODE_NAME_1) != -1) {
65+
if (sb == null)
66+
sb = new StringBuilder();
67+
else
68+
sb.append("; ");
69+
sb.append(NODE_NAME_1 + " should *not* have been found");
70+
}
71+
72+
if (sb != null)
73+
throw new RuntimeException(sb.toString());
5374
}
5475
}

0 commit comments

Comments
 (0)
Please sign in to comment.