Skip to content

Commit 4cf6d1a

Browse files
committed
Remove reflection in IndirectObjectFactory
There has been a public PdfObject::isReleaseForbidden for 8 years now, which does the same check. So we can safely remove reflection.
1 parent d1a28c3 commit 4cf6d1a

File tree

1 file changed

+3
-27
lines changed

1 file changed

+3
-27
lines changed

src/main/java/com/itextpdf/rups/model/IndirectObjectFactory.java

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,6 @@ public class IndirectObjectFactory {
9090
*/
9191
protected ArrayList<Boolean> isLoaded = new ArrayList<>();
9292

93-
private static final String METHOD_NAME = "checkState";
94-
private static final String FIELD_NAME = "FORBID_RELEASE";
95-
private static Method checkStateMethod;
96-
private static Field forbidReleaseField;
97-
98-
static {
99-
try {
100-
checkStateMethod = PdfObject.class.getDeclaredMethod(METHOD_NAME, short.class);
101-
checkStateMethod.setAccessible(true);
102-
forbidReleaseField = PdfObject.class.getDeclaredField(FIELD_NAME);
103-
forbidReleaseField.setAccessible(true);
104-
} catch (NoSuchFieldException | NoSuchMethodException | SecurityException ignored) {
105-
// left intentionally empty
106-
}
107-
}
108-
10993
/**
11094
* Creates a list that will contain all the indirect objects
11195
* in a PDF document.
@@ -186,11 +170,11 @@ private void store(PdfObject object) {
186170
}
187171
}
188172
isLoaded.add(object.isNull());
189-
if (canRelease(object)) {
173+
if (object.isReleaseForbidden()) {
174+
objects.add(object);
175+
} else {
190176
object.release();
191177
objects.add(PdfNull.PDF_NULL);
192-
} else {
193-
objects.add(object);
194178
}
195179
}
196180

@@ -271,14 +255,6 @@ public PdfObject loadObjectByReference(int ref) {
271255
return object;
272256
}
273257

274-
private boolean canRelease(PdfObject obj) {
275-
try {
276-
return !(Boolean) checkStateMethod.invoke(obj, forbidReleaseField.get(obj));
277-
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException any) {
278-
return true;
279-
}
280-
}
281-
282258
void addNewIndirectObject(PdfObject object) {
283259
object.makeIndirect(document);
284260
++n;

0 commit comments

Comments
 (0)