Skip to content

Commit

Permalink
8264512: jdk/test/jdk/java/util/prefs/ExportNode.java relies on defau…
Browse files Browse the repository at this point in the history
…lt platform encoding

Backport-of: 104e925
  • Loading branch information
GoeLin committed Feb 17, 2023
1 parent eb8c6f5 commit ffac38f
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions test/jdk/java/util/prefs/ExportNode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -30,25 +30,46 @@
* @run main/othervm -Djava.util.prefs.userRoot=. ExportNode
* @author Konstantin Kladko
*/
import java.util.prefs.*;
import java.io.*;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;

public class ExportNode {
private static final String NODE_NAME_1 = "ExportNodeTestName1";
private static final String NODE_NAME_2 = "ExportNodeTestName2";

public static void main(String[] args) throws
BackingStoreException, IOException {
Preferences N1 = Preferences.userRoot().node("ExportNodeTest1");
N1.put("ExportNodeTestName1","ExportNodeTestValue1");
Preferences N2 = N1.node("ExportNodeTest2");
N2.put("ExportNodeTestName2","ExportNodeTestValue2");
ByteArrayOutputStream exportStream = new ByteArrayOutputStream();
N2.exportNode(exportStream);

// Removal of preference node should always succeed on Solaris/Linux
// by successfully acquiring the appropriate file lock (4947349)
N1.removeNode();

if (((exportStream.toString()).lastIndexOf("ExportNodeTestName2")== -1) ||
((exportStream.toString()).lastIndexOf("ExportNodeTestName1")!= -1)) {
}
BackingStoreException, IOException {
Preferences N1 = Preferences.userRoot().node("ExportNodeTest1");
N1.put(NODE_NAME_1,"ExportNodeTestValue1");
Preferences N2 = N1.node("ExportNodeTest2");
N2.put(NODE_NAME_2,"ExportNodeTestValue2");
ByteArrayOutputStream exportStream = new ByteArrayOutputStream();
N2.exportNode(exportStream);

// Removal of preference node should always succeed on Solaris/Linux
// by successfully acquiring the appropriate file lock (4947349)
N1.removeNode();

String streamAsString = exportStream.toString("UTF-8");

StringBuilder sb = null;
if (streamAsString.lastIndexOf(NODE_NAME_2) == -1) {
if (sb == null)
sb = new StringBuilder();
sb.append(NODE_NAME_2 + " should have been found");
}
if (streamAsString.lastIndexOf(NODE_NAME_1) != -1) {
if (sb == null)
sb = new StringBuilder();
else
sb.append("; ");
sb.append(NODE_NAME_1 + " should *not* have been found");
}

if (sb != null)
throw new RuntimeException(sb.toString());
}
}

1 comment on commit ffac38f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.