Skip to content

Commit d326b01

Browse files
committed
Call equals() for string literal, passing the variable as an argument, to avoid NPE
1 parent 50a5816 commit d326b01

File tree

6 files changed

+10
-50
lines changed

6 files changed

+10
-50
lines changed

findbugs-filter.xml

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -22,46 +22,6 @@
2222
</Or>
2323
<Bug pattern="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS"/>
2424
</Match>
25-
<Match>
26-
<Class name="com.itextpdf.html2pdf.attach.impl.DefaultHtmlProcessor"/>
27-
<Method name="visit" params="com.itextpdf.styledxmlparser.node.INode"/>
28-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
29-
</Match>
30-
<Match>
31-
<Class name="com.itextpdf.html2pdf.attach.impl.layout.HeightDimensionContainer"/>
32-
<Method
33-
name="&lt;init&gt;"
34-
params="com.itextpdf.styledxmlparser.css.CssContextNode, float, float, com.itextpdf.layout.renderer.IRenderer, float"
35-
/>
36-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
37-
</Match>
38-
<Match>
39-
<Class name="com.itextpdf.html2pdf.attach.impl.layout.WidthDimensionContainer"/>
40-
<Method
41-
name="&lt;init&gt;"
42-
params="com.itextpdf.styledxmlparser.css.CssContextNode, float, com.itextpdf.layout.renderer.IRenderer, float"
43-
/>
44-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
45-
</Match>
46-
<Match>
47-
<Class name="com.itextpdf.html2pdf.attach.impl.tags.ThTagWorker"/>
48-
<Method
49-
name="processEnd"
50-
params="com.itextpdf.styledxmlparser.node.IElementNode, com.itextpdf.html2pdf.attach.ProcessorContext"
51-
/>
52-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
53-
</Match>
54-
<Match>
55-
<Class name="com.itextpdf.html2pdf.attach.util.WaitingColgroupsHelper"/>
56-
<Or>
57-
<Method name="applyColStyles" params=""/>
58-
<Method
59-
name="applyColStyles"
60-
params="com.itextpdf.styledxmlparser.node.INode, com.itextpdf.html2pdf.attach.util.RowColHelper"
61-
/>
62-
</Or>
63-
<Bug pattern="LSC_LITERAL_STRING_COMPARISON"/>
64-
</Match>
6525
<Match>
6626
<Class name="com.itextpdf.html2pdf.css.CssConstants"/>
6727
<Field name="OVERFLOW_VALUES"/>

src/main/java/com/itextpdf/html2pdf/attach/impl/DefaultHtmlProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ private void visit(INode node) {
330330

331331
visitPseudoElement(element, tagWorker, CssConstants.BEFORE);
332332
visitPseudoElement(element, tagWorker, CssConstants.PLACEHOLDER);
333-
if (element.name().equals(TagConstants.BODY) || element.name().equals(TagConstants.HTML))
333+
if (TagConstants.BODY.equals(element.name()) || TagConstants.HTML.equals(element.name()))
334334
runApplier(element, tagWorker);
335335
for (INode childNode : element.childNodes()) {
336336
if (!context.isProcessingInlineSvg()) {
@@ -345,7 +345,7 @@ private void visit(INode node) {
345345
context.getOutlineHandler().addDestination(tagWorker, element);
346346
context.getState().pop();
347347

348-
if (!element.name().equals(TagConstants.BODY) && !element.name().equals(TagConstants.HTML))
348+
if (!TagConstants.BODY.equals(element.name()) && !TagConstants.HTML.equals(element.name()))
349349
runApplier(element, tagWorker);
350350
if (!context.getState().empty()) {
351351
PageBreakApplierUtil.addPageBreakElementBefore(context, context.getState().top(), element, tagWorker);

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/HeightDimensionContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class HeightDimensionContainer extends DimensionContainer {
5656

5757
HeightDimensionContainer(CssContextNode pmbcNode, float width, float maxHeight, IRenderer renderer, float additionalWidthFix) {
5858
String height = pmbcNode.getStyles().get(CssConstants.HEIGHT);
59-
if (height != null && !height.equals(CssConstants.AUTO)) {
59+
if (height != null && !CssConstants.AUTO.equals(height)) {
6060
dimension = parseDimension(pmbcNode, height, maxHeight, additionalWidthFix);
6161
}
6262
minDimension = getMinHeight(pmbcNode, maxHeight, additionalWidthFix);

src/main/java/com/itextpdf/html2pdf/attach/impl/layout/WidthDimensionContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class WidthDimensionContainer extends DimensionContainer {
5252

5353
public WidthDimensionContainer(CssContextNode node, float maxWidth, IRenderer renderer, float additionalWidthFix) {
5454
String width = node.getStyles().get(CssConstants.WIDTH);
55-
if (width != null && !width.equals(CssConstants.AUTO)) {
55+
if (width != null && !CssConstants.AUTO.equals(width)) {
5656
dimension = parseDimension(node, width, maxWidth, additionalWidthFix);
5757
}
5858
minDimension = getMinWidth(node, maxWidth, additionalWidthFix);

src/main/java/com/itextpdf/html2pdf/attach/impl/tags/ThTagWorker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ public void processEnd(IElementNode element, ProcessorContext context) {
7979
AccessibilityProperties properties = ((IAccessibleElement) elementResult).getAccessibilityProperties();
8080
PdfDictionary attributes = new PdfDictionary();
8181
attributes.put(PdfName.O, PdfName.Table);
82-
if (scope != null && (scope.equalsIgnoreCase(AttributeConstants.ROW) || scope.equalsIgnoreCase(AttributeConstants.ROWGROUP))) {
82+
if (scope != null && (AttributeConstants.ROW.equalsIgnoreCase(scope) || AttributeConstants.ROWGROUP.equalsIgnoreCase(scope))) {
8383
attributes.put(PdfName.Scope, PdfName.Row);
8484
properties.addAttributes(new PdfStructureAttributes(attributes));
85-
} else if (scope != null && (scope.equalsIgnoreCase(AttributeConstants.COL) || scope.equalsIgnoreCase(AttributeConstants.COLGROUP))) {
85+
} else if (scope != null && (AttributeConstants.COL.equalsIgnoreCase(scope) || AttributeConstants.COLGROUP.equalsIgnoreCase(scope))) {
8686
attributes.put(PdfName.Scope, PdfName.Column);
8787
properties.addAttributes(new PdfStructureAttributes(attributes));
8888
} else {

src/main/java/com/itextpdf/html2pdf/attach/util/WaitingColgroupsHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public void applyColStyles() {
105105
for (INode child : tableElement.childNodes()) {
106106
if (child instanceof IElementNode) {
107107
element = (IElementNode) child;
108-
if (element.name().equals(TagConstants.THEAD)) {
108+
if (TagConstants.THEAD.equals(element.name())) {
109109
applyColStyles(element, headerRowColHelper);
110-
} else if (element.name().equals(TagConstants.TFOOT)) {
110+
} else if (TagConstants.TFOOT.equals(element.name())) {
111111
applyColStyles(element, footerRowColHelper);
112112
} else {
113113
applyColStyles(element, tableRowColHelper);
@@ -141,10 +141,10 @@ private void applyColStyles(INode node, RowColHelper rowColHelper) {
141141
for (INode child : node.childNodes()) {
142142
if (child instanceof IElementNode) {
143143
element = (IElementNode) child;
144-
if (element.name().equals(TagConstants.TR)) {
144+
if (TagConstants.TR.equals(element.name())) {
145145
applyColStyles(element, rowColHelper);
146146
rowColHelper.newRow();
147-
} else if (element.name().equals(TagConstants.TH) || element.name().equals(TagConstants.TD)) {
147+
} else if (TagConstants.TH.equals(element.name()) || TagConstants.TD.equals(element.name())) {
148148
Integer colspan = CssUtils.parseInteger(element.getAttribute(AttributeConstants.COLSPAN));
149149
Integer rowspan = CssUtils.parseInteger(element.getAttribute(AttributeConstants.ROWSPAN));
150150
colspan = colspan != null ? colspan : 1;

0 commit comments

Comments
 (0)