Skip to content

Commit

Permalink
NullPointerException in documentColor
Browse files Browse the repository at this point in the history
Fixes #1473

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Mar 10, 2023
1 parent 705f1cf commit 7feb246
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void doColorPresentations(DOMDocument xmlDocument, ColorPresentationParam
private static boolean isColorNode(DOMNode node, List<XMLColorExpression> expressions) {
if (node.isAttribute()) {
DOMAttr attr = (DOMAttr) node;
if (attr.getValue() == null && attr.getValue().isEmpty()) {
if (attr.getValue() == null || attr.getValue().isEmpty()) {
return false;
}
} else if (node.isText()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,22 @@ public void colorOnAttr() throws BadLocationException {
colorInfo(1, 0, 0, 1, r(5, 14, 5, 17)));
}

@Test
public void colorOnAttrWithoutValue() throws BadLocationException {
// Here color is done for item/@color only
XMLColorsSettings settings = createXMLColorsSettings();
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"
+ "<resources>\r\n"
+ " <color name=\"opaque_red\">#f00</color>\r\n"
+ " <color name=\"translucent_red\">#80ff0000</color>\r\n"
+ " <item color= />\r\n" // <-- here item/@color has no attr value
+ " <item color=\"red\" />\r\n" // <-- here item/@color is colorized
+ " <item color=\"BAD_COLOR\" />\r\n" //
+ "</resources>";
testColorInformationFor(xml, "file:///test/colors-attr.xml", settings, //
colorInfo(1, 0, 0, 1, r(5, 14, 5, 17)));
}

@Test
public void colorAllPresentation() throws BadLocationException {
// Here color is done for color/text() only
Expand Down Expand Up @@ -106,8 +122,8 @@ public void colorPresentation() throws BadLocationException {
colorPres("rgb(0,128,0)", te(2, 14, 2, 19, "rgb(0,128,0)")), //
colorPres("#008000", te(2, 14, 2, 19, "#008000")));
}

private XMLColorsSettings createXMLColorsSettings() {
private static XMLColorsSettings createXMLColorsSettings() {
XMLColorsSettings settings = new XMLColorsSettings();
List<XMLColors> colors = new ArrayList<>();
settings.setColors(colors);
Expand Down

0 comments on commit 7feb246

Please sign in to comment.