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

Michael Klink commented on PDFBOX-4723:
---------------------------------------

I think one should first go back to the drawing board and decide which behavior 
is desired and then check whether that desired behavior is attainable.

The original objective of this issue was to _add equals() and hashCode() to 
PDAnnotation and COS objects_ in order _to detect equality where an object is 
equal if the underlying COSDictionary has the same entries._

Is it really desired that dictionary objects are considered equal by `equals` 
and `hashcode` if they have the same entries? There are situations in which one 
probably does not want this, e.g. as already mentioned in previous comments 
insertion of new pages before or after a specific page can fail if page 
dictionaries are equal (which is quite possible if a document contains multiple 
"intentionally left blank" pages). 

Furthermore, usually one considers objects considered equal to be exchangeable 
but there are situations where replacing a dictionary by another one with the 
same entries can result in issues, e.g.
* different page dictionaries might have the same entries but need to remain in 
distinct indirect objects to have Adobe Reader accept them in the pages tree of 
the same PDF, 
* different annotation dictionaries might have the same entries but need to 
remain in distinct indirect objects if they are on different pages.

Thus, probably one should not override {{equals}} and {{hashcode}} but instead 
create separate utility methods which allow comparing PDF objects with 
different degrees of equivalence relations applied (e.g. after resolving 
references, comparing arrays/dictionaries by their immediate contents, 
comparing array/dictionaries recursively up to a given depth, ...). One can 
then check the existing code and consider case by case which equivalence is 
needed and use that method.

> 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