You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ss...@apache.org on 2026/01/22 14:25:57 UTC

(xmlgraphics-fop) branch main updated: FOP-3291: Skip cache of images with no key

This is an automated email from the ASF dual-hosted git repository.

ssteiner pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/xmlgraphics-fop.git


The following commit(s) were added to refs/heads/main by this push:
     new 6d2fb2d92 FOP-3291: Skip cache of images with no key
6d2fb2d92 is described below

commit 6d2fb2d92faf78c81bca7394999191fda07a55ee
Author: Simon Steiner <ss...@apache.org>
AuthorDate: Thu Jan 22 14:24:14 2026 +0000

    FOP-3291: Skip cache of images with no key
---
 fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java     | 10 ++++++----
 .../java/org/apache/fop/render/pdf/ImageRenderedAdapter.java   |  7 +++++--
 .../src/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java  |  9 +++++++++
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java b/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java
index ee4db6ec1..d8cde2290 100644
--- a/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java
+++ b/fop-core/src/main/java/org/apache/fop/pdf/PDFDocument.java
@@ -830,16 +830,18 @@ public class PDFDocument {
      */
     public PDFXObject getXObject(String key) {
         Object xObj = xObjectsMapFast.get(key);
-        if (xObj != null) {
+        if (xObj != null || key == null) {
             return (PDFXObject) xObj;
         }
         return xObjectsMap.get(toHashCode(key));
     }
 
     private void putXObject(String key, PDFXObject pdfxObject) {
-        xObjectsMapFast.clear();
-        xObjectsMapFast.put(key, pdfxObject);
-        xObjectsMap.put(toHashCode(key), pdfxObject);
+        if (key != null) {
+            xObjectsMapFast.clear();
+            xObjectsMapFast.put(key, pdfxObject);
+            xObjectsMap.put(toHashCode(key), pdfxObject);
+        }
     }
 
     private String toHashCode(String key) {
diff --git a/fop-core/src/main/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java b/fop-core/src/main/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java
index c47f4e507..9ee2e88cf 100644
--- a/fop-core/src/main/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java
+++ b/fop-core/src/main/java/org/apache/fop/render/pdf/ImageRenderedAdapter.java
@@ -124,8 +124,11 @@ public class ImageRenderedAdapter extends AbstractImageAdapter {
             doc.getProfile().verifyTransparencyAllowed(image.getInfo().getOriginalURI());
             //TODO Implement code to combine image with background color if transparency is not
             //allowed (need BufferedImage support for that)
-
-            AlphaRasterImage alphaImage = new AlphaRasterImage("Mask:" + getKey(), ri);
+            String key = null;
+            if (getKey() != null) {
+                key = "Mask:" + getKey();
+            }
+            AlphaRasterImage alphaImage = new AlphaRasterImage(key, ri);
             this.softMask = doc.addImage(null, alphaImage).makeReference();
         }
     }
diff --git a/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java b/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java
index 5bfbac704..fa0df0321 100644
--- a/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java
+++ b/fop-core/src/test/java/org/apache/fop/pdf/PDFDocumentTestCase.java
@@ -22,8 +22,10 @@ package org.apache.fop.pdf;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 
+import org.junit.Assert;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
 
 /**
  * Test case for {@link PDFDocument}
@@ -58,4 +60,11 @@ public class PDFDocumentTestCase {
         PDFDocument.flushTextBuffer(textBuffer, out);
         assertEquals(fullString, out.toString());
     }
+
+    @Test
+    public void testImageWithNoKey() {
+        PDFImage image = mock(PDFImage.class);
+        PDFImageXObject xObject = new PDFDocument("").addImage(null, image);
+        Assert.assertNotNull(xObject);
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org