changeset 35268:d5aa211825e1

7065236: To interpret case-insensitive string locale independently Reviewed-by: jbachorik Contributed-by: harsha.wardhana.b@oracle.com
author sspitsyn
date Mon, 04 Jan 2016 13:45:39 +0100
parents 8f0a2a0b4d96
children bbd3ec15b968
files jdk/src/java.management/share/classes/javax/management/loading/MLetParser.java jdk/src/java.management/share/classes/javax/management/modelmbean/DescriptorSupport.java jdk/src/java.management/share/classes/javax/management/remote/JMXServiceURL.java jdk/test/javax/management/loading/MletParserLocaleTest.java jdk/test/javax/management/loading/mlet4.html jdk/test/javax/management/modelmbean/DescriptorSupportXMLLocaleTest.java jdk/test/javax/management/remote/mandatory/connection/JMXServiceURLLocaleTest.java
diffstat 7 files changed, 253 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.management/share/classes/javax/management/loading/MLetParser.java	Mon Jan 04 10:07:08 2016 +0100
+++ b/jdk/src/java.management/share/classes/javax/management/loading/MLetParser.java	Mon Jan 04 13:45:39 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1999, 2015, 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
@@ -37,6 +37,7 @@
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 import java.util.logging.Level;
 
@@ -142,7 +143,7 @@
                 skipSpace(in);
                 val = buf.toString();
             }
-            atts.put(att.toLowerCase(), val);
+            atts.put(att.toLowerCase(Locale.ENGLISH), val);
             skipSpace(in);
         }
         return atts;
--- a/jdk/src/java.management/share/classes/javax/management/modelmbean/DescriptorSupport.java	Mon Jan 04 10:07:08 2016 +0100
+++ b/jdk/src/java.management/share/classes/javax/management/modelmbean/DescriptorSupport.java	Mon Jan 04 13:45:39 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2015, 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
@@ -45,6 +45,7 @@
 import java.security.AccessController;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
 import java.util.SortedMap;
@@ -283,7 +284,7 @@
             throw new RuntimeOperationsException(iae, msg);
         }
 
-        final String lowerInStr = inStr.toLowerCase();
+        final String lowerInStr = inStr.toLowerCase(Locale.ENGLISH);
         if (!lowerInStr.startsWith("<descriptor>")
             || !lowerInStr.endsWith("</descriptor>")) {
             throw new XMLParseException("No <descriptor>, </descriptor> pair");
--- a/jdk/src/java.management/share/classes/javax/management/remote/JMXServiceURL.java	Mon Jan 04 10:07:08 2016 +0100
+++ b/jdk/src/java.management/share/classes/javax/management/remote/JMXServiceURL.java	Mon Jan 04 13:45:39 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2002, 2015, 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
@@ -38,6 +38,7 @@
 import java.net.MalformedURLException;
 import java.net.UnknownHostException;
 import java.util.BitSet;
+import java.util.Locale;
 import java.util.StringTokenizer;
 
 /**
@@ -168,7 +169,7 @@
         final int protoStart = requiredPrefixLength;
         final int protoEnd = indexOf(serviceURL, ':', protoStart);
         this.protocol =
-            serviceURL.substring(protoStart, protoEnd).toLowerCase();
+            serviceURL.substring(protoStart, protoEnd).toLowerCase(Locale.ENGLISH);
 
         if (!serviceURL.regionMatches(protoEnd, "://", 0, 3)) {
             throw new MalformedURLException("Missing \"://\" after " +
@@ -328,7 +329,7 @@
                 throw new MalformedURLException("More than one [[...]]");
         }
 
-        this.protocol = protocol.toLowerCase();
+        this.protocol = protocol.toLowerCase(Locale.ENGLISH);
         this.host = host;
         this.port = port;
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/management/loading/MletParserLocaleTest.java	Mon Jan 04 13:45:39 2016 +0100
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2015, 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 7065236
+ * @summary Checking MletParser for Locale insensitive strings
+ * @author Harsha Wardhana B
+ * @modules java.management
+ * @run clean MletParserLocaleTest
+ * @run build MletParserLocaleTest
+ * @run main/othervm/timeout=5 MletParserLocaleTest mlet4.html
+ */
+
+import java.io.File;
+import java.util.Locale;
+import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import javax.management.ObjectName;
+import javax.management.loading.MLet;
+
+public class MletParserLocaleTest {
+
+    public static void main(String[] args) throws Exception {
+
+        boolean error = false;
+
+        // Instantiate the MBean server
+        //
+        System.out.println("Create the MBean server");
+        MBeanServer mbs = MBeanServerFactory.createMBeanServer();
+
+        // Get Default Locale
+        Locale loc = Locale.getDefault();
+
+        // Instantiate an MLet
+        //
+        System.out.println("Create the MLet");
+        MLet mlet = new MLet();
+
+        // Register the MLet MBean with the MBeanServer
+        //
+        System.out.println("Register the MLet MBean");
+        ObjectName mletObjectName = new ObjectName("Test:type=MLet");
+        mbs.registerMBean(mlet, mletObjectName);
+
+        // Call getMBeansFromURL
+        //
+        System.out.println("Call mlet.getMBeansFromURL(<url>)");
+        String testSrc = System.getProperty("test.src");
+        System.out.println("test.src = " + testSrc);
+        String urlCodebase;
+        if (testSrc.startsWith("/")) {
+            urlCodebase =
+                "file:" + testSrc.replace(File.separatorChar, '/') + "/";
+        } else {
+            urlCodebase =
+                "file:/" + testSrc.replace(File.separatorChar, '/') + "/";
+        }
+        String mletFile = urlCodebase + args[0];
+        System.out.println("MLet File = " + mletFile);
+        try {
+            // Change default Locale to Turkish
+            Locale.setDefault(new Locale("tr", "TR"));
+            mlet.getMBeansFromURL(mletFile);
+            System.out.println("Test Passes");
+        } catch (Exception e) {
+            error = true;
+            e.printStackTrace(System.out);
+        }finally {
+            Locale.setDefault(loc);
+        }
+
+        // Unregister the MLet MBean
+        //
+        System.out.println("Unregister the MLet MBean");
+        mbs.unregisterMBean(mletObjectName);
+
+        // Release MBean server
+        //
+        System.out.println("Release the MBean server");
+        MBeanServerFactory.releaseMBeanServer(mbs);
+
+        // End Test
+        //
+        System.out.println("Bye! Bye!");
+        if (error) System.exit(1);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/management/loading/mlet4.html	Mon Jan 04 13:45:39 2016 +0100
@@ -0,0 +1,2 @@
+<MLET CODE=HelloWorld ARCHIVE="helloworld.jar">
+</MLET>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/management/modelmbean/DescriptorSupportXMLLocaleTest.java	Mon Jan 04 13:45:39 2016 +0100
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2015, 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 7065236
+ * @summary Test for locale insensitive strings in DescriptorSupport class
+ * @author Harsha Wardhana B
+ * @modules java.management
+ * @run clean DescriptorSupportXMLLocaleTest
+ * @run build DescriptorSupportXMLLocaleTest
+ * @run main DescriptorSupportXMLLocaleTest
+ */
+import java.util.Locale;
+import javax.management.modelmbean.DescriptorSupport;
+
+public class DescriptorSupportXMLLocaleTest {
+
+    public static void main(String[] args) throws Exception {
+        boolean failed = false;
+        String xmlDesc = "<DESCRIPTOR>"
+                + "<FIELD name=\"field1\" value=\"dummy\">"
+                + "</FIELD>"
+                + "</DESCRIPTOR>";
+        Locale loc = Locale.getDefault();
+        try {
+            Locale.setDefault(new Locale("tr", "TR"));
+            new DescriptorSupport(xmlDesc);
+        } catch (Exception e) {
+            e.printStackTrace(System.out);
+            failed = true;
+        }finally{
+            Locale.setDefault(loc);
+        }
+
+        if (!failed) {
+            System.out.println("OK: all tests passed");
+        } else {
+            System.out.println("TEST FAILED");
+            throw new IllegalArgumentException("Test Failed");
+        }
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/javax/management/remote/mandatory/connection/JMXServiceURLLocaleTest.java	Mon Jan 04 13:45:39 2016 +0100
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015, 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 7065236
+ * @summary Test for locale insensitive strings in JMXServiceURL class
+ * @author Harsha Wardhana B
+ * @modules java.management
+ * @run clean JMXServiceURLLocaleTest
+ * @run build JMXServiceURLLocaleTest
+ * @run main JMXServiceURLLocaleTest
+*/
+
+import java.util.Locale;
+import javax.management.remote.JMXServiceURL;
+
+public class JMXServiceURLLocaleTest {
+    public static void main(String[] args) throws Exception {
+
+        boolean error = false;
+        Locale loc = Locale.getDefault();
+
+        try {
+            echo("Setting Turkish locale");
+            // Set locale other than Locale.ENGLISH
+            Locale.setDefault(new Locale("tr", "TR"));
+            new JMXServiceURL("service:jmx:RMI://");
+        } catch (Exception e) {
+            e.printStackTrace(System.out);
+            error = true;
+        } finally {
+            Locale.setDefault(loc);
+            echo("\n>>> Bye! Bye!");
+        }
+
+        if (error) {
+            echo("\nTest failed! ");
+            throw new IllegalArgumentException("Test failed");
+        } else {
+            echo("\nTest passed!\n");
+        }
+    }
+
+    private static void echo(String msg) {
+        System.out.println(msg);
+    }
+}