changeset 58351:055991789807

8240881: [BACKOUT] 8222489 jcmd VM.system_properties gives unusable paths on Windows Summary: Undo the 8222489 changeset Reviewed-by: dcubed, iklam
author sspitsyn
date Wed, 11 Mar 2020 20:28:43 +0000
parents 3a3ce5f3e2f7
children d462f05faa2d
files src/java.base/share/classes/jdk/internal/vm/VMSupport.java test/jdk/sun/tools/jcmd/TestVM.java
diffstat 2 files changed, 9 insertions(+), 110 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/vm/VMSupport.java	Wed Mar 11 17:09:10 2020 +0000
+++ b/src/java.base/share/classes/jdk/internal/vm/VMSupport.java	Wed Mar 11 20:28:43 2020 +0000
@@ -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 @@
      */
     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());
     }
--- a/test/jdk/sun/tools/jcmd/TestVM.java	Wed Mar 11 17:09:10 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -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");
-    }
-}