[
https://issues.apache.org/jira/browse/PDFBOX-4723?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17189300#comment-17189300
]
Christian Appl commented on PDFBOX-4723:
----------------------------------------
To reiterate:
HashTable is using the following method to find a table entry:
{color:#0033b3}public synchronized {color}{color:#007e8a}V
{color}{color:#00627a}get{color}({color:#000000}Object {color}key) {
{color:#000000}Entry{color}<?,?> {color:#000000}tab{color}[] =
{color:#871094}table{color};
{color:#0033b3}int {color}{color:#000000}hash {color}= key.hashCode();
{color:#0033b3}int {color}{color:#000000}index {color}= ({color:#000000}hash
{color}& {color:#1750eb}0x7FFFFFFF{color}) %
{color:#000000}tab{color}.{color:#871094}length{color};
{color:#0033b3}for {color}({color:#000000}Entry{color}<?,?> e =
{color:#000000}tab{color}[{color:#000000}index{color}] ; e !=
{color:#0033b3}null {color}; e = e.{color:#871094}next{color}) {
{color:#0033b3}if {color}((e.{color:#871094}hash {color}==
{color:#000000}hash{color}) && *e.{color:#871094}key{color}.equals(key)*) {
{color:#0033b3}return
{color}({color:#007e8a}V{color})e.{color:#871094}value{color};
}
}
{color:#0033b3}return null{color};
}
This method and similar methods are directly influenced whenever you are
overriding equals and/or hashcode.
HashTable *will* treat objects as already contained, if their equals method
returns true.
It *will* further treat objects as not contained, if their equals method
returns false.
Whenever you override equals (as intended here) you are accepting, that some
entries might not be added, because a similar entry (that has an equal content)
might already exist in the table.
(Which might be the behaviour you intend to implement - I can't know that for
certain.)
And also it might result in a duplication of entries, that can no longer be
considered as already contained, as their content has changed.
> 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]