-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add sanity checks for ObjectMapper.readXXX()
methods
#2348
Conversation
Seems reasonable to me. I think same would also apply to One other note: if PR is based on |
ObjectMapper.readXXX()
methods
Since I want to add this to |
Since I stumbled upon this myself, I wanted to point out: |
@Robin479 it would be useful to enumerate specific cases where Change from previously checked exceptions are unfortunate too of course, but seem like things that should have been caught earlier, assuming failure was due to invalid argument. So in that case I consider situation a bug (missing early detection of invalid argument) that is getting fixes. |
@cowtowncoder The example of @Robin479 just happend to us. We had some (acceptable) null references that were nicely wrapped in try-catch-blocks. Now those are useless and e.g. our tests broke. |
@hazeglide I would like you to think very carefully here as to whether your statement is helpful, in light of my previous comment. |
@cowtowncoder Have a look here: https://github.com/Robin479/jackson-nulltest/blob/master/src/test/java/com/fasterxml/jackson/databind/ObjectMapperNullabilityTest.java
|
@Robin479 Could you please file a new issue, including link to that project, and brief explanation of the issue. I do not usually re-open closed issues as that can make release notes difficult to follow. |
Today by trying to read something that I though being an
InputStream
:I get a quite broad end-of-input exception :
Actually,
readValue(InputStream src, Class<T> valueType)
as well as ObjectMapper reading methods do not perform sanity checks against the source parameters that they receive. In my case theInputStream
variable referenced a null.The error message is so misleading and too broad.
For example on SO, we can find other usecases that produces this error :
https://stackoverflow.com/questions/26925058/no-content-to-map-due-to-end-of-input-jackson-parser
Applying fail fast principle and throwing
IllegalArgumentException
orNullPointerException
with a meaningful message would make much more sense.So here is a pull request with this change. I didn't write whole unit tests for every case. But I can of course add it if the pull request makes sense for reviewers.
Regards,
David