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

Pass missing argument for string formatting in ObjectMapper #1771

Closed
wants to merge 1 commit into from

Conversation

buehner
Copy link

@buehner buehner commented Sep 21, 2017

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 a java.util.MissingFormatArgumentException.

It seems that the following call is responsible, because the msg string contains three placeholders (%s)...

if (!expSimpleName.equals(actualName)) {
ctxt.reportInputMismatch(rootType,
"Root name '%s' does not match expected ('%s') for type %s",
actualName, expSimpleName);
}

...but in the implementation of reportInputMismatch only two arguments ( actualName and expSimpleName from above) are passed to the _format method (which again calls String.format(...)):

public <T> T reportInputMismatch(JavaType targetType,
String msg, Object... msgArgs) throws JsonMappingException
{
msg = _format(msg, msgArgs);
throw MismatchedInputException.from(getParser(), targetType, msg);
}

This will always lead to the following exception:

java.util.MissingFormatArgumentException: Format specifier '%s'

and the expected MismatchedInputException from line 1355 above (which is the JsonMappingException 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 the ObjectReader class:

if (!expSimpleName.equals(actualName)) {
ctxt.reportInputMismatch(rootType,
"Root name '%s' does not match expected ('%s') for type %s",
actualName, expSimpleName, rootType);
}

@cowtowncoder
Copy link
Member

Thank you for reporting this. Formatting bugs are pretty tricky; obviously higher test coverage would help here.

@cowtowncoder cowtowncoder added this to the 2.9.2 milestone Sep 21, 2017
@cowtowncoder cowtowncoder changed the title Pass missing argument for string formatting Pass missing argument for string formatting in ObjectMapper Sep 21, 2017
@cowtowncoder
Copy link
Member

Thank you for reporting the fix -- I integrated it manually for 2.9 branch as suggested.

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

Successfully merging this pull request may close these issues.

2 participants