mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8240881: [BACKOUT] 8222489 jcmd VM.system_properties gives unusable paths on Windows
Undo the 8222489 changeset Reviewed-by: dcubed, iklam
This commit is contained in:
parent
8c6649dea0
commit
db69852ac2
2 changed files with 9 additions and 110 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -26,16 +26,8 @@ package jdk.internal.vm;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.CharBuffer;
|
|
||||||
import java.nio.charset.CharacterCodingException;
|
|
||||||
import java.nio.charset.CoderResult;
|
|
||||||
import java.nio.charset.CodingErrorAction;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.jar.JarFile;
|
import java.util.jar.JarFile;
|
||||||
import java.util.jar.Manifest;
|
import java.util.jar.Manifest;
|
||||||
import java.util.jar.Attributes;
|
import java.util.jar.Attributes;
|
||||||
|
@ -65,54 +57,20 @@ public class VMSupport {
|
||||||
*/
|
*/
|
||||||
private static byte[] serializePropertiesToByteArray(Properties p) throws IOException {
|
private static byte[] serializePropertiesToByteArray(Properties p) throws IOException {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
|
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
|
||||||
PrintWriter bw = new PrintWriter(new OutputStreamWriter(out, "8859_1"));
|
|
||||||
|
|
||||||
bw.println("#" + new Date().toString());
|
Properties props = new Properties();
|
||||||
|
|
||||||
try {
|
// stringPropertyNames() returns a snapshot of the property keys
|
||||||
for (String key : p.stringPropertyNames()) {
|
Set<String> keyset = p.stringPropertyNames();
|
||||||
String val = p.getProperty(key);
|
for (String key : keyset) {
|
||||||
key = toISO88591(toEscapeSpecialChar(toEscapeSpace(key)));
|
String value = p.getProperty(key);
|
||||||
val = toISO88591(toEscapeSpecialChar(val));
|
props.put(key, value);
|
||||||
bw.println(key + "=" + val);
|
|
||||||
}
|
|
||||||
} catch (CharacterCodingException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
bw.flush();
|
|
||||||
|
|
||||||
|
props.store(out, null);
|
||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String toEscapeSpecialChar(String source) {
|
|
||||||
return source.replace("\t", "\\t").replace("\n", "\\n").replace("\r", "\\r").replace("\f", "\\f");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String toEscapeSpace(String source) {
|
|
||||||
return source.replace(" ", "\\ ");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String toISO88591(String source) throws CharacterCodingException {
|
|
||||||
var charBuf = CharBuffer.wrap(source);
|
|
||||||
// 6 is 2 bytes for '\\u' as String and 4 bytes for code point.
|
|
||||||
var byteBuf = ByteBuffer.allocate(charBuf.length() * 6);
|
|
||||||
var encoder = StandardCharsets.ISO_8859_1
|
|
||||||
.newEncoder()
|
|
||||||
.onUnmappableCharacter(CodingErrorAction.REPORT);
|
|
||||||
|
|
||||||
CoderResult result;
|
|
||||||
do {
|
|
||||||
result = encoder.encode(charBuf, byteBuf, false);
|
|
||||||
if (result.isUnmappable()) {
|
|
||||||
byteBuf.put(String.format("\\u%04X", (int)charBuf.get()).getBytes());
|
|
||||||
} else if (result.isError()) {
|
|
||||||
result.throwException();
|
|
||||||
}
|
|
||||||
} while (result.isError());
|
|
||||||
|
|
||||||
return new String(byteBuf.array(), 0, byteBuf.position());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static byte[] serializePropertiesToByteArray() throws IOException {
|
public static byte[] serializePropertiesToByteArray() throws IOException {
|
||||||
return serializePropertiesToByteArray(System.getProperties());
|
return serializePropertiesToByteArray(System.getProperties());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2020, 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
|
|
||||||
* under the terms of the GNU General Public License version 2 only, as
|
|
||||||
* published by the Free Software Foundation.
|
|
||||||
*
|
|
||||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
||||||
* version 2 for more details (a copy is included in the LICENSE file that
|
|
||||||
* accompanied this code).
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License version
|
|
||||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
||||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
*
|
|
||||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
||||||
* or visit www.oracle.com if you need additional information or have any
|
|
||||||
* questions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import jdk.test.lib.process.OutputAnalyzer;
|
|
||||||
import jdk.test.lib.Platform;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* @test
|
|
||||||
* @bug 8222489
|
|
||||||
* @summary Unit test for jcmd utility. The test will send different diagnostic
|
|
||||||
* command requests to the current java process.
|
|
||||||
*
|
|
||||||
* @library /test/lib
|
|
||||||
*
|
|
||||||
* @run main/othervm TestVM
|
|
||||||
*/
|
|
||||||
public class TestVM {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
System.setProperty("normal", "normal_val");
|
|
||||||
System.setProperty("nonascii", "\u3042\u3044\u3046\u3048\u304A");
|
|
||||||
System.setProperty("url", "http://openjdk.java.net/");
|
|
||||||
System.setProperty("winDir", "C:\\");
|
|
||||||
System.setProperty("mix", "a\u3044u\u3048\u304Aka");
|
|
||||||
System.setProperty("space space", "blank blank");
|
|
||||||
|
|
||||||
OutputAnalyzer output = JcmdBase.jcmd("VM.system_properties");
|
|
||||||
output.shouldNotContain("https\\:");
|
|
||||||
output.shouldNotContain("C\\:\\\\");
|
|
||||||
|
|
||||||
output.shouldContain("normal=normal_val");
|
|
||||||
output.shouldContain("nonascii=\\u3042\\u3044\\u3046\\u3048\\u304A");
|
|
||||||
output.shouldContain("url=http://openjdk.java.net/");
|
|
||||||
output.shouldContain("winDir=C:\\");
|
|
||||||
output.shouldContain("mix=a\\u3044u\\u3048\\u304Aka");
|
|
||||||
output.shouldContain("space\\ space=blank blank");
|
|
||||||
output.shouldContain(Platform.isWindows() ? "line.separator=\\r\\n" : "line.separator=\\n");
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue