# HG changeset patch # User ksrini # Date 1423782037 28800 # Node ID 7e09121db885c1f697e9c665491056e16cf2f0bb # Parent dc7d89f2e25c8d9e3200e0291ac692750981e899 8071836: javadoc fails as javadoc resource bundle not visible to com.sun.tools.javac.util.JavacMessages Reviewed-by: jjg, mchung diff -r dc7d89f2e25c -r 7e09121db885 langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/util/JavacMessages.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>> bundleCache; - private List bundleNames; + private List bundleHelpers; private Locale currentLocale; private List 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 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); + } } diff -r dc7d89f2e25c -r 7e09121db885 langtools/src/jdk.javadoc/share/classes/com/sun/tools/javadoc/Messager.java --- 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) {