Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in documentColor #1501

Merged
merged 1 commit into from
Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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