Open juherr opened 3 months ago
Hi
I'd consider it as a false-positive and suggested change as incorrect.
Given following oversimplified schema:
{
"type": "object",
"javaType":"Example",
"properties": {
"myInteger": {
"type": "integer"
}
}
}
And following code
System.out.println(new Example().equals(new Example()));
Code accoring to ErrorProne would yield false
whereas one would expect it to be true
.
@unkish Example
is not a boxed primitive. The issue is about Integer
, Double
, Float
, ...
Object
equality must not change.
"type": "integer"
can be replaced with "existingJavaType": "Integer"
yielding same outcome whilst having same expectations
Yes and
System.out.println(new Integer(10).equals(new Integer(10)));
will return true as expected.
I still don't understand your point.
Schema above will generate code containing equals
method
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if ((other instanceof Example) == false) {
return false;
}
Example rhs = ((Example) other);
return ((this.myInteger == rhs.myInteger)||((this.myInteger!= null)&&this.myInteger.equals(rhs.myInteger)));
}
that contains "erroneous code" as reported by ErrorProne.
My point is that leaving out this.myInteger == rhs.myInteger
produces result that would differ from expected one.
@unkish Sorry for overlooking the double null case. Thank you for pointing it out.
By the way, I have made the necessary updates to the request, and it is now functioning as expected thanks to Objects.equals
.
When using ErrorProne on my project using jsonschema2pojo, it complains about the following errors:
According to ErrorProne, the generated code should be: