[ 
https://issues.apache.org/jira/browse/PDFBOX-4723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17190597#comment-17190597
 ] 

Christian Appl commented on PDFBOX-4723:
----------------------------------------

[~mkl], I aggree to your premise *and* your conclusion. :)

For exactly this reason I critizise, that equals and hashcode have been 
altered. Prior to this change the object returned consistent results for those 
methods their external state was stable and such uses of said classes therefore 
worked and were used.

As explained in posts above: For example the PDFBox COSWriter is using 
HashTable and HashMap to find COSObjectKeys for COSBases and COSBases to find 
COSObjectKeys. (I can find more examples in the PDFBox library itself, where 
you are taking said risk.)

I agree to what you have said, as this usage is safe _no longer_. As the 
behaviour of equals and hashcode has changed, is now inconsistent and is not as 
reliable as before. Therefore the usage of said objects in Collections is *now* 
risky, following this change.
It has not been before, when the results of equals and hashcode did not depend 
on the internal state of the objects.

My conclusion is: Maybe equals and hashcode should not have been altered in the 
first place. So that such objects can be used in such a form and classes like 
COSWriter would not have to be adapted accordingly.
As already stated: I do not use COSBase objects in that way anymore, as the 
equals implementation causes incompatibilities with Java.utils classes (Which 
was my initial claim) and such objects can not be trusted any longer to behave 
in a stable and consistent manner. (As you stated in your last comment.)

Further: As pointed out above and even if your are completly right and if I am 
completly wrong... The behaviour of equals and hashcode still does violate the 
contract and therefore - even when you still want to alter said methods - this 
specific example of the implementation still is erroneous.

> Add equals() and hashCode() to PDAnnotation and COS objects
> -----------------------------------------------------------
>
>                 Key: PDFBOX-4723
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-4723
>             Project: PDFBox
>          Issue Type: Sub-task
>          Components: PDModel
>    Affects Versions: 2.0.18
>            Reporter: Maruan Sahyoun
>            Assignee: Maruan Sahyoun
>            Priority: Major
>             Fix For: 3.0.0 PDFBox
>
>         Attachments: bird_burst.heic.pdf, image-2020-09-02-13-52-21-370.png, 
> image-2020-09-02-13-53-02-622.png, image-2020-09-02-13-54-31-630.png, 
> screenshot-1.png
>
>
> In order to proper support removeAll/retainAll for COSArrayList we need to 
> detect if entries are in fact duplicates of others. This currently fails as 
> even though one might add the same instance of an annotation object multiple 
> times to setAnnotations getting the annotations will have individual 
> instances. See the discussion at PDFBOX-4669.
> In order to proper support removal we need to be able to detect equality 
> where an object is equal if the underlying COSDictionary has the same entries.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to