Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Fixed
-
3.0.1 PDFBox, 4.0.0
-
None
Description
The equals() method in CharStringCommand breaks the contract of Object.equals(). From the Object.equals() Javadoc:
The equals method implements an equivalence relation on non-null object references:
- It is reflexive: for any non-null reference value x, x.equals should return true.
- It is symmetric: for any non-null reference values x and y, x.equals should return true if and only if y.equals returns true.
- It is transitive: for any non-null reference values x, y, and z, if x.equals returns true and y.equals(z) returns true, then x.equals(z) should return true.
- It is consistent: for any non-null reference values x and y, multiple invocations of x.equals consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
- For any non-null reference value x, x.equals(null) should return false.
This is the current implementation:
@Override public boolean equals(Object object) { if (object instanceof CharStringCommand) { CharStringCommand that = (CharStringCommand) object; if (type1KeyWord != null && type1KeyWord == that.getType1KeyWord()) { return true; } if (type2KeyWord != null && type2KeyWord == that.getType2KeyWord()) { return true; } if (type1KeyWord == null && type2KeyWord == null) { return true; } } return false; }
If type1Keyword==null and type2Keyword!=null, true is returned without checking the values of that.getType1Keyword() and that.getType2Keyword().
Now imagine a has both fields set to null and b has not. Then a.equals(b)==true and b.equals(a)!=true.