8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages
authorksrini
Thu, 12 Feb 2015 15:00:37 -0800
changeset 28892 7e09121db885
parent 28891 dc7d89f2e25c
child 28893 bf992bd35aad
8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages Reviewed-by: jjg, mchung
langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.java
langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Messager.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.java	Thu Feb 12 10:16:19 2015 +0530
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.java	Thu Feb 12 15:00:37 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 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
@@ -56,7 +56,7 @@
 
     private Map<Locale, SoftReference<List<ResourceBundle>>> bundleCache;
 
-    private List<String> bundleNames;
+    private List<ResourceBundleHelper> bundleHelpers;
 
     private Locale currentLocale;
     private List<ResourceBundle> currentBundles;
@@ -91,7 +91,7 @@
      * @param bundleName the name to identify the resource bundle of localized messages.
      */
     public JavacMessages(String bundleName, Locale locale) throws MissingResourceException {
-        bundleNames = List.nil();
+        bundleHelpers = List.nil();
         bundleCache = new HashMap<>();
         add(bundleName);
         setCurrentLocale(locale);
@@ -101,8 +101,13 @@
         this(defaultBundleName);
     }
 
+    @Override
     public void add(String bundleName) throws MissingResourceException {
-        bundleNames = bundleNames.prepend(bundleName);
+        add(locale -> ResourceBundle.getBundle(bundleName, locale));
+    }
+
+    public void add(ResourceBundleHelper ma) {
+        bundleHelpers = bundleHelpers.prepend(ma);
         if (!bundleCache.isEmpty())
             bundleCache.clear();
         currentBundles = null;
@@ -115,12 +120,13 @@
         List<ResourceBundle> bundleList = bundles == null ? null : bundles.get();
         if (bundleList == null) {
             bundleList = List.nil();
-            for (String bundleName : bundleNames) {
+            for (ResourceBundleHelper helper : bundleHelpers) {
                 try {
-                    ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
+                    ResourceBundle rb = helper.getResourceBundle(locale);
                     bundleList = bundleList.prepend(rb);
                 } catch (MissingResourceException e) {
-                    throw new InternalError("Cannot find javac resource bundle for locale " + locale);
+                    throw new InternalError("Cannot find requested resource bundle for locale " +
+                            locale, e);
                 }
             }
             bundleCache.put(locale, new SoftReference<>(bundleList));
@@ -134,6 +140,7 @@
         return getLocalizedString(currentLocale, key, args);
     }
 
+    @Override
     public String getLocalizedString(Locale l, String key, Object... args) {
         if (l == null)
             l = getCurrentLocale();
@@ -146,8 +153,7 @@
      * easy access to simple localized strings.
      */
 
-    private static final String defaultBundleName =
-        "com.sun.tools.javac.resources.compiler";
+    private static final String defaultBundleName = "com.sun.tools.javac.resources.compiler";
     private static ResourceBundle defaultBundle;
     private static JavacMessages defaultMessages;
 
@@ -198,4 +204,17 @@
        }
        return MessageFormat.format(msg, args);
     }
+
+    /**
+     * This provides a way for the JavacMessager to retrieve a
+     * ResourceBundle from another module such as jdk.javadoc.
+     */
+    public interface ResourceBundleHelper {
+        /**
+         * Gets the ResourceBundle.
+         * @param locale the requested bundle's locale
+         * @return ResourceBundle
+         */
+        ResourceBundle getResourceBundle(Locale locale);
+    }
 }
--- a/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Messager.java	Thu Feb 12 10:16:19 2015 +0530
+++ b/langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Messager.java	Thu Feb 12 15:00:37 2015 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 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
@@ -27,6 +27,7 @@
 
 import java.io.PrintWriter;
 import java.util.Locale;
+import java.util.ResourceBundle;
 
 import com.sun.javadoc.*;
 import com.sun.tools.javac.util.Context;
@@ -126,9 +127,11 @@
                        PrintWriter noticeWriter) {
         super(context, errWriter, warnWriter, noticeWriter);
         messages = JavacMessages.instance(context);
-        messages.add("com.sun.tools.javadoc.resources.javadoc");
+        messages.add(locale -> ResourceBundle.getBundle("com.sun.tools.javadoc.resources.javadoc",
+                                                         locale));
         javadocDiags = new JCDiagnostic.Factory(messages, "javadoc");
         this.programName = programName;
+
     }
 
     public void setLocale(Locale locale) {