[ https://issues.apache.org/jira/browse/PDFBOX-5724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17792669#comment-17792669 ]
ASF subversion and git services commented on PDFBOX-5724: --------------------------------------------------------- Commit 1914311 from Tilman Hausherr in branch 'pdfbox/branches/3.0' [ https://svn.apache.org/r1914311 ] PDFBOX-5724: fix equals() and hashCode(), by Axel Howind > 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 > Priority: Critical > Attachments: fix_CharStringCommand_equals()_and_hashCode().patch > > > 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} > This is the current implementation: > {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: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org