Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8240881: [BACKOUT] 8222489 jcmd VM.system_properties gives unusable p…
…aths on Windows

Undo the 8222489 changeset

Reviewed-by: dcubed, iklam
  • Loading branch information
Serguei Spitsyn committed Mar 11, 2020
1 parent 8c6649d commit db69852ac222e15db02ed84f8a2901dd1ffb5c84
Showing with 9 additions and 110 deletions.
  1. +9 −51 src/java.base/share/classes/jdk/internal/vm/VMSupport.java
  2. +0 −59 test/jdk/sun/tools/jcmd/TestVM.java
@@ -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.
*
* This code is free software; you can redistribute it and/or modify it
@@ -26,16 +26,8 @@

import java.io.ByteArrayOutputStream;
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.Set;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import java.util.jar.Attributes;
@@ -65,54 +57,20 @@ public static synchronized Properties getAgentProperties() {
*/
private static byte[] serializePropertiesToByteArray(Properties p) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
PrintWriter bw = new PrintWriter(new OutputStreamWriter(out, "8859_1"));

bw.println("#" + new Date().toString());
Properties props = new Properties();

try {
for (String key : p.stringPropertyNames()) {
String val = p.getProperty(key);
key = toISO88591(toEscapeSpecialChar(toEscapeSpace(key)));
val = toISO88591(toEscapeSpecialChar(val));
bw.println(key + "=" + val);
}
} catch (CharacterCodingException e) {
throw new RuntimeException(e);
// stringPropertyNames() returns a snapshot of the property keys
Set<String> keyset = p.stringPropertyNames();
for (String key : keyset) {
String value = p.getProperty(key);
props.put(key, value);
}
bw.flush();

props.store(out, null);
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 {
return serializePropertiesToByteArray(System.getProperties());
}

This file was deleted.

0 comments on commit db69852

Please sign in to comment.