Skip to content

Commit

Permalink
Fix NPE when bundle is not started
Browse files Browse the repository at this point in the history
Currently the code checks for 'localizationTracker == null' to see if
bundle is started, but that field is actually never null (as it is a
final field always initilized with a value) instead the Activator
instance itself can be null.

This changes the method to replace the usless check with one that checks
if the activator instance is null and additionally make the method
static.
  • Loading branch information
laeubi committed Jul 30, 2023
1 parent 1c54099 commit 3bd3dbd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@ public String getBundleId(Object object) {
* in the given locale. Does not return null.
* @throws MissingResourceException If the corresponding resource could not be found
*/
public ResourceBundle getLocalization(Bundle bundle, String locale) throws MissingResourceException {
if (localizationTracker == null) {
throw new MissingResourceException(CommonMessages.activator_resourceBundleNotStarted, bundle.getSymbolicName(), ""); //$NON-NLS-1$
public static ResourceBundle getLocalization(Bundle bundle, String locale) throws MissingResourceException {
Activator activator = Activator.getDefault();
if (activator == null) {
throw new MissingResourceException(CommonMessages.activator_resourceBundleNotStarted,
bundle.getSymbolicName(), ""); //$NON-NLS-1$
}
BundleLocalization location = localizationTracker.current().orElse(null);
BundleLocalization location = activator.localizationTracker.current().orElse(null);
ResourceBundle result = null;
if (location != null)
result = location.getLocalization(bundle, locale);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private static ResourceBundle getResourceBundle(Bundle bundle, String language)
Locale locale = (language == null) ? Locale.getDefault() : new Locale(language);
return ResourceBundle.getBundle("plugin", locale, createTempClassloader(bundle)); //$NON-NLS-1$
}
return Activator.getDefault().getLocalization(bundle, language);
return Activator.getLocalization(bundle, language);
}

public static String[] getResourceString(Bundle bundle, String[] nonTranslated, String locale) {
Expand Down

0 comments on commit 3bd3dbd

Please sign in to comment.