-
-
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
Move p.isNaN()
check inside try
block, post #4195
#4234
Conversation
if (p.isNaN() && ctxt.isEnabled(JsonNodeFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION)) { | ||
ctxt.handleWeirdNumberValue(handledType(), p.getDoubleValue(), | ||
"Cannot convert NaN into BigDecimal"); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not what I meant - p.isNan is unreliable and should not be used
this code code can be changed to remove this and put this in the catch
if (ctxt.isEnabled(JsonNodeFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION)) {
ctxt.handleWeirdNumberValue(handledType(), p.getDoubleValue(),
"Cannot convert NaN into BigDecimal");
return; //??
} else {
// fall through
}
If you give me a week or 2, I can get back to this and try to fix it myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pjfanning First thing would be to show how JsonNode
serialization would be compromised by this change. I do not know why this would be, based on my reading of code.
Is there a case where BigDecimal
value would now be incorrect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JooHyukKim As usual, it'd be necessary to have a failing case first before trying to solve a problem. Otherwise we have no verification of the fix, or check against regression.
And specifically, as far as I can see, p.isNaN()
never throws an exception; at least for JSON parser. So enclosing that in try-catch block would serve no purpose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmh. Ok, I think I know what is likely problematic... Double value overflow becoming +INFINITY
, in case of JsonNodeFeature.FAIL_ON_NAN_TO_BIG_DECIMAL_COERCION
being true.
So this would be actual bug for this handling.
But we do need jackson-core
test reproduction. Maybe:
does that, I'll have another look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. So one issue relevant here is this:
- JsonParser.isNaN() immediately after
parser.nextToken()
is accurate; only considering non-standard values (if allowed) - JsonParser.getNumberType() coerces all fp values into NumberType.DOUBLE and thus Double value overflow can induce NaNs
- JsonNodeDeserializer should not call
getNumberType()
for JSON -- but! It should call it for binary formats that DO provide this information
so it's combo of (2) and (3) that are problematic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we need a reproduction. I will close this, because I think I missed lots of information here thus need to catch up on what's missing.
My mistake 🙏🏼 Thank you for explaining things @pjfanning @cowtowncoder !
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a good change - it still uses the unreliable p.isNaN call
part of #4194
Motivation
This PR addresses possible
p.isNan()
failure by adding a fix proposed by https://github.com/FasterXML/jackson-databind/pull/4195/files#r1408831213Changes
p.isNaN()
check insidetry
block