danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!

Home Page:https://danfickle.github.io/pdf-templates/index.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NPE in BlockBox.calcMinMaxWidthInlineChildren() (_children is null)

rototor opened this issue · comments

I get this NPE in production after upgrading to RC18 from RC17. As I am going on holiday next week I don't have time to investigate at the moment whats exactly causing the problem here. When repeating the report generation it then often just works ... I've rolled back to RC17 in the mean time.

This might be some multithread fun/race, but thats just a guess.

 java.lang.NullPointerException
      at com.openhtmltopdf.render.BlockBox.calcMinMaxWidthInlineChildren(BlockBox.java:1726)
      at com.openhtmltopdf.render.BlockBox.calcMinMaxWidth(BlockBox.java:1629)
      at com.openhtmltopdf.render.BlockBox.calcShrinkToFitWidth(BlockBox.java:1506)
      at com.openhtmltopdf.render.BlockBox.calcShrinkToFitWidthIfNeeded(BlockBox.java:981)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:874)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.layout.InlineBoxing.layoutInlineBlockContent(InlineBoxing.java:423)
      at com.openhtmltopdf.layout.InlineBoxing.layoutContent(InlineBoxing.java:314)
      at com.openhtmltopdf.render.BlockBox.layoutInlineChildren(BlockBox.java:1073)
      at com.openhtmltopdf.render.AnonymousBlockBox.layout(AnonymousBlockBox.java:48)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
      at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
      at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
      at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
      at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.newtable.TableRowBox.layoutCell(TableRowBox.java:453)
      at com.openhtmltopdf.newtable.TableRowBox.layoutChildren(TableRowBox.java:206)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.newtable.TableRowBox.layout(TableRowBox.java:89)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
      at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
      at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057)
      at com.openhtmltopdf.newtable.TableSectionBox.layoutChildren(TableSectionBox.java:139)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.newtable.TableSectionBox.layout(TableSectionBox.java:275)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
      at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
      at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057)
      at com.openhtmltopdf.newtable.TableBox.layoutChildren(TableBox.java:311)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.newtable.TableBox.layoutTable(TableBox.java:277)
      at com.openhtmltopdf.newtable.TableBox.layout(TableBox.java:237)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
      at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
      at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
      at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
      at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321)
      at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299)
      at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90)
      at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911)
      at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827)
      at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.layout(PdfBoxRenderer.java:332)

I also get the same NPE after upgrading to RC18 from RC17. In my case, I could trace this specific issue back to a wrong URL for a remote image in the HTML code, which does not exist and returns a 404 HTTP error page.
I tried the exact HTML input with the RC17 version and I did not throw an exception but just did not display the wrong image.

This HTML code can lead to the exception:

<p><img alt="" src="http://example.com/non-existent-image.jpg" />
</p>

Here is the same exception I get:

java.lang.NullPointerException: null
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidthInlineChildren(BlockBox.java:1726) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidth(BlockBox.java:1629) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidthInlineChildren(BlockBox.java:1744) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidth(BlockBox.java:1629) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidthBlockChildren(BlockBox.java:1698) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidth(BlockBox.java:1626) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.recalcColumn(TableBox.java:1247) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.fullRecalc(TableBox.java:1221) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.calcMinMaxWidth(TableBox.java:1516) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox.calcMinMaxWidth(TableBox.java:158) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidthBlockChildren(BlockBox.java:1698) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidth(BlockBox.java:1626) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.recalcColumn(TableBox.java:1247) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.fullRecalc(TableBox.java:1221) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.calcMinMaxWidth(TableBox.java:1516) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox.calcMinMaxWidth(TableBox.java:158) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidthBlockChildren(BlockBox.java:1698) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.calcMinMaxWidth(BlockBox.java:1626) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.recalcColumn(TableBox.java:1247) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.fullRecalc(TableBox.java:1221) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox$AutoTableLayout.calcMinMaxWidth(TableBox.java:1516) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox.calcMinMaxWidth(TableBox.java:158) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.newtable.TableBox.layout(TableBox.java:221) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild0(BlockBoxing.java:321) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutBlockChild(BlockBoxing.java:299) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.layout.BlockBoxing.layoutContent(BlockBoxing.java:90) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.layoutChildren(BlockBox.java:1057) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:911) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.render.BlockBox.layout(BlockBox.java:827) ~[openhtmltopdf-core-0.0.1-RC18.jar:na]
	at com.openhtmltopdf.pdfboxout.PdfBoxRenderer.layout(PdfBoxRenderer.java:332) ~[openhtmltopdf-pdfbox-0.0.1-RC18.jar:na]

Thanks @svenfrauen for finding the cause. I think this is a side effect of fixing #328. I didn’t think to test with a broken image link. I will fix, add test and do another release.

Have a good holiday @rototor!

All fixed. RC19 planned for tomorrow. Thanks again.

RC19 just released with this fix.