diff --git a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/InlineText.java b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/InlineText.java index ce3e9ea72..8d66a9469 100644 --- a/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/InlineText.java +++ b/openhtmltopdf-core/src/main/java/com/openhtmltopdf/render/InlineText.java @@ -312,6 +312,10 @@ public float calcTotalAdjustment(JustificationInfo info) { // letter spacing is already explicitly set. return 0f; } + + if (_counts == null) { + return 0f; + } return (_counts.getSpaceCount() * info.getSpaceAdjust()) + (_counts.getNonSpaceCount() * info.getNonSpaceAdjust()); diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-420-justify-text-null-pointer-exception.pdf b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-420-justify-text-null-pointer-exception.pdf new file mode 100644 index 000000000..29219dce3 Binary files /dev/null and b/openhtmltopdf-examples/src/main/resources/visualtest/expected/issue-420-justify-text-null-pointer-exception.pdf differ diff --git a/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-420-justify-text-null-pointer-exception.html b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-420-justify-text-null-pointer-exception.html new file mode 100644 index 000000000..35f1cd635 --- /dev/null +++ b/openhtmltopdf-examples/src/main/resources/visualtest/html/issue-420-justify-text-null-pointer-exception.html @@ -0,0 +1 @@ +

a
b

\ No newline at end of file diff --git a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java index 6c2ec2739..b5bdd6af5 100644 --- a/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java +++ b/openhtmltopdf-examples/src/test/java/com/openhtmltopdf/visualregressiontests/VisualRegressionTest.java @@ -923,7 +923,12 @@ public void testIssue399TableHeaderFooterWithNoRows() throws IOException { assertTrue(vt.runTest("issue-399-table-header-with-no-rows")); } - + + @Test + public void testIssue420JustifyTextNullPointerException() throws IOException { + assertTrue(vt.runTest("issue-420-justify-text-null-pointer-exception")); + } + // TODO: // + Elements that appear just on generated overflow pages. // + content property (page counters, etc)