Skip to content

Commit 3b3020d

Browse files
committed
Fix problem with NullPointerException in ListStyleApplierUtil class and add invalidLinearGradientTest
DEVSIX-4138
1 parent 058c90a commit 3b3020d

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

src/main/java/com/itextpdf/html2pdf/css/apply/util/ListStyleApplierUtil.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,16 @@ public static void applyListStyleImageProperty(Map<String, String> cssProps, Pro
141141
if (gradientBuilder != null) {
142142
Rectangle formBBox = new Rectangle(0, 0, em * LIST_ITEM_MARKER_SIZE_COEFFICIENT,
143143
em * LIST_ITEM_MARKER_SIZE_COEFFICIENT);
144-
imageXObject = new PdfFormXObject(formBBox);
144+
145145
PdfDocument pdfDocument = context.getPdfDocument();
146146
Color gradientColor = gradientBuilder.buildColor(formBBox, null, pdfDocument);
147-
new PdfCanvas((PdfFormXObject) imageXObject, pdfDocument)
148-
.setColor(gradientColor, true)
149-
.rectangle(formBBox)
150-
.fill();
147+
if (gradientColor != null) {
148+
imageXObject = new PdfFormXObject(formBBox);
149+
new PdfCanvas((PdfFormXObject) imageXObject, context.getPdfDocument())
150+
.setColor(gradientColor, true)
151+
.rectangle(formBBox)
152+
.fill();
153+
}
151154
}
152155
} catch (StyledXMLParserException e) {
153156
LOGGER.warn(MessageFormatUtil.format(

src/test/java/com/itextpdf/html2pdf/css/ListStyleImageLinearGradientTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ This file is part of the iText (R) project.
2323
package com.itextpdf.html2pdf.css;
2424

2525
import com.itextpdf.html2pdf.HtmlConverter;
26+
import com.itextpdf.html2pdf.LogMessageConstant;
2627
import com.itextpdf.kernel.utils.CompareTool;
2728
import com.itextpdf.test.ExtendedITextTest;
29+
import com.itextpdf.test.annotations.LogMessage;
30+
import com.itextpdf.test.annotations.LogMessages;
2831
import com.itextpdf.test.annotations.type.IntegrationTest;
2932

3033
import java.io.File;
@@ -55,6 +58,12 @@ public void linearGradientTypeTest() throws IOException, InterruptedException {
5558
runTest("linearGradientType");
5659
}
5760

61+
@Test
62+
@LogMessages(messages = {@LogMessage(messageTemplate = LogMessageConstant.INVALID_GRADIENT_DECLARATION, count = 3)})
63+
public void invalidLinearGradientTypeTest() throws IOException, InterruptedException {
64+
runTest("invalidLinearGradientType");
65+
}
66+
5867
@Test
5968
public void repeatingLinearGradientTypeTest() throws IOException, InterruptedException {
6069
runTest("repeatingLinearGradientType");
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<style>
5+
ol li {
6+
list-style-image: linear-gradient(,);
7+
}
8+
</style>
9+
</head>
10+
<body>
11+
<ol>
12+
<li>1</li>
13+
<li>2</li>
14+
<li>3</li>
15+
</ol>
16+
</body>
17+
</html>

0 commit comments

Comments
 (0)