@@ -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