Skip to content
New issue

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

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

Already on GitHub? # to your account

Clarify AbstractResourceBasedMessageSource.setCacheMillis vs java.util.ResourceBundle #24563

Closed
destan opened this issue Feb 21, 2020 · 1 comment
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: documentation A documentation task
Milestone

Comments

@destan
Copy link

destan commented Feb 21, 2020

Affects: 4.x, 5.x


In Javadoc of org.springframework.context.support.AbstractResourceBasedMessageSource#setCacheMillis
it says:

Default is "-1", indicating to cache forever (just like java.util.ResourceBundle).

However -1 in java.util.ResourceBundle is TTL_DONT_CACHE and its effect is not cache forever.

It should be TTL_NO_EXPIRATION_CONTROL = -2 to have the cache forever effect.

Hence I think implementation of org.springframework.context.support.ResourceBundleMessageSource#getResourceBundle is inconsistent with java.util.ResourceBundle.

it caches forever for any value less than 0. In order to be consistent with java.util.ResourceBundle it should be as follows

if (getCacheMillis() >= -1) {
	return doGetBundle(basename, locale);
}
else {
	// Cache forever...
}

and call doGetBundle for TTL_DONT_CACHE = -1 as well.

@jhoeller what do you think about it?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 21, 2020
@jhoeller
Copy link
Contributor

jhoeller commented Feb 24, 2020

That documentation comment actually refers to the default behavior of java.util.ResourceBundle, not to its time-to-live constants. That comment even predates the introduction of time-to-live support in java.util.ResourceBundle itself. From a ResourceBundleMessageSource and in particular from a AbstractResourceBasedMessageSource perspective, compatibility with those JDK constants is not a goal to begin with; the cacheMillis and cacheSeconds properties have their own rules there, following Spring conventions.

I'll revise the documentation accordingly, explicitly mentioning the default behavior reference.

@jhoeller jhoeller self-assigned this Feb 24, 2020
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: documentation A documentation task and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 24, 2020
@jhoeller jhoeller added this to the 5.2.4 milestone Feb 24, 2020
@jhoeller jhoeller changed the title Wrong javadoc in AbstractResourceBasedMessageSource and inconsistent implementation Clarify AbstractResourceBasedMessageSource.setCacheMillis vs java.util.ResourceBundle Feb 24, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.1.x labels Feb 24, 2020
# for free to join this conversation on GitHub. Already have an account? # 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: documentation A documentation task
Projects
None yet
Development

No branches or pull requests

3 participants