Skip to content

Commit a62168e

Browse files
committed
Improve PdfArray#contains() and PdfAray#remove().
DEVSIX-728
1 parent 2ec9154 commit a62168e

File tree

2 files changed

+48
-403
lines changed

2 files changed

+48
-403
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfArray.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,18 @@ public boolean isEmpty() {
186186
}
187187

188188
public boolean contains(PdfObject o) {
189-
return list.contains(o);
189+
if (list.contains(o))
190+
return true;
191+
if (o != null) {
192+
if (o.getIndirectReference() != null
193+
&& list.contains(o.getIndirectReference())) {
194+
return true;
195+
} else if (o.isIndirectReference()
196+
&& list.contains(((PdfIndirectReference) o).getRefersTo())) {
197+
return true;
198+
}
199+
}
200+
return false;
190201
}
191202

192203
/**
@@ -217,7 +228,14 @@ public void add(PdfObject pdfObject) {
217228
}
218229

219230
public void remove(PdfObject o) {
220-
list.remove(o);
231+
if (list.remove(o))
232+
return;
233+
if (o != null) {
234+
if (o.getIndirectReference() != null && list.remove(o.getIndirectReference()))
235+
return;
236+
if (o.isIndirectReference())
237+
list.remove(((PdfIndirectReference) o).getRefersTo());
238+
}
221239
}
222240

223241
/**

0 commit comments

Comments
 (0)