8072130: java/lang/instrument/BootClassPath/BootClassPathTest.sh fails on Mac OSX
authorbchristi
Mon, 24 Sep 2018 10:41:41 -0700
changeset 51854 3c6d285c8168
parent 51853 ec62d6cab037
child 51855 8bbb5cbac92c
child 51930 a642a0efc36d
8072130: java/lang/instrument/BootClassPath/BootClassPathTest.sh fails on Mac OSX Reviewed-by: sherman
src/java.base/unix/native/libjava/java_props_md.c
src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c
test/jdk/ProblemList.txt
test/jdk/java/lang/instrument/BootClassPath/BootClassPathTest.sh
test/jdk/java/lang/instrument/BootClassPath/Setup.java
--- a/src/java.base/unix/native/libjava/java_props_md.c	Mon Sep 24 19:26:48 2018 +0200
+++ b/src/java.base/unix/native/libjava/java_props_md.c	Mon Sep 24 10:41:41 2018 -0700
@@ -348,8 +348,14 @@
          * file to correctly read UTF-8 files using the default encoding (see
          * 8011194).
          */
-        if (strcmp(p,"US-ASCII") == 0 && getenv("LANG") == NULL &&
-            getenv("LC_ALL") == NULL && getenv("LC_CTYPE") == NULL) {
+        const char* env_lang = getenv("LANG");
+        const char* env_lc_all = getenv("LC_ALL");
+        const char* env_lc_ctype = getenv("LC_CTYPE");
+
+        if (strcmp(p,"US-ASCII") == 0 &&
+            (env_lang == NULL || strlen(env_lang) == 0) &&
+            (env_lc_all == NULL || strlen(env_lc_all) == 0) &&
+            (env_lc_ctype == NULL || strlen(env_lc_ctype) == 0)) {
             *std_encoding = "UTF-8";
         }
 #endif
--- a/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c	Mon Sep 24 19:26:48 2018 +0200
+++ b/src/java.instrument/unix/native/libinstrument/EncodingSupport_md.c	Mon Sep 24 10:41:41 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 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
@@ -63,7 +63,7 @@
 static void
 utfInitialize(void)
 {
-    char *codeset;
+    const char* codeset;
 
     /* Set the locale from the environment */
     (void)setlocale(LC_ALL, "");
@@ -77,6 +77,20 @@
 
     UTF_DEBUG(("Codeset = %s\n", codeset));
 
+#ifdef MACOSX
+    /* On Mac, if US-ASCII, but with no env hints, use UTF-8 */
+    const char* env_lang = getenv("LANG");
+    const char* env_lc_all = getenv("LC_ALL");
+    const char* env_lc_ctype = getenv("LC_CTYPE");
+
+    if (strcmp(codeset,"US-ASCII") == 0 &&
+        (env_lang == NULL || strlen(env_lang) == 0) &&
+        (env_lc_all == NULL || strlen(env_lc_all) == 0) &&
+        (env_lc_ctype == NULL || strlen(env_lc_ctype) == 0)) {
+        codeset = "UTF-8";
+    }
+#endif
+
     /* If we don't need this, skip it */
     if (strcmp(codeset, "UTF-8") == 0 || strcmp(codeset, "utf8") == 0 ) {
         UTF_DEBUG(("NO iconv() being used because it is not needed\n"));
@@ -146,6 +160,7 @@
         }
 
         /* Failed to do the conversion */
+        UTF_DEBUG(("iconv() failed to do the conversion\n"));
         return -1;
     }
 
--- a/test/jdk/ProblemList.txt	Mon Sep 24 19:26:48 2018 +0200
+++ b/test/jdk/ProblemList.txt	Mon Sep 24 10:41:41 2018 -0700
@@ -517,8 +517,6 @@
 java/lang/instrument/RedefineBigClass.sh                        8065756 generic-all
 java/lang/instrument/RetransformBigClass.sh                     8065756 generic-all
 
-java/lang/instrument/BootClassPath/BootClassPathTest.sh         8072130 macosx-all
-
 java/lang/management/MemoryMXBean/Pending.java                  8158837 generic-all
 java/lang/management/MemoryMXBean/PendingAllGC.sh               8158837 generic-all
 
--- a/test/jdk/java/lang/instrument/BootClassPath/BootClassPathTest.sh	Mon Sep 24 19:26:48 2018 +0200
+++ b/test/jdk/java/lang/instrument/BootClassPath/BootClassPathTest.sh	Mon Sep 24 10:41:41 2018 -0700
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2004, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2004, 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
@@ -90,6 +90,6 @@
 
 "$JAVAC" ${TESTJAVACOPTS} ${TESTTOOLVMOPTS} -d "${TESTCLASSES}" \
     "${TESTSRC}"/Cleanup.java
-"$JAVA" ${TESTTOOLVMOPTS} -classpath "${TESTCLASSES}" Cleanup "${BOOTDIR}"
+"$JAVA" ${TESTVMOPTS} -classpath "${TESTCLASSES}" Cleanup "${BOOTDIR}"
 
 exit $result
--- a/test/jdk/java/lang/instrument/BootClassPath/Setup.java	Mon Sep 24 19:26:48 2018 +0200
+++ b/test/jdk/java/lang/instrument/BootClassPath/Setup.java	Mon Sep 24 10:41:41 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 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
@@ -27,7 +27,7 @@
  * Used by BootClassPath.sh.
  *
  * Given a "work directory" this class creates a sub-directory with a
- * name that uses locale specific characters. It the creates a jar
+ * name that uses locale specific characters. It then creates a jar
  * manifest file in the work directory with a Boot-Class-Path that
  * encodes the created sub-directory. Finally it creates a file
  * "boot.dir" in the work directory with the name of the sub-directory.
@@ -51,6 +51,13 @@
 
         String bootDir = workDir + fileSeparator + bootClassPath;
 
+        /*
+         * Environment variable settings ("null" if unset)
+         */
+        System.out.println("Env vars:");
+        System.out.println("  LANG=" + System.getenv("LANG"));
+        System.out.println("  LC_ALL=" + System.getenv("LC_ALL"));
+        System.out.println("  LC_CTYPE=" + System.getenv("LC_CTYPE"));
 
         /*
          * Create sub-directory