Axel Howind created PDFBOX-5724:
-----------------------------------
Summary: CharStringCommand.equals() does not conform to the
contract of Object.equals
Key: PDFBOX-5724
URL: https://issues.apache.org/jira/browse/PDFBOX-5724
Project: PDFBox
Issue Type: Bug
Affects Versions: 4.0.0
Reporter: Axel Howind
The equals() method in CharStringCommand breaks the contract of
Object.equals(). From the Object.equals() Javadoc:
{quote}The {{equals}} method implements an equivalence relation on non-null
object references:
* It is {_}reflexive{_}: for any non-null reference value {{{}x{}}},
{{x.equals(x)}} should return {{{}true{}}}.
* It is {_}symmetric{_}: for any non-null reference values {{x}} and
{{{}y{}}}, {{x.equals(y)}} should return {{true}} if and only if
{{y.equals(x)}} returns {{{}true{}}}.
* It is {_}transitive{_}: for any non-null reference values {{{}x{}}},
{{{}y{}}}, and {{{}z{}}}, if {{x.equals(y)}} 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(y)}} 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{}}}.
{quote}
{code:java}
@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;
}
{code}
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.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]