Skip to content

MessageSourceResourceBundle.containsKey throws NullPointerException [SPR-10136] #14769

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Dec 31, 2012 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Adrien Bonnin opened SPR-10136 and commented

When I try to use containsKey method on a MessageSourceResourceBundle instance I got the following NullPointerException :

Exception in thread "main" java.lang.NullPointerException
at java.util.ResourceBundle.handleKeySet(ResourceBundle.java:1787)
at java.util.ResourceBundle.containsKey(ResourceBundle.java:1741)
at net.toto.main(Main.java:36)

Here is a sample code :

Locale locale = Locale.getDefault();

ResourceBundleMessageSource bundle = new ResourceBundleMessageSource();
bundle.setBasename("bundles.Main");
System.out.println(bundle.getMessage("settings", new Object[0], locale));

MessageSourceResourceBundle bundle2 = new MessageSourceResourceBundle(bundle, locale);
System.out.println(bundle2.getString("settings"));

bundle2.containsKey("settings"); // NullPointerException


Affects: 3.1.2

Backported to: 3.1.4

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

This is fundamentally a JDK 1.6 API compatibility issue: containsKey (along with keySet and others) has been introduced in JDK 1.6, with Spring's MessageSourceResourceBundle adapter originally not having been designed to support those methods. We'll fix this for 3.2.1 and 3.1.4.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Fixed through overriding containsKey. Note that enumeration of keys doesn't work at all with a MessageSource, so ResourceBundle's keySet and getKeys methods throw an UnsupportedOperationException now.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Adrien Bonnin commented

Thank you :)

@spring-projects-issues spring-projects-issues added type: bug A general bug status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.2.1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants