changeset 55058:dfea18758dfa

8218960: CONFIG level logging statements printed in CLDRCalendarDataProviderImpl.java even when default log Level is INFO Reviewed-by: nishjain, rriggs
author naoto
date Thu, 21 Feb 2019 10:26:56 -0800
parents 8bc3d3eeaa53
children 4584d0331318
files src/java.base/share/classes/sun/util/cldr/CLDRCalendarDataProviderImpl.java src/java.base/share/classes/sun/util/locale/provider/CalendarDataUtility.java src/java.base/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java test/jdk/sun/util/locale/provider/CheckLoggingFromLocaleProvider.java
diffstat 4 files changed, 73 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/sun/util/cldr/CLDRCalendarDataProviderImpl.java	Thu Feb 21 16:57:47 2019 +0000
+++ b/src/java.base/share/classes/sun/util/cldr/CLDRCalendarDataProviderImpl.java	Thu Feb 21 10:26:56 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2019, 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
@@ -80,7 +80,8 @@
         String region = locale.getCountry();
 
         if (region.isEmpty()) {
-            return 0;
+            // Use "US" as default
+            region = "US";
         }
 
         Integer val = map.get(region);
--- a/src/java.base/share/classes/sun/util/locale/provider/CalendarDataUtility.java	Thu Feb 21 16:57:47 2019 +0000
+++ b/src/java.base/share/classes/sun/util/locale/provider/CalendarDataUtility.java	Thu Feb 21 10:26:56 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2019, 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
@@ -256,7 +256,9 @@
             default:
                 throw new InternalError("invalid requestID: " + requestID);
             }
-            return (value != 0) ? value : null;
+
+            assert value != 0;
+            return value;
         }
     }
 }
--- a/src/java.base/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java	Thu Feb 21 16:57:47 2019 +0000
+++ b/src/java.base/share/classes/sun/util/locale/provider/LocaleServiceProviderPool.java	Thu Feb 21 10:26:56 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2019, 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
@@ -283,8 +283,8 @@
                     return providersObj;
                 } else if (isObjectProvider) {
                     config(LocaleServiceProviderPool.class,
-                        "A locale sensitive service provider returned null for a localized objects,  which should not happen.  provider: "
-                            + lsp + " locale: " + locale);
+                        "A locale sensitive service object provider returned null, " +
+                        "which should not happen. Provider: " + lsp + " Locale: " + locale);
                 }
             }
         }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/sun/util/locale/provider/CheckLoggingFromLocaleProvider.java	Thu Feb 21 10:26:56 2019 -0800
@@ -0,0 +1,63 @@
+/*
+ * Copyright (c) 2019, 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 8218960
+ * @modules java.base/sun.util.locale.provider
+ * @modules java.logging
+ * @summary Check that no CONFIG messages are logged on instantiating
+ *     SimpleDateFormat with the language-only locale.
+ * @run main CheckLoggingFromLocaleProvider
+ */
+import java.text.*;
+import java.util.*;
+import java.util.logging.*;
+import sun.util.locale.provider.*;
+
+public class CheckLoggingFromLocaleProvider extends StreamHandler {
+
+    @Override
+    public boolean isLoggable(LogRecord lr) {
+        if (lr.getLevel() == Level.CONFIG &&
+            lr.getLoggerName().equals(
+                LocaleServiceProviderPool.class.getCanonicalName())) {
+            throw new RuntimeException("CONFIG message was logged in " +
+                lr.getLoggerName() + ". Message: " + lr.getMessage());
+        }
+        return false;
+    }
+
+    public CheckLoggingFromLocaleProvider() {
+        setLevel(Level.CONFIG);
+        Logger l = LogManager.getLogManager().getLogger("");
+        l.setLevel(Level.CONFIG);
+        l.addHandler(this);
+
+        new SimpleDateFormat("", Locale.ENGLISH);
+    }
+
+    public static void main(String[] args) {
+        new CheckLoggingFromLocaleProvider();
+    }
+}