Skip to content
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

MessageResolver throws a NoSuchMessageException if a message cannot be resolved (and does not return null as mentioned in the javadoc) #1380

Open
ingogriebsch opened this issue Oct 22, 2020 · 2 comments
Labels

Comments

@ingogriebsch
Copy link

If one calls resolve on the MessageResolver and the message cannot be resolved, a NoSuchMessageException is thrown.

The javadoc of the resolve method explains that null is returned if no message was found. This is only true if the no resource bundles were found and the DefaultOnlyMessageResolver is configured through the HateoasConfiguration.

@odrotbohm
Copy link
Member

Are you fine with the current behavior and just want us to update the Javadoc? Or are you rather suggesting we should change the behavior?

@odrotbohm odrotbohm added in: core Core parts of the project in: documentation Reference documentation process: waiting for feedback type: bug labels Oct 27, 2020
@ingogriebsch
Copy link
Author

I'm personally a bit unsure about how to handle this issue. If you not have asked I would have said, that the behavior needs to be changed for sure.

I just created a test project to check why the exception is not thrown if somone is for example using HAL as a mediatype. And I realized that the reason is, that class HalLinkRelation (which is a MessageSourceResolvable) returns an empty string if something calls getDefaultMessage on it.

My implementation of MessageSourceResolvable is simply returning null (because it does not know about a good/matching default message). Therefore the underlying MessageSource can neither resovle a message nor a default message and therefore throws an exception.

I'm currently solving the problem the way, that I try/catch the call to the given MessageResolver. I could also return an empty String on all my MessageSourceResolvable implementations (but this feels like it is not the correct way to do).

tldr: I'm still unsure. Currently I think 'Why do I need to handle that case? Especially because there is a facility available in Spring HATEOAS that deals with the message-source/resource-bundle.'. But I can live/deal with weither option you have in mind as a solution! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants