spring-projects / spring-projects/spring-hateoas
In some situations, `HateoasConfiguration#lookupMessageSource` wrongly returns null instead of `ReloadableResourceBundleMessageSource`
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 476
- PR merge metrics
- No merged PRs in 30d
Description
While trying to define rest-messages.properties files to generate HAL Forms property prompts, I discovered the following - IMHO buggy - behavior.
Steps to reproduce
Given a maven project, suppose you have the following src/main/resources/rest-message.properties
foo._prompt=Foo
The compilation copies rest-message.properties to target/classes/rest-message.properties.
Now you run a Spring Boot test. The context initialization triggers the following method:
Actual result
The method returns null because loadResourceBundleResources(I18N_BASE_NAME, true) returns an empty collection. Consequently, the prompts are never rendered in the test context.
Expected result
The method should return a non null AbstractMessageSource to allow prompt rendering in the test context.
Digging
In this case, if we ignore line 138 to 142 and build a ReloadableResourceBundleMessageSource anyway, the latter is able to resolve any message from the main file:
@Test
void test() {
ReloadableResourceBundleMessageSource messageSource =
new ReloadableResourceBundleMessageSource();
messageSource.setResourceLoader(context);
messageSource.setBasename("classpath:".concat("rest-messages"));
messageSource.setDefaultEncoding(StandardCharsets.UTF_8.toString());
String message = messageSource.getMessage("foo._prompt", new Object[0], Locale.getDefault());
assertThat(message).isEqualTo("Foo");
}
Therefore, I think the preliminary checks (138 to 142) are not "in sync" with the way ReloadableResourceBundleMessageSource actually works.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in HateoasConfiguration.java around lines 136–154 and reproduce the Spring Boot test with src/main/resources/rest-message.properties containing foo._prompt=Foo. Check why loadResourceBundleResources(I18N_BASE_NAME, true) is empty, then verify the resulting message source is non-null and resolves foo._prompt from the main resource.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 74/100