Pass missing argument for string formatting in ObjectMapper
#1771
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I just upgraded the jackson dependency in a project from version 2.8.8 to 2.9.1.
We have a line of code that catches a
JsonMappingException
. Since upgrading to version 2.9.1, this catch block is not reached anymore - instead we get ajava.util.MissingFormatArgumentException
.It seems that the following call is responsible, because the msg string contains three placeholders (
%s
)...jackson-databind/src/main/java/com/fasterxml/jackson/databind/ObjectMapper.java
Lines 3930 to 3934 in 85dafb9
...but in the implementation of
reportInputMismatch
only two arguments (actualName
andexpSimpleName
from above) are passed to the_format
method (which again callsString.format(...)
):jackson-databind/src/main/java/com/fasterxml/jackson/databind/DeserializationContext.java
Lines 1351 to 1356 in 85dafb9
This will always lead to the following exception:
java.util.MissingFormatArgumentException: Format specifier '%s'
and the expected
MismatchedInputException
from line 1355 above (which is theJsonMappingException
we try to catch in our project) will never be thrown.This pull request fixes this bug by passing the
rootType
as third argument for the string formatting, which is the same approach that is already implemented in theObjectReader
class:jackson-databind/src/main/java/com/fasterxml/jackson/databind/ObjectReader.java
Lines 1410 to 1414 in 85dafb9