Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Fix NPE on empty .xsd document #58

Merged
merged 1 commit into from
Jun 5, 2020
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 @@ -288,6 +288,9 @@ public static void searchXSOriginAttributes(DOMNode targetNode, BiConsumer<DOMAt
* @return the referenced attributes list from the given referenced node.
*/
private static List<DOMAttr> getTargetAttrs(DOMNode referencedNode) {
if (referencedNode == null) {
return Collections.emptyList();
}
List<DOMAttr> referencedNodes = new ArrayList<>();
Document document = referencedNode.getOwnerDocument();
switch (referencedNode.getNodeType()) {
Expand All @@ -302,7 +305,11 @@ private static List<DOMAttr> getTargetAttrs(DOMNode referencedNode) {
// The referenced node is the DOM document, collect all attributes
// xs:complexType/@name, xs:simpleType/@name, xs:element/@name, xs:group/@name
// which can be referenced
NodeList nodes = document.getDocumentElement().getChildNodes();
Element documentElement = document.getDocumentElement();
if (documentElement == null) {
break;
}
NodeList nodes = documentElement.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node n = nodes.item(i);
if (n.getNodeType() == Node.ELEMENT_NODE) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,16 @@ public void codeLensOnComplexTypeAndSimpleType() throws BadLocationException {
cl(r(15, 16, 15, 35), "1 reference", SHOW_REFERENCES));
}

@Test
public void codeLensEmptyDocument() throws BadLocationException {
String xml = "";
XMLAssert.testCodeLensFor(xml);
}

@Test
public void codeLensSpace() throws BadLocationException {
String xml = " ";
XMLAssert.testCodeLensFor(xml);
}

}