[
https://issues.apache.org/jira/browse/PDFBOX-4723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17190842#comment-17190842
]
Michael Klink commented on PDFBOX-4723:
---------------------------------------
{quote}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.
{quote}
I assume you here refer to your example where the hash code of an object
changes over time while the `equal` implementation would call that object
before and after the change equal due to a `==` check.
But that example is not a real example because you cannot apply `equal` to the
same object instance in different states at different points in time.
----
Essentially, the {{hashcode}} and {{equals}} methods of a class may be
implemented in a way to take members into account whose values can change over
time. This does not violate the basic Java contracts. It merely makes that
class an inappropriate candidate for map keys or set entries.
An actual contract violation was the situation in January when two dictionaries
were considered equal but hashed differently, see this comment, but the
situations you describe in your comment are not (unless I overlooked something
there).
----
Thus, one may be pro or contra the efforts to make arrays, dictionaries, and
streams implement `equals` and `hashcode` based on contents instead of entity
identity, but that objective is not itself breaking contracts.
(I'm a bit undecided here: It would be great to have purely content based
implementations thereof as that would allow reducing the size of PDFs
considerably, but I doubt that that is doable, in particular in case of
circular dependencies there are issues; and even if it was (is?) possible, the
time those implementations would require to run could be much too long...)
> 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]