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

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

Just to impede and frustrate you a bit (sorry ;)) -

+I doubt that the removal based on content equality alone always is correct, in 
particular if indirect objects are dereferenced first.+

In general it is allowed to have multiple entries in a PDF array that in turn 
have identical contents. If someone wants to remove specific entries from an 
array but retain some with identical contents (e.g. of entries with equal 
content remove all but the first), he might think of collecting all those 
entries to remove and then use {{removeAll(...)}}. With the introduction of the 
`equals` test here, that attempt suddenly removes _all_ of those _equal_ 
objects.

As long as dereferencing was not part of the game, you could have pointed out 
that using {{equals}} is part of the collection framework contract, so that 
person would have no one else to blame than his own wrong approach. But if you 
also dereference all indirect references, you suddenly are beyond that argument.

(If I misunderstood and only certain references are dereferenced while others 
are not, the result may not have this issue but probably similar ones...)
----
I have to admit I don't have a constructive alternative proposal yet...
----
A possible real-life use case: Imagine someone has added certain content pieces 
to a page contents array with {{APPEND}} and {{resetContext}}. Now he wants 
remove one of those additions again, first collecting one of the leading 
streams with only {{q}} as content and the trailing stream in question, then 
calling {{removeAll}} for that collection. If {{removeAll}} uses overall 
dereferencing and {{equals}}, *all* the leading streams with only {{q}} as 
content are removed, not merely the single, chosen one.

> 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: 2.0.19, 3.0.0 PDFBox
>
>
> 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