Skip to content

Commit

Permalink
Fix NPE on empty .xsd document
Browse files Browse the repository at this point in the history
Added some null checks to prevent the NPE occuring.

Fixes eclipse-lemminx#684
  • Loading branch information
datho7561 committed Jun 4, 2020
1 parent 35ac5a1 commit 2e89f5d
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ public static void searchXSOriginAttributes(DOMNode targetNode, BiConsumer<DOMAt
*/
private static List<DOMAttr> getTargetAttrs(DOMNode referencedNode) {
List<DOMAttr> referencedNodes = new ArrayList<>();
if (referencedNode == null) {
return referencedNodes;
}
Document document = referencedNode.getOwnerDocument();
switch (referencedNode.getNodeType()) {
case Node.ATTRIBUTE_NODE:
Expand All @@ -302,6 +305,9 @@ 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
if (document.getDocumentElement() == null) {
break;
}
NodeList nodes = document.getDocumentElement().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node n = nodes.item(i);
Expand Down

0 comments on commit 2e89f5d

Please sign in to comment.