-
-
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
TextNode.equals()
throws NullPointerException
when TextNode
constructed with null
#4378
Comments
Does this happen if you use the equals method? That is the more correct way to check for value equality |
@pjfanning Yeah, sorry, should have used equals as an example under Reproduction, I have updated it now
causes the NPE |
@Javed6234 see #4379 |
@pjfanning Lovely, thank you! |
@Javed6234 Looking at the code in TextNode and equivalent classes like DecimalNode, it is clear that they were never intended to support nulls. The constructors on these classes are public but not really intended to be used by non-Jackson code. They are public to faciliatate modular Jackson code. Why do you need to use @cowtowncoder in Jackson 3, we should probably throw an exception if some calls the TextNode/DecimalNode/BigIntegerNode constructors with null inputs. I would argue that it too late in Jackson 2 to make these constructors strict about null inputs. I have created #4379 and #4380 to work around immediate issues with equals and hashCode but users who somehow get null data into instances of these classes will likely get NullPointerExceptions elsewhere (eg DecimalMode doubleValue() method is not null safe and can't be made null safe). |
Ok, so, no, this is NOT a supported use case. We should, I think, fail with exception on But there is of course the pesky question of backwards compatibility, so I agree that it is probably too late to fix this in 2.x. I do agree that no NPE should be thrown for Thank you @Javed6234 for reporting this problem. |
TextNode.equals()
throws NullPointerException
when TextNode
constructed with null
My use case is that the string I'm passing into the TextNode can be null sometimes. |
For 2.x, then, Thank you once again for reporting this @Javed6234 ! |
Search before asking
Describe the bug
new TextNode(null) == new TextNode(null) returns false.
When debugging this issue, it actually causes an NPE in TextNode's
equals
method.Version Information
Version: 2.13.5
Java 11
Spring Boot: 2.5.15
Reproduction
Expected behavior
I would expect this to return true as both values are equal
Additional context
No response
The text was updated successfully, but these errors were encountered: