--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/BlankLines.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4218776
+ * @summary Test loading of properties files with blank lines
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+/**
+ * This class tests to see if a properties object correctly handles blank
+ * lines in a properties file
+ */
+public class BlankLines {
+ public static void main(String []args)
+ {
+ try {
+ // create test file
+ File file = new File("test.properties");
+
+ // write a single space to the test file
+ FileOutputStream fos = new FileOutputStream(file);
+ fos.write(' ');
+ fos.close();
+
+ // test empty properties
+ Properties prop1 = new Properties();
+
+ // now load the file we just created, into a
+ // properties object.
+ // the properties object should have no elements,
+ // but due to a bug, it has an empty key/value.
+ // key = "", value = ""
+ Properties prop2 = new Properties();
+ InputStream is = new FileInputStream(file);
+ try {
+ prop2.load(is);
+ } finally {
+ is.close();
+ }
+ if (!prop1.equals(prop2))
+ throw new RuntimeException("Incorrect properties loading.");
+
+ // cleanup
+ file.delete();
+ }
+ catch(IOException e) {}
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/CloseXMLStream.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 6270682
+ * @summary Test the input stream is closed after loadtoXML returns.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.util.Properties;
+
+public class CloseXMLStream {
+ public static void main(String[] args) throws Throwable {
+ class ExpectedClosingException extends RuntimeException {};
+ Properties props = new Properties();
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ props.storeToXML(out, null);
+ ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()) {
+ public void close() {
+ throw new ExpectedClosingException();
+ }
+ };
+ try {
+ props.loadFromXML(in);
+ throw new Exception("Failed: loadFromXML does not close the is!");
+ } catch (ExpectedClosingException ex) { /*OK*/ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/EscapeSpace.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4219644
+ * @summary Escaping of spaces required only for leading spaces in the value
+ * part of the property.
+ */
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+public class EscapeSpace {
+
+ static String props =
+ "key1=\\ \\ Value1, has leading and trailing spaces\\ \n" +
+ "key2=Value2,\\ does not have\\ leading or trailing\\ spaces\n" +
+ "key3=Value3,has,no,spaces\n" +
+ "key4=Value4, does not have leading spaces\\ \n" +
+ "key5=\\t\\ \\ Value5, has leading tab and no trailing spaces\n" +
+ "key6=\\ \\ Value6,doesnothaveembeddedspaces\\ \\ \n" +
+ "\\ key1\\ test\\ =key1, has leading and trailing spaces \n" +
+ "key2\\ test=key2, does not have leading or trailing spaces\n" +
+ "key3test=key3,has,no,spaces\n" +
+ "key4\\ test\\ =key4, does not have leading spaces \n" +
+ "\\t\\ key5\\ test=key5, has leading tab and no trailing spaces\n" +
+ "\\ \\ key6\\ \\ =\\ key6,doesnothaveembeddedspaces ";
+ static void load(Properties p, String file) throws Exception
+ {
+ FileInputStream fis = null;
+ BufferedInputStream bis = null;
+
+ try {
+ fis = new FileInputStream(file);
+ bis = new BufferedInputStream( fis );
+
+ p.load(bis);
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e.getMessage());
+ } finally {
+ if (fis != null)
+ fis.close();
+ }
+ }
+
+ static void store(Properties p, String file) throws Exception
+ {
+
+ FileOutputStream fos = null;
+ BufferedOutputStream bos = null;
+
+ try {
+ fos = new FileOutputStream(file);
+ bos = new BufferedOutputStream( fos );
+
+ p.store( bos, "Omitting escape characters for non leading space \" \" in properties");
+ }
+ catch (IOException e) {
+ throw new RuntimeException(e.getMessage());
+ } finally {
+ if (fos != null)
+ fos.close();
+ }
+ }
+
+ public static void main( String args[] ) throws Exception
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(props.getBytes());
+ Properties props0 = new Properties();
+ // Load properties with escape character '\' before space characters
+ try {
+ props0.load(bais);
+ } catch (IOException e) {
+ throw new RuntimeException(e.getMessage());
+ }
+
+ Properties props1 = new Properties();
+ /*
+ * Put the same properties, but without the escape char for space in
+ * value part.
+ */
+ props1.put( "key1", " Value1, has leading and trailing spaces " );
+ props1.put( "key2",
+ "Value2, does not have leading or trailing spaces" );
+ props1.put( "key3", "Value3,has,no,spaces" );
+ props1.put( "key4", "Value4, does not have leading spaces " );
+ props1.put( "key5",
+ "\t Value5, has leading tab and no trailing spaces" );
+ props1.put( "key6", " Value6,doesnothaveembeddedspaces " );
+ props1.put( " key1 test ", "key1, has leading and trailing spaces " );
+ props1.put( "key2 test",
+ "key2, does not have leading or trailing spaces" );
+ props1.put( "key3test", "key3,has,no,spaces" );
+ props1.put( "key4 test ", "key4, does not have leading spaces " );
+ props1.put( "\t key5 test",
+ "key5, has leading tab and no trailing spaces" );
+ props1.put( " key6 ", " key6,doesnothaveembeddedspaces " );
+
+ // Check if both the properties match
+ if (!props0.equals(props1))
+ throw new RuntimeException("Test failed");
+
+
+ // Also store the new properties to a file
+ store(props1, "out1.props");
+
+ Properties props2 = new Properties();
+ // Reread the properties from the file
+ load(props2, "out1.props");
+
+ // Make sure that the properties match
+ if (!props1.equals(props2))
+ throw new RuntimeException("Test failed");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/GenerifiedUses.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 5060820 5054615 5056707 5061476
+ * @modules java.desktop
+ * java.naming
+ * @compile GenerifiedUses.java
+ */
+
+import java.awt.image.CropImageFilter;
+import java.awt.image.ImageFilter;
+import java.awt.image.PixelGrabber;
+import java.awt.image.ReplicateScaleFilter;
+import java.util.Properties;
+import javax.naming.InitialContext;
+import javax.naming.directory.InitialDirContext;
+import javax.naming.spi.NamingManager;
+
+public class GenerifiedUses {
+
+ static void foo() throws Exception {
+
+ Properties props = new Properties();
+
+ // 5060820
+ new InitialDirContext(props);
+
+ // 5054615
+ new InitialContext(props);
+
+ // 5056707
+ NamingManager.getObjectInstance(null, null, null, props);
+
+ // 5061476
+ new CropImageFilter(0, 0, 0, 0).setProperties(props);
+ new ImageFilter().setProperties(props);
+ new PixelGrabber(null, 0, 0, 0, 0, false).setProperties(props);
+ new ReplicateScaleFilter(1, 1).setProperties(props);
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/LoadParsing.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4115936 4385195 4972297
+ * @summary checks for processing errors in properties.load
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.Properties;
+
+public class LoadParsing {
+ public static void main(String[] argv) throws Exception {
+ File f = new File(System.getProperty("test.src", "."), "input.txt");
+ FileInputStream myIn = new FileInputStream(f);
+ Properties myProps = new Properties();
+ int size = 0;
+ try {
+ myProps.load(myIn);
+ } finally {
+ myIn.close();
+ }
+
+ if (!myProps.getProperty("key1").equals("value1"))
+ throw new RuntimeException("Bad comment parsing");
+ if (!myProps.getProperty("key2").equals("abc\\defg\\"))
+ throw new RuntimeException("Bad slash parsing");
+ if (!myProps.getProperty("key3").equals("value3"))
+ throw new RuntimeException("Adds spaces to key");
+ if (!myProps.getProperty("key4").equals(":value4"))
+ throw new RuntimeException("Bad separator parsing");
+ if (myProps.getProperty("#") != null)
+ throw new RuntimeException(
+ "Does not recognize comments with leading spaces");
+ if ((size=myProps.size()) != 4)
+ throw new RuntimeException(
+ "Wrong number of keys in Properties; expected 4, got " +
+ size + ".");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/LoadParsing2.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4881291 4094886
+ * @summary checks for processing errors in properties.load
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+public class LoadParsing2 {
+ public static void main(String[] argv) throws Exception {
+ for (int i = 0; i < dfiles.length; i++) {
+ test(dfiles[i], keys[i], values[i], true);
+ test(dfiles[i], keys[i], values[i], false);
+ }
+ }
+
+ private static Properties getLoadedProperties(InputStream is,
+ boolean doStream)
+ throws Exception
+ {
+ Properties props = new Properties();
+ if (doStream)
+ props.load(is);
+ else
+ props.load(new InputStreamReader(is, "UTF-8"));
+ return props;
+ }
+
+ private static void test(String fnData,
+ String[] keys,
+ String[] values,
+ boolean doStream)
+ throws Exception
+ {
+ File f = new File(System.getProperty("test.src", "."), fnData);
+ FileInputStream myIn = new FileInputStream(f);
+ Properties myProps = getLoadedProperties(myIn, doStream);
+ for (int i = 0; i < keys.length; i++) {
+ if (!myProps.getProperty(keys[i]).equals(values[i])) {
+ throw new RuntimeException("Test1: Bad parsing at " + i);
+ }
+ }
+ }
+
+ static String[] keys1 = {
+ "\\",
+ "\\:key12",
+ "key16 b",
+ "key14_asdfa",
+ "\\\\",
+ "key8notassign",
+ "key17",
+ "key15",
+ "keyabcdef",
+ "key13dialog.3",
+ "key7",
+ "key6",
+ "key5",
+ "key3",
+ "key2",
+ "key1",
+ "key9 Term",
+ "key0"
+ };
+
+ static String[] keys2 = {
+ "key1",
+ "key2"
+ };
+
+ static String[] keys3 = {
+ "key1",
+ "key2"
+ };
+
+ static String[] values1 = {
+ "key10=bar",
+ "bar2",
+ " abcdef",
+ "",
+ "key11=bar2",
+ "abcdef",
+ "#barbaz",
+ " abcdef",
+ "",
+ "",
+ "Symbol,SYMBOL_CHARSET ",
+ "WingDings,SYMBOL_CHARSET \\abc",
+ "==Arial,ANSI_CHARSET",
+ "",
+ "= abcde",
+ "value1",
+ "ABCDE",
+ "abcd"
+ };
+
+ static String[] values2 = {
+ "-monotype-timesnewroman-regular-r---*-%d-*-*-p-*-iso8859-1serif.1a-monotype-timesnewroman-regular-r-normal--*-%d-*-*-p-*-iso8859-2serif.2a-b&h-LucidaBrightLat4-Normal-r-normal--*-%d-*-*-p-*-iso8859-4serif.3a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-5serif.4a-monotype-timesnewromangreek-regular-r-normal--*-%d-*-*-p-*-iso8859-7serif.5a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-9serif.6a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-15serif.7a-hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1serif.8a-sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0serif.9a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0serif.10a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0208.1983-0serif.11a-ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0serif.12a-hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3serif.13a-urw-itczapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificserif.14a-*-symbol-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificbserif.italic.0=-monotype-timesbnewbroman-regular-i---*-%d-*-*-p-*-iso8859-1bserif.italic.1=-monotype-timesbnewbroman-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-2",
+ "-b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4"
+ };
+
+ static String[] values3 = {
+ "-monotype-times new roman-regular-r---*-%d-*-*-p-*-iso8859-1, -monotype-times new roman-regular-r-normal--*-%d-*-*-p-*-iso8859-2, -b&h-LucidaBrightLat4-Normal-r-normal--*-%d-*-*-p-*-iso8859-4, -monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-5, -monotype-times new roman greek-regular-r-normal--*-%d-*-*-p-*-iso8859-7, -monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-9, -monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-15, -hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1, -sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0, -ricoh-hg gothic b-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0, -ricoh-hg gothic b-medium-r-normal-*-*-%d-*-*-m-*-jisx0208.1983-0, -ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0, -hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3",
+ "-monotype-times new roman-regular-i---*-%d-*-*-p-*-iso8859-1, -monotype-times new roman-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-2, -b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4, -monotype-times-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-5, -monotype-times new roman greek-regular-i-normal--*-%d-*-*-p-*-iso8859-7, -monotype-times-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-9, -monotype-times-regular-i-normal--*-%d-*-*-p-*-iso8859-15, -hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1, -sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0, -ricoh-hg gothic b-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0, -ricoh-hg gothic b-medium-r-normal-*-*-%d-*-*-m-*-jisx0208.1983-0, -ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0, -hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3"
+ };
+
+ static String[][] keys = {keys1, keys1, keys2, keys2, keys3};
+ static String[][] values = {values1, values1, values2, values2, values3};
+ static String[] dfiles = {
+ "testData1",
+ "testData1.dos",
+ "testData2",
+ "testData2.dos",
+ "testData3.dos"
+ };
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/LoadSeparators.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,76 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4192678
+ * @summary Test loading of values that are key value separators
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * This class tests to see if a properties object can successfully save and
+ * load properties with a non-escaped value that is also a key value separator
+ *
+ */
+public class LoadSeparators {
+ public static void main(String[] argv) throws Exception {
+ try {
+ // Destroy old test file if any
+ // Create a properties file
+ File propFile = new File("testout");
+ propFile.delete();
+
+ // Create a properties file
+ FileOutputStream myOut = new FileOutputStream(propFile);
+ String testProperty = "Test3==";
+ myOut.write(testProperty.getBytes());
+ myOut.close();
+
+ // Load the properties set
+ FileInputStream myIn = new FileInputStream("testout");
+ Properties myNewProps = new Properties();
+ try {
+ myNewProps.load(myIn);
+ } finally {
+ myIn.close();
+ }
+
+ // Read in the test property
+ String equalSign = myNewProps.getProperty("Test3");
+
+ // Clean up
+ propFile.delete();
+
+ if (!equalSign.equals("="))
+ throw new Exception("Cannot read key-value separators.");
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/PropertiesTest.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,494 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @summary tests the load and store methods of Properties class
+ * @author Xueming Shen
+ * @bug 4094886
+ * @modules jdk.charsets
+ * @key randomness
+ */
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.Properties;
+import java.util.Random;
+
+public class PropertiesTest {
+
+ private static boolean failure = false;
+ private static int failCount = 0;
+
+ /**
+ * Main to interpret arguments and run several tests.
+ *
+ */
+ public static void main(String[] args) throws Exception {
+ BlankLines();
+ EscapeSpace();
+ LoadParsing();
+ SaveEncoding();
+ SaveLoadBasher();
+ SaveSeparator();
+ SaveClose();
+ SaveComments();
+ UnicodeEscape();
+
+ if (failure)
+ throw new RuntimeException("Failure in Properties testing.");
+ else
+ System.err.println("OKAY: All tests passed.");
+ }
+
+ private static void report(String testName) {
+ int spacesToAdd = 30 - testName.length();
+ StringBuffer paddedNameBuffer = new StringBuffer(testName);
+ for (int i=0; i<spacesToAdd; i++)
+ paddedNameBuffer.append(" ");
+ String paddedName = paddedNameBuffer.toString();
+ System.err.println(paddedName + ": " +
+ (failCount==0 ? "Passed":"Failed("+failCount+")"));
+ if (failCount > 0)
+ failure = true;
+ failCount = 0;
+ }
+
+ private static void check(Properties prop1, Properties prop2) {
+ if (!prop1.equals(prop2))
+ failCount++;
+ }
+
+ private static Reader getReader(String src, String csn)
+ throws Exception {
+ return new InputStreamReader(
+ new ByteArrayInputStream(src.getBytes()),
+ csn);
+ }
+
+ private static OutputStream getFOS(String name)
+ throws Exception
+ {
+ return new FileOutputStream(name);
+ }
+
+ private static Writer getFOSW(String name, String csn)
+ throws Exception
+ {
+ return new OutputStreamWriter(
+ new FileOutputStream(name),
+ csn);
+ }
+
+ private static Reader getReader(byte[] src, String csn)
+ throws Exception {
+ return new InputStreamReader(new ByteArrayInputStream(src), csn);
+ }
+
+ private static InputStream getInputStream(String src) {
+ return new ByteArrayInputStream(src.getBytes());
+ }
+
+ private static InputStream getInputStream(byte[] src) {
+ return new ByteArrayInputStream(src);
+ }
+
+ private static void BlankLines() throws Exception {
+ // write a single space to the output stream
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ baos.write(' ');
+ // test empty properties
+ Properties prop1 = new Properties();
+
+ // now load the file we just created, into a properties object.
+ // the properties object should have no elements, but due to a
+ // bug, it has an empty key/value. key = "", value = ""
+ Properties prop2 = new Properties();
+ prop2.load(getInputStream(baos.toByteArray()));
+ check(prop1, prop2);
+
+ // test reader
+ prop2 = new Properties();
+ prop2.load(getReader(baos.toByteArray(), "UTF-8"));
+ check(prop1, prop2);
+
+ report("BlinkLine");
+ }
+
+ private static void EscapeSpace() throws Exception {
+ String propsCases =
+ "key1=\\ \\ Value\\u4e001, has leading and trailing spaces\\ \n" +
+ "key2=Value\\u4e002,\\ does not have\\ leading or trailing\\ spaces\n" +
+ "key3=Value\\u4e003,has,no,spaces\n" +
+ "key4=Value\\u4e004, does not have leading spaces\\ \n" +
+ "key5=\\t\\ \\ Value\\u4e005, has leading tab and no trailing spaces\n" +
+ "key6=\\ \\ Value\\u4e006,doesnothaveembeddedspaces\\ \\ \n" +
+ "\\ key1\\ test\\ =key1, has leading and trailing spaces \n" +
+ "key2\\ test=key2, does not have leading or trailing spaces\n" +
+ "key3test=key3,has,no,spaces\n" +
+ "key4\\ test\\ =key4, does not have leading spaces \n" +
+ "\\t\\ key5\\ test=key5, has leading tab and no trailing spaces\n" +
+ "\\ \\ key6\\ \\ =\\ key6,doesnothaveembeddedspaces ";
+
+ // Put the same properties, but without the escape char for space in
+ // value part.
+ Properties props = new Properties();
+ props.put("key1", " Value\u4e001, has leading and trailing spaces ");
+ props.put("key2", "Value\u4e002, does not have leading or trailing spaces");
+ props.put("key3", "Value\u4e003,has,no,spaces");
+ props.put("key4", "Value\u4e004, does not have leading spaces ");
+ props.put("key5", "\t Value\u4e005, has leading tab and no trailing spaces");
+ props.put("key6", " Value\u4e006,doesnothaveembeddedspaces ");
+ props.put(" key1 test ", "key1, has leading and trailing spaces ");
+ props.put("key2 test", "key2, does not have leading or trailing spaces");
+ props.put("key3test", "key3,has,no,spaces");
+ props.put("key4 test ", "key4, does not have leading spaces ");
+ props.put("\t key5 test", "key5, has leading tab and no trailing spaces");
+ props.put(" key6 ", " key6,doesnothaveembeddedspaces ");
+
+ // Load properties with escape character '\' before space characters
+ Properties props1 = new Properties();
+ props1.load(getInputStream(propsCases));
+ check(props1, props);
+
+ // Test Reader
+ props1 = new Properties();
+ props1.load(getReader(propsCases, "UTF-8"));
+ check(props1, props);
+
+ // Also store the new properties to a storage
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ props.store(baos, "EscapeSpace Test");
+
+ props1 = new Properties();
+ props1.load(getInputStream(baos.toByteArray()));
+ check(props1, props);
+
+ // Reader should work as well
+ props1 = new Properties();
+ props1.load(getReader(baos.toByteArray(), "UTF-8"));
+ check(props1, props);
+
+ // Try Writer
+ baos = new ByteArrayOutputStream();
+ props.store(new OutputStreamWriter(baos, "UTF-8"),
+ "EscapeSpace Test");
+
+ props1 = new Properties();
+ props1.load(getReader(baos.toByteArray(), "UTF-8"));
+ check(props1, props);
+
+ report("EscapeSpace");
+ }
+
+ private static void LoadParsing() throws Exception {
+ File f = new File(System.getProperty("test.src", "."), "input.txt");
+ FileInputStream myIn = new FileInputStream(f);
+ Properties myProps = new Properties();
+ int size = 0;
+ try {
+ myProps.load(myIn);
+ } finally {
+ myIn.close();
+ }
+
+ if (!myProps.getProperty("key1").equals("value1") || // comment
+ !myProps.getProperty("key2").equals("abc\\defg\\") || // slash
+ !myProps.getProperty("key3").equals("value3") || // spaces in key
+ !myProps.getProperty("key4").equals(":value4") || // separator
+ // Does not recognize comments with leading spaces
+ (myProps.getProperty("#") != null) ||
+ // Wrong number of keys in Properties
+ ((size=myProps.size()) != 4))
+ failCount++;
+ report("LoadParsing");
+ }
+
+ private static void SaveEncoding() throws Exception {
+ // Create a properties object to save
+ Properties props = new Properties();
+ props.put("signal", "val\u0019");
+ props.put("ABC 10", "value0");
+ props.put("\uff10test", "value\u0020");
+ props.put("key with spaces", "value with spaces");
+ props.put("key with space and Chinese_\u4e00", "valueWithChinese_\u4e00");
+ props.put(" special#=key ", "value3");
+
+ // Save the properties and check output
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ props.store(baos,"A test");
+
+ // Read properties file and verify \u0019
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(
+ new ByteArrayInputStream(
+ baos.toByteArray())));
+ String firstLine = "foo";
+ while (!firstLine.startsWith("signal"))
+ firstLine = in.readLine();
+ if (firstLine.length() != 16)
+ failCount++;
+
+ // Load the properties set
+ Properties newProps = new Properties();
+ newProps.load(getInputStream(baos.toByteArray()));
+ check(newProps, props);
+
+ // Store(Writer)/Load(Reader)
+ baos = new ByteArrayOutputStream();
+ props.store(new OutputStreamWriter(baos, "EUC_JP"), "A test");
+ newProps = new Properties();
+ newProps.load(getReader(baos.toByteArray(), "EUC_JP"));
+ check(newProps, props);
+
+ report("SaveEncoding");
+ }
+
+ /**
+ * This class tests to see if a properties object
+ * can successfully save and load properties
+ * using character encoding
+ */
+ private static void SaveLoadBasher() throws Exception {
+ String keyValueSeparators = "=: \t\r\n\f#!\\";
+
+ Properties originalProps = new Properties();
+ Properties loadedProps = new Properties();
+
+ // Generate a unicode key and value
+ Random generator = new Random();
+ int achar=0;
+ StringBuffer aKeyBuffer = new StringBuffer(120);
+ StringBuffer aValueBuffer = new StringBuffer(120);
+ String aKey;
+ String aValue;
+ int maxKeyLen = 100;
+ int maxValueLen = 100;
+ int maxPropsNum = 300;
+ for (int x=0; x<maxPropsNum; x++) {
+ for(int y=0; y<maxKeyLen; y++) {
+ achar = generator.nextInt();
+ char test;
+ if(achar < 99999) {
+ test = (char)(achar);
+ }
+ else {
+ int zz = achar % 10;
+ test = keyValueSeparators.charAt(zz);
+ }
+ if (Character.isHighSurrogate(test)) {
+ aKeyBuffer.append(test);
+ aKeyBuffer.append('\udc00');
+ y++;
+ } else if (Character.isLowSurrogate(test)) {
+ aKeyBuffer.append('\ud800');
+ aKeyBuffer.append(test);
+ y++;
+ } else
+ aKeyBuffer.append(test);
+ }
+ aKey = aKeyBuffer.toString();
+ for(int y=0; y<maxValueLen; y++) {
+ achar = generator.nextInt();
+ char test = (char)(achar);
+ if (Character.isHighSurrogate(test)) {
+ aKeyBuffer.append(test);
+ aKeyBuffer.append('\udc00');
+ y++;
+ } else if (Character.isLowSurrogate(test)) {
+ aKeyBuffer.append('\ud800');
+ aKeyBuffer.append(test);
+ y++;
+ } else {
+ aValueBuffer.append(test);
+ }
+ }
+ aValue = aValueBuffer.toString();
+
+ // Attempt to add to original
+ try {
+ originalProps.put(aKey, aValue);
+ }
+ catch (IllegalArgumentException e) {
+ System.err.println("disallowing...");
+ }
+ aKeyBuffer.setLength(0);
+ aValueBuffer.setLength(0);
+ }
+
+ // Store(OutputStream)/Load(InputStream)
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ originalProps.store(baos, "test properties");
+ loadedProps.load(getInputStream(baos.toByteArray()));
+ check(loadedProps, originalProps);
+
+ // Store(Writer)/Load(Reader)
+ baos = new ByteArrayOutputStream();
+ originalProps.store(new OutputStreamWriter(baos, "UTF-8"),
+ "test properties");
+ loadedProps.load(getReader(baos.toByteArray(), "UTF-8"));
+ check(loadedProps, originalProps);
+
+ report("SaveLoadBasher");
+ }
+
+
+ /* Note: this regression test only detects incorrect line
+ * separator on platform running the test
+ */
+ private static void SaveSeparator() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ Properties props = new Properties();
+ props.store(baos, "A test");
+
+ // Examine the result to verify that line.separator was used
+ String theSeparator = System.getProperty("line.separator");
+ String content = baos.toString();
+ if (!content.endsWith(theSeparator))
+ failCount++;
+
+ // store(Writer)
+ baos = new ByteArrayOutputStream();
+ props.store(new OutputStreamWriter(baos, "UTF-8"), "A test");
+ content = baos.toString();
+ if (!content.endsWith(theSeparator))
+ failCount++;
+
+ report("SaveSeparator");
+ }
+
+ // Ensure that the save method doesn't close its output stream
+ private static void SaveClose() throws Exception {
+ Properties p = new Properties();
+ p.put("Foo", "Bar");
+ class MyOS extends ByteArrayOutputStream {
+ boolean closed = false;
+ public void close() throws IOException {
+ this.closed = true;
+ }
+ }
+ MyOS myos = new MyOS();
+ p.store(myos, "Test");
+ if (myos.closed)
+ failCount++;
+
+ p.store(new OutputStreamWriter(myos, "UTF-8"), "Test");
+ if (myos.closed)
+ failCount++;
+
+ report ("SaveClose");
+ }
+
+ private static void UnicodeEscape() throws Exception {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ OutputStreamWriter osw = new OutputStreamWriter(baos);
+ osw.write("a=b\nb=\\u0\n");
+ osw.close();
+ Properties props = new Properties();
+ boolean failed = true;
+ try {
+ props.load(getInputStream(baos.toByteArray()));
+ } catch (IllegalArgumentException iae) {
+ failed = false;
+ }
+ if (failed)
+ failCount++;
+
+ failed = true;
+ props = new Properties();
+ try {
+ props.load(getReader(baos.toByteArray(), "UTF-8"));
+ } catch (IllegalArgumentException iae) {
+ failed = false;
+ }
+ if (failed)
+ failCount++;
+ report("UnicodeEscape");
+ }
+
+ private static void SaveComments() throws Exception {
+ String ls = System.getProperty("line.separator");
+ String[] input = new String[] {
+ "Comments with \u4e2d\u6587\u6c49\u5b57 included",
+ "Comments with \n Second comments line",
+ "Comments with \n# Second comments line",
+ "Comments with \n! Second comments line",
+ "Comments with last character is \n",
+ "Comments with last character is \r\n",
+ "Comments with last two characters are \n\n",
+ "Comments with last four characters are \r\n\r\n",
+ "Comments with \nkey4=value4",
+ "Comments with \n#key4=value4"};
+
+ String[] output = new String[] {
+ "#Comments with \\u4E2D\\u6587\\u6C49\\u5B57 included" + ls,
+ "#Comments with " + ls + "# Second comments line" + ls,
+ "#Comments with " + ls + "# Second comments line" + ls,
+ "#Comments with " + ls + "! Second comments line" + ls,
+ "#Comments with last character is " + ls+"#"+ls,
+ "#Comments with last character is " + ls+"#"+ls,
+ "#Comments with last two characters are " + ls+"#"+ls+"#"+ls,
+ "#Comments with last four characters are " + ls+"#"+ls+"#"+ls};
+
+ Properties props = new Properties();
+ ByteArrayOutputStream baos;
+ int i = 0;
+ for (i = 0; i < output.length; i++) {
+ baos = new ByteArrayOutputStream();
+ props.store(baos, input[i]);
+ String result = baos.toString("iso8859-1");
+ if (result.indexOf(output[i]) == -1) {
+ failCount++;
+ }
+ }
+ props.put("key1", "value1");
+ props.put("key2", "value2");
+ props.put("key3", "value3");
+ for (; i < input.length; i++) {
+ baos = new ByteArrayOutputStream();
+ props.store(baos, input[i]);
+ Properties propsNew = new Properties();
+ propsNew.load(getInputStream(baos.toByteArray()));
+ check(propsNew, props);
+
+ baos = new ByteArrayOutputStream();
+ props.store(new OutputStreamWriter(baos, "UTF-8"),
+ input[i]);
+ propsNew = new Properties();
+ propsNew.load(getReader(baos.toByteArray(), "UTF-8"));
+ check(propsNew, props);
+ }
+ report("SaveComments");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/Save.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4034428
+ * @summary Test for leading space in values output from properties
+ */
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/**
+ * This class tests to see if the properties object saves
+ * leading space in the value of a property as it should
+ * do according to the JLS
+ */
+public class Save {
+
+ public static void main(String argv[]) {
+ int testSucceeded=0;
+ FileOutputStream myOutput;
+
+ // create a properties object to save
+ Properties myProperties = new Properties();
+ String value = " spacesfirst";
+ myProperties.put("atest", value);
+
+ try {
+ // save the object and check output
+ myOutput = new FileOutputStream("testout");
+ myProperties.store(myOutput,"A test");
+ myOutput.close();
+
+ //load the properties set
+ FileInputStream myIn = new FileInputStream("testout");
+ Properties myNewProps = new Properties();
+ try {
+ myNewProps.load(myIn);
+ } finally {
+ myIn.close();
+ }
+
+ //check the results
+ String newValue = (String) myNewProps.get("atest");
+ if (!newValue.equals(value))
+ throw new RuntimeException(
+ "Properties does not save leading spaces in values correctly.");
+ } catch (IOException e) { //do nothing
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/SaveClose.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4095273
+ * @summary Ensure that the save method doesn't close its output stream
+ * @author Mark Reinhold
+ */
+
+import java.util.Properties;
+import java.io.OutputStream;
+import java.io.FilterOutputStream;
+import java.io.IOException;
+
+
+public class SaveClose {
+
+
+ static class O extends FilterOutputStream {
+
+ boolean closed = false;
+
+ O(OutputStream o) {
+ super(o);
+ }
+
+ public void close() throws IOException {
+ this.closed = true;
+ }
+
+ }
+
+
+ public static void main(String argv[]) throws Exception {
+ Properties p = new Properties();
+ p.put("Foo", "Bar");
+ O o = new O(System.err);
+ p.store(o, "Test");
+ if (o.closed)
+ throw new Exception("Properties.save closed its output stream");
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/SaveComments.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 5087448
+ * @summary Verify that property.save saves comments correctly
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+public class SaveComments {
+
+ public static void main(String[] argv) throws IOException {
+ String ls = System.getProperty("line.separator");
+ String[] input = new String[] {
+ "Comments with \u4e2d\u6587\u6c49\u5b57 included",
+ "Comments with \n Second comments line",
+ "Comments with \n# Second comments line",
+ "Comments with \n! Second comments line",
+ "Comments with last character is \n",
+ "Comments with last character is \r\n",
+ "Comments with last two characters are \n\n",
+ "Comments with last four characters are \r\n\r\n",
+ "Comments with \nkey4=value4",
+ "Comments with \n#key4=value4"};
+
+ String[] output = new String[] {
+ "#Comments with \\u4E2D\\u6587\\u6C49\\u5B57 included" + ls,
+ "#Comments with " + ls + "# Second comments line" + ls,
+ "#Comments with " + ls + "# Second comments line" + ls,
+ "#Comments with " + ls + "! Second comments line" + ls,
+ "#Comments with last character is " + ls+"#"+ls,
+ "#Comments with last character is " + ls+"#"+ls,
+ "#Comments with last two characters are " + ls+"#"+ls+"#"+ls,
+ "#Comments with last four characters are " + ls+"#"+ls+"#"+ls};
+
+ Properties props = new Properties();
+ boolean failed = false;
+ int i = 0;
+ for (i = 0; i < output.length; i++) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(200);
+ props.store(baos, input[i]);
+ String result = baos.toString("iso8859-1");
+ if (result.indexOf(output[i]) == -1) {
+ System.out.println("Wrong \"store()\" output:");
+ System.out.println(result);
+ failed = true;
+ }
+ }
+
+ props.put("key1", "value1");
+ props.put("key2", "value2");
+ props.put("key3", "value3");
+ for (; i < input.length; i++) {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(200);
+ props.store(baos, input[i]);
+ Properties propsNew = new Properties();
+ propsNew.load(new ByteArrayInputStream(baos.toByteArray()));
+ /*
+ Set<Map.Entry<Object, Object>> kvsetNew = propsNew.entrySet();
+ Set<Map.Entry<Object, Object>> kvset = props.entrySet();
+ if (!kvsetNew.containsAll(kvset) || !kvset.containsAll(kvsetNew)) {
+ */
+ if (!props.equals (propsNew)) {
+ System.out.println("Wrong output:");
+ System.out.println(baos.toString("iso8859-1"));
+ failed = true;
+ }
+ }
+ if (failed)
+ throw new RuntimeException("Incorrect Properties Comment Output.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/SaveEncoding.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+ /*
+ * @test
+ * @bug 4026910 4011163 4077980 4096786 4213537
+ * @summary Test for saving and loading encoded keys and values
+ */
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.Properties;
+
+/**
+ * This class tests to see if the properties object saves
+ * and loads keys and values properly
+ */
+public class SaveEncoding {
+
+ public static void main(String argv[]) {
+ int testSucceeded=0;
+ FileOutputStream myOutput;
+
+ // Create a properties object to save
+ Properties myProperties = new Properties();
+ myProperties.put("signal", "val\u0019");
+ myProperties.put("ABC 10", "value0");
+ myProperties.put("\uff10test", "value\u0020");
+ myProperties.put("key with spaces", "value with spaces");
+ myProperties.put(" special#=key ", "value3");
+
+ try {
+ // Destroy old test file if any
+ File myFile = new File("testout");
+ myFile.delete();
+
+ // Save the object and check output
+ myOutput = new FileOutputStream("testout");
+ myProperties.store(myOutput,"A test");
+ myOutput.close();
+
+ // Read properties file and verify \u0019
+ FileInputStream inFile = new FileInputStream("testout");
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(inFile));
+ String firstLine = "foo";
+ while (!firstLine.startsWith("signal"))
+ firstLine = in.readLine();
+ inFile.close();
+ if (firstLine.length() != 16)
+ throw new RuntimeException(
+ "Incorrect storage of values < 32.");
+
+ // Load the properties set
+ FileInputStream myIn = new FileInputStream("testout");
+ Properties myNewProps = new Properties();
+ try {
+ myNewProps.load(myIn);
+ } finally {
+ myIn.close();
+ }
+
+ // Check the results
+ if (!myNewProps.equals(myProperties))
+ throw new RuntimeException(
+ "Properties is not character encoding safe.");
+ } catch (IOException e) { // Do nothing
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/SaveLoadBasher.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4077980 4011163 4096786 4075955
+ * @summary Test properties save and load methods
+ * @key randomness
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+import java.util.Random;
+
+/**
+ * This class tests to see if a properties object
+ * can successfully save and load properties
+ * using character encoding
+ */
+public class SaveLoadBasher {
+
+ private static String keyValueSeparators = "=: \t\r\n\f#!\\";
+
+ public static void main(String[] args) throws Exception {
+
+ Properties originalProps = new Properties();
+ Properties loadedProps = new Properties();
+
+ // Generate a unicode key and value
+ Random generator = new Random();
+ int achar=0;
+ StringBuffer aKeyBuffer = new StringBuffer(120);
+ StringBuffer aValueBuffer = new StringBuffer(120);
+ String aKey;
+ String aValue;
+ for (int x=0; x<300; x++) {
+ for(int y=0; y<100; y++) {
+ achar = generator.nextInt();
+ char test;
+ if(achar < 99999) {
+ test = (char)(achar);
+ }
+ else {
+ int zz = achar % 10;
+ test = keyValueSeparators.charAt(zz);
+ }
+ aKeyBuffer.append(test);
+ }
+ aKey = aKeyBuffer.toString();
+ for(int y=0; y<100; y++) {
+ achar = generator.nextInt();
+ char test = (char)(achar);
+ aValueBuffer.append(test);
+ }
+ aValue = aValueBuffer.toString();
+
+ // Attempt to add to original
+ try {
+ originalProps.put(aKey, aValue);
+ }
+ catch (IllegalArgumentException e) {
+ System.err.println("disallowing...");
+ }
+ aKeyBuffer.setLength(0);
+ aValueBuffer.setLength(0);
+ }
+
+ // Destroy old test file if it exists
+ File oldTestFile = new File("props3");
+ oldTestFile.delete();
+
+ // Save original
+ System.out.println("Saving...");
+ OutputStream out = new FileOutputStream("props3");
+ originalProps.store(out, "test properties");
+ out.close();
+
+ // Load in the set
+ System.out.println("Loading...");
+ InputStream in = new FileInputStream("props3");
+ try {
+ loadedProps.load(in);
+ } finally {
+ in.close();
+ }
+
+ // Compare results
+ if (!originalProps.equals(loadedProps))
+ throw new RuntimeException("Properties load and save failed");
+
+ }
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/SaveSeparator.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4062657
+ * @summary Verify that property.save uses local lineseparator
+ */
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+/* Note: this regression test only detects incorrect line
+ * separator on platform running the test
+ */
+
+public class SaveSeparator {
+
+ public static void main(String[] argv) throws IOException {
+ // Save a property set
+ Properties myProps = new Properties();
+ ByteArrayOutputStream myOut = new ByteArrayOutputStream(40);
+ myProps.store(myOut, "A test");
+
+ // Examine the result to verify that line.separator was used
+ String theSeparator = System.getProperty("line.separator");
+ String content = myOut.toString();
+ if (!content.endsWith(theSeparator))
+ throw new RuntimeException("Incorrect Properties line separator.");
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/StoreDeadlock.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 6199320
+ * @summary Properties.store() causes deadlock when concurrently calling TimeZone apis
+ * @run main/timeout=20 StoreDeadlock
+ * @author Xueming Shen
+ */
+
+import java.io.IOException;
+import java.util.Properties;
+import java.util.TimeZone;
+
+public class StoreDeadlock {
+ public StoreDeadlock() {
+ Properties sysproperty = System.getProperties();
+ Thread1 t1 = new Thread1(sysproperty);
+ Thread2 t2 = new Thread2();
+ t1.start();
+ t2.start();
+ }
+ public static void main(String[] args) {
+ StoreDeadlock deadlock = new StoreDeadlock();
+ }
+ class Thread1 extends Thread {
+ Properties sp;
+ public Thread1(Properties p) {
+ sp = p;
+ }
+ public void run() {
+ try {
+ sp.store(System.out, null);
+ } catch (IOException e) {
+ System.out.println("IOException : " + e);
+ }
+ }
+ }
+ class Thread2 extends Thread {
+ public void run() {
+ System.out.println("tz=" + TimeZone.getTimeZone("PST"));
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/StringPropertyNames.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,173 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 6253413 8059361
+ * @summary Test for Properties.stringPropertyNames() if the system
+ * properties contain another list of properties as the defaults.
+ * @author Mandy Chung
+ *
+ * @run build StringPropertyNames
+ * @run main StringPropertyNames
+ */
+
+import java.util.Properties;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Set;
+
+public class StringPropertyNames {
+ private static int NUM_SHARE_PROPS = 2;
+ private static int NUM_PROPS1 = 3;
+ private static int NUM_PROPS2 = 5;
+ private static String KEY = "good.property.";
+ private static String VALUE = "good.value.";
+ public static void main(String[] argv) throws Exception {
+ Properties props1 = new Properties();
+ Properties props2 = new Properties(props1);
+
+ // add several new properties
+ for (int i = 0; i < NUM_PROPS1; i++) {
+ props1.put(KEY + "1." + i, VALUE + "1." + i);
+ }
+ for (int i = 0; i < NUM_PROPS2; i++) {
+ props2.put(KEY + "2." + i, VALUE + "2." + i);
+ }
+
+ // add the same properties in both props1 and props2
+ for (int i = 0; i < NUM_SHARE_PROPS; i++) {
+ props1.put(KEY + i, VALUE + "1." + i);
+ props2.put(KEY + i, VALUE + "2." + i);
+ }
+ checkProperties(props1,
+ NUM_PROPS1 + NUM_SHARE_PROPS, // size of props1
+ NUM_PROPS1 + NUM_SHARE_PROPS, // num of string keys
+ NUM_PROPS1 + NUM_SHARE_PROPS, // num of keys in propertyName(),
+ false);
+ checkProperties(props2,
+ NUM_PROPS2 + NUM_SHARE_PROPS, // size of props2
+ NUM_PROPS1 + NUM_PROPS2 + NUM_SHARE_PROPS, // num of string keys
+ NUM_PROPS1 + NUM_PROPS2 + NUM_SHARE_PROPS, // num of keys in propertyName(),
+ false);
+
+ // Add non-String value
+ props1.put(KEY + "9", new Integer(4));
+ checkProperties(props1,
+ NUM_PROPS1 + NUM_SHARE_PROPS + 1, // size of props1
+ NUM_PROPS1 + NUM_SHARE_PROPS, // num of string keys
+ NUM_PROPS1 + NUM_SHARE_PROPS + 1, // num of keys in propertyName(),
+ false);
+ checkProperties(props2,
+ NUM_PROPS2 + NUM_SHARE_PROPS, // size of props2
+ NUM_PROPS1 + NUM_PROPS2 + NUM_SHARE_PROPS, // num of string keys
+ NUM_PROPS1 + NUM_PROPS2 + NUM_SHARE_PROPS + 1, // num of keys in propertyName(),
+ false);
+ Object v = props1.remove(KEY + "9");
+ if (v == null) {
+ throw new RuntimeException("Test Failed: " +
+ "Key " + KEY + "9" + " not found");
+ }
+
+ // Add a non-String key
+ props1.put(new Integer(5), "good.value.5");
+ props2.put(new Object(), new Object());
+ checkProperties(props1,
+ NUM_PROPS1 + NUM_SHARE_PROPS + 1, // size of props1
+ NUM_PROPS1 + NUM_SHARE_PROPS, // num of string keys
+ NUM_PROPS1 + NUM_SHARE_PROPS + 1, // num of keys in propertyName(),
+ true);
+ checkProperties(props2,
+ NUM_PROPS2 + NUM_SHARE_PROPS + 1, // size of props2
+ NUM_PROPS1 + NUM_PROPS2 + NUM_SHARE_PROPS, // num of string keys
+ NUM_PROPS1 + NUM_PROPS2 + NUM_SHARE_PROPS + 2, // num of keys in propertyName(),
+ true);
+ System.out.println("Test passed.");
+ }
+
+ private static void checkProperties(Properties props,
+ int propSize,
+ int numStringKeys,
+ int enumerateSize,
+ boolean hasNonStringKeys) {
+ // check the size of the properties
+ if (props.size() != propSize) {
+ throw new RuntimeException("Test Failed: " +
+ "Expected number of properties = " +
+ propSize + " but found = " + props.size());
+ }
+
+ // check the number of properties whose key and value
+ // are both strings
+ Set<String> keys = props.stringPropertyNames();
+ if (keys.size() != numStringKeys) {
+ throw new RuntimeException("Test Failed: " +
+ "Expected number of String keys = " +
+ numStringKeys + " but found = " + keys.size());
+ }
+ boolean cceThrown = false;
+ try {
+ // check the number of properties whose key are strings
+ // but its value can be anything in the current impl
+ int count = 0;
+ Enumeration<?> e = props.propertyNames();
+ for (;e.hasMoreElements(); e.nextElement()) {
+ count++;
+ }
+ if (count != enumerateSize) {
+ throw new RuntimeException("Test Failed: " +
+ "Expected number of enumerated keys = " +
+ enumerateSize + " but found = " + count);
+ }
+ } catch (ClassCastException e) {
+ if (!hasNonStringKeys) {
+ RuntimeException re = new RuntimeException("Test Failed: " +
+ "ClassCastException is expected not to be thrown");
+ re.initCause(e);
+ throw re;
+ }
+ cceThrown = true;
+ }
+
+ if ((hasNonStringKeys && !cceThrown)) {
+ throw new RuntimeException("Test Failed: " +
+ "ClassCastException is expected to be thrown");
+ }
+
+ // make sure the set cannot be modified
+ try {
+ keys.add("xyzzy");
+ throw new RuntimeException("Test Failed: " +
+ "add() should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) { }
+
+ Iterator<String> it = keys.iterator();
+ if (it.hasNext()) {
+ try {
+ keys.remove(it.next());
+ throw new RuntimeException("Test Failed: " +
+ "remove() should have thrown UnsupportedOperationException");
+ } catch (UnsupportedOperationException ignore) { }
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/UnicodeEscape.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4792682
+ * @summary Test for correct exception with a short unicode escape
+*/
+
+import java.io.FileInputStream;
+import java.io.FileWriter;
+import java.io.InputStream;
+import java.util.Properties;
+
+public class UnicodeEscape {
+
+ public static void main(String argv[]) throws Exception {
+ save();
+ load();
+ }
+
+ private static void save() throws Exception {
+ FileWriter out = new FileWriter("a.properties");
+ out.write("a=b\nb=\\u0\n");
+ out.close();
+ }
+
+ private static void load() throws Exception {
+ Properties properties = new Properties();
+ InputStream in = new FileInputStream("a.properties");
+ try {
+ properties.load(in);
+ } catch (IllegalArgumentException iae) {
+ // Correct result
+ } finally {
+ in.close();
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/XMLSaveLoadBasher.java Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+/*
+ * @test
+ * @bug 4749531 5015114 5055738
+ * @summary Test properties XML save and load methods
+ * @key randomness
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Properties;
+import java.util.Random;
+
+/**
+ * This class tests to see if a properties object
+ * can successfully save and load properties in XML
+ */
+public class XMLSaveLoadBasher {
+
+ private static final int MAX_KEY_SIZE = 120;
+ private static final int MIN_KEY_SIZE = 1;
+ private static final int MAX_VALUE_SIZE = 120;
+ private static final int MIN_VALUE_SIZE = 0;
+
+ public static void main(String[] args) throws Exception {
+ testSaveLoad("UTF-8", "test save");
+ testSaveLoad("UTF-8", null);
+ testSaveLoad("ISO-8859-1", "test save");
+ testSaveLoad("KOI8-R", "test save");
+ }
+
+ private static void testSaveLoad(String encoding, String comment)
+ throws Exception
+ {
+ Properties originalProps = new Properties();
+ Properties loadedProps = new Properties();
+
+ // Generate a unicode key and value
+ Random generator = new Random();
+
+ for (int x=0; x<10; x++) {
+ String aKey;
+ String aValue;
+
+ // Assumes MAX_KEY_SIZE >> MIN_KEY_SIZE
+ int keyLen = generator.nextInt(MAX_KEY_SIZE - MIN_KEY_SIZE + 1) +
+ MIN_KEY_SIZE;
+ int valLen = generator.nextInt(
+ MAX_VALUE_SIZE - MIN_VALUE_SIZE + 1) + MIN_VALUE_SIZE;
+
+ StringBuffer aKeyBuffer = new StringBuffer(keyLen);
+ StringBuffer aValueBuffer = new StringBuffer(valLen);
+
+ for(int y=0; y<keyLen; y++) {
+ char test = (char)(generator.nextInt(6527) + 32);
+ aKeyBuffer.append(test);
+ }
+ aKey = aKeyBuffer.toString();
+
+ for(int y=0; y<valLen; y++) {
+ char test = (char)(generator.nextInt(6527) + 32);
+ aValueBuffer.append(test);
+ }
+ aValue = aValueBuffer.toString();
+
+ // Attempt to add to original
+ try {
+ originalProps.setProperty(aKey, aValue);
+ } catch (IllegalArgumentException e) {
+ System.err.println("disallowing...");
+ }
+ }
+
+ //originalProps.put("squid", "kraken");
+ //originalProps.put("demon", "furnace");
+
+ // Destroy old test file if it exists
+ File oldTestFile = new File("props3");
+ oldTestFile.delete();
+
+ // Save original
+ System.err.println("Saving...");
+ try (OutputStream out = new FileOutputStream("props3")) {
+ originalProps.storeToXML(out, comment, encoding);
+ }
+
+ // Load in the set
+ System.err.println("Loading...");
+ try (InputStream in = new FileInputStream("props3")) {
+ loadedProps.loadFromXML(in);
+ }
+
+ // Compare results
+ if (!originalProps.equals(loadedProps))
+ throw new RuntimeException("Properties load and save failed");
+
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/input.txt Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,10 @@
+# this input file is used for the LoadParsing.java test
+# comment ending with slash \
+key1 = value1
+key2 = abc\\\
+def\
+g\\
+ key3 = value3
+key4 = :value4
+ # comment with leading space
+#key = comment without line terminator
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/testData1 Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,35 @@
+# testcases
+key0=abcd\
+
+\
+key1=value1
+
+key2 \= abcde
+key3
+
+ #key4=abcde
+key5 ===Arial,ANSI_CHARSET
+key6= WingDings,SYMBOL_CHARSET \\\
+ abc
+key7 Symbol,SYMBOL_CHARSET \
+
+ keyabcdef
+
+key8notassign abcdef
+key9\ Term=ABCDE
+
+\\:key10=bar
+
+\\\\:key11=bar2
+
+\\\:key12=bar2
+
+key13dialog.3=
+key14_asdfa
+key15 \ abcdef
+key16\ b= \ abcdef
+key17=\
+#bar\
+baz
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/testData1.dos Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,35 @@
+# testcases
+key0=abcd\
+
+\
+key1=value1
+
+key2 \= abcde
+key3
+
+ #key4=abcde
+key5 ===Arial,ANSI_CHARSET
+key6= WingDings,SYMBOL_CHARSET \\\
+ abc
+key7 Symbol,SYMBOL_CHARSET \
+
+ keyabcdef
+
+key8notassign abcdef
+key9\ Term=ABCDE
+
+\\:key10=bar
+
+\\\\:key11=bar2
+
+\\\:key12=bar2
+
+key13dialog.3=
+key14_asdfa
+key15 \ abcdef
+key16\ b= \ abcdef
+key17=\
+#bar\
+baz
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/testData2 Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,4 @@
+#
+key1=-monotype-timesnewroman-regular-r---*-%d-*-*-p-*-iso8859-1serif.1a-monotype-timesnewroman-regular-r-normal--*-%d-*-*-p-*-iso8859-2serif.2a-b&h-LucidaBrightLat4-Normal-r-normal--*-%d-*-*-p-*-iso8859-4serif.3a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-5serif.4a-monotype-timesnewromangreek-regular-r-normal--*-%d-*-*-p-*-iso8859-7serif.5a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-9serif.6a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-15serif.7a-hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1serif.8a-sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0serif.9a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0serif.10a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0208.1983-0serif.11a-ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0serif.12a-hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3serif.13a-urw-itczapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificserif.14a-*-symbol-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificbserif.italic.0=-monotype-timesbnewbroman-regular-i---*-%d-*-*-p-*-iso8859-1bserif.italic.1=-monotype-timesbnewbroman-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-2
+
+key2=-b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/testData2.dos Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,4 @@
+#
+key1=-monotype-timesnewroman-regular-r---*-%d-*-*-p-*-iso8859-1serif.1a-monotype-timesnewroman-regular-r-normal--*-%d-*-*-p-*-iso8859-2serif.2a-b&h-LucidaBrightLat4-Normal-r-normal--*-%d-*-*-p-*-iso8859-4serif.3a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-5serif.4a-monotype-timesnewromangreek-regular-r-normal--*-%d-*-*-p-*-iso8859-7serif.5a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-9serif.6a-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-15serif.7a-hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1serif.8a-sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0serif.9a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0serif.10a-ricoh-hgminchol-medium-r-normal--*-%d-*-*-m-*-jisx0208.1983-0serif.11a-ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0serif.12a-hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3serif.13a-urw-itczapfdingbats-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificserif.14a-*-symbol-medium-r-normal--*-%d-*-*-p-*-sun-fontspecificbserif.italic.0=-monotype-timesbnewbroman-regular-i---*-%d-*-*-p-*-iso8859-1bserif.italic.1=-monotype-timesbnewbroman-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-2
+
+key2=-b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/util/Properties/testData3.dos Thu Jan 25 14:12:43 2018 +0800
@@ -0,0 +1,29 @@
+key1=\
+-monotype-times new roman-regular-r---*-%d-*-*-p-*-iso8859-1, \
+-monotype-times new roman-regular-r-normal--*-%d-*-*-p-*-iso8859-2, \
+-b&h-LucidaBrightLat4-Normal-r-normal--*-%d-*-*-p-*-iso8859-4, \
+-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-5, \
+-monotype-times new roman greek-regular-r-normal--*-%d-*-*-p-*-iso8859-7, \
+-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-9, \
+-monotype-times-regular-r-normal--*-%d-*-*-p-*-iso8859-15, \
+-hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1, \
+-sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0, \
+-ricoh-hg gothic b-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0, \
+-ricoh-hg gothic b-medium-r-normal-*-*-%d-*-*-m-*-jisx0208.1983-0, \
+-ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0, \
+-hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3
+
+key2=\
+-monotype-times new roman-regular-i---*-%d-*-*-p-*-iso8859-1, \
+-monotype-times new roman-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-2, \
+-b&h-LucidaBrightLat4-normal-i-normal-Italic-*-%d-*-*-p-*-iso8859-4, \
+-monotype-times-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-5, \
+-monotype-times new roman greek-regular-i-normal--*-%d-*-*-p-*-iso8859-7, \
+-monotype-times-regular-i-normal-italic-*-%d-*-*-p-*-iso8859-9, \
+-monotype-times-regular-i-normal--*-%d-*-*-p-*-iso8859-15, \
+-hanyi-ming-medium-r-normal--*-%d-*-*-m-*-big5-1, \
+-sun-song-medium-r-normal--*-%d-*-*-c-*-gb2312.1980-0, \
+-ricoh-hg gothic b-medium-r-normal--*-%d-*-*-m-*-jisx0201.1976-0, \
+-ricoh-hg gothic b-medium-r-normal-*-*-%d-*-*-m-*-jisx0208.1983-0, \
+-ricoh-heiseimin-w3-r-normal--*-%d-*-*-m-*-jisx0212.1990-0, \
+-hanyang-myeongjo-medium-r-normal--*-%d-*-*-m-*-ksc5601.1992-3