From 296b2f2d164e5570e65987e95735b0896c73ea7d Mon Sep 17 00:00:00 2001 From: Andrei Solntsev Date: Sat, 26 Oct 2024 10:13:45 +0300 Subject: [PATCH] fix NPE when rendering "demo/lists.html" in BrowserStartup --- .../xhtmlrenderer/swing/ImageResourceLoader.java | 3 +++ .../xhtmlrenderer/swing/ScalableXHTMLPanel.java | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ImageResourceLoader.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ImageResourceLoader.java index 243464b77..de7893476 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ImageResourceLoader.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ImageResourceLoader.java @@ -65,6 +65,9 @@ public static ImageResource loadImageResourceFromUri(final String uri) { try (InputStream is = IOUtil.getInputStream(uri)) { try { + if (is == null) { + return createImageResource(uri, null); + } BufferedImage img = ImageIO.read(is); if (img == null) { throw new IOException("ImageIO.read() returned null"); diff --git a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ScalableXHTMLPanel.java b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ScalableXHTMLPanel.java index 5154686c6..9033b154a 100644 --- a/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ScalableXHTMLPanel.java +++ b/flying-saucer-core/src/main/java/org/xhtmlrenderer/swing/ScalableXHTMLPanel.java @@ -167,14 +167,16 @@ protected void doRender(RenderingContext c, Layer root) { AffineTransform current = g.getTransform(); PaintingInfo pI = root.getMaster().getPaintingInfo(); - Dimension layoutSize = pI.getOuterMarginCorner(); + if (pI != null) { + Dimension layoutSize = pI.getOuterMarginCorner(); - calculateScaleAccordingToPolicy(layoutSize); + calculateScaleAccordingToPolicy(layoutSize); - if (lastLayoutSize == null) { - lastLayoutSize = layoutSize; - setPreferredSize(new Dimension((int) (lastLayoutSize.width * scale), (int) (lastLayoutSize.height * scale))); - revalidate(); + if (lastLayoutSize == null) { + lastLayoutSize = layoutSize; + setPreferredSize(new Dimension((int) (lastLayoutSize.width * scale), (int) (lastLayoutSize.height * scale))); + revalidate(); + } } g.transform(AffineTransform.getScaleInstance(scale, scale));