@@ -110,15 +110,22 @@ private COSBase addObjectToPool(COSObjectKey key, COSBase base)
110110 // Drop hollow objects.
111111 COSBase current = base instanceof COSObject ? ((COSObject ) base ).getObject () : base ;
112112 // to avoid to mixup indirect COSInteger objects holding the same value we have to check
113- // if the given key is the same than the key which is stored for the "same" base object wihtin the object pool
114- // the same is always true for COSFloat, COSBoolean and COSName and under certain circumstances for the remainig
115- // types as well
116- if (current == null //
117- || (key != null && objectPool .contains (key )) //
118- || (key == null && objectPool .contains (current )))
113+ // if the given key is the same than the key which is stored for the "same" base object within the object pool
114+ // the same is always true for COSFloat, COSBoolean and COSName and under certain circumstances for the
115+ // remaining types as well
116+ if (current == null || (key == null && objectPool .contains (current )))
119117 {
120118 return current ;
121119 }
120+ if (current != null && key != null && objectPool .contains (key ))
121+ {
122+ COSBase cosObject = objectPool .getObject (key );
123+ // check if the key belongs to the same object
124+ if (cosObject == current || cosObject == base )
125+ {
126+ return current ;
127+ }
128+ }
122129
123130 // Check whether the object can not be appended to an object stream.
124131 // An objectStream shall only contain generation 0 objects.
@@ -188,10 +195,10 @@ private List<COSBase> addStructure(List<COSBase> cosBaseList)
188195 private List <COSBase > addStructure (COSBase current )
189196 {
190197 COSBase base = current ;
191- if (current instanceof COSStream
192- || (current instanceof COSDictionary && ! current . isDirect ()) //
193- || ( current instanceof COSArray && ! current . isDirect ()) //
194- )
198+ if (! current . isDirect () && //
199+ (current instanceof COSStream //
200+ || current instanceof COSDictionary //
201+ || current instanceof COSArray ) )
195202 {
196203 base = addObjectToPool (base .getKey (), current );
197204 }
0 commit comments