From 381129b202eb3e636335b559c3922ab0a40390ed Mon Sep 17 00:00:00 2001 From: azerr Date: Wed, 8 Mar 2023 09:19:42 +0100 Subject: [PATCH] NullPointerException in documentColor Fixes #1473 Signed-off-by: azerr --- .../XMLDocumentColorParticipant.java | 2 +- .../colors/XMLColorsExtensionsTest.java | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/colors/participants/XMLDocumentColorParticipant.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/colors/participants/XMLDocumentColorParticipant.java index bf34f3348..df830d884 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/colors/participants/XMLDocumentColorParticipant.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/extensions/colors/participants/XMLDocumentColorParticipant.java @@ -129,7 +129,7 @@ public void doColorPresentations(DOMDocument xmlDocument, ColorPresentationParam private static boolean isColorNode(DOMNode node, List 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()) { diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/colors/XMLColorsExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/colors/XMLColorsExtensionsTest.java index 9e8598b9c..713ac2f34 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/colors/XMLColorsExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/colors/XMLColorsExtensionsTest.java @@ -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 = "\r\n" + + "\r\n" + + " #f00\r\n" + + " #80ff0000\r\n" + + " \r\n" // <-- here item/@color has no attr value + + " \r\n" // <-- here item/@color is colorized + + " \r\n" // + + ""; + 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 @@ -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 colors = new ArrayList<>(); settings.setColors(colors);