Skip to content

Commit

Permalink
NPE on xsd datatype autocompletion in binary mode
Browse files Browse the repository at this point in the history
Fixes #1189

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
azerr authored and angelozerr committed Mar 29, 2022
1 parent 4a176d5 commit f0daed7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Expand Up @@ -12,8 +12,11 @@
package org.eclipse.lemminx.extensions.xsd;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
Expand All @@ -30,6 +33,8 @@

public class DataType {

private static final Logger LOGGER = Logger.getLogger(DataType.class.getName());

private static String lineSeparator = System.lineSeparator();

private static final Map<String, DataType> dataTypes;
Expand Down Expand Up @@ -103,14 +108,16 @@ public static String getDocumentation(DOMAttr attr) {
}

private static Map<String, DataType> loadDataTypes() {
String dataTypesFile = "/schemas/xsd/datatypes.xml";
try {
SAXParserFactory factory = DOMUtils.newSAXParserFactory();
SAXParser saxParser = factory.newSAXParser();
DataTypeHandler handler = new DataTypeHandler();
saxParser.parse(new InputSource(DataType.class.getResourceAsStream("/schemas/xsd/datatypes.xml")), handler);
saxParser.parse(new InputSource(DataType.class.getResourceAsStream(dataTypesFile)), handler);
return handler.getDataTypes();
} catch (Exception e) {
return null;
LOGGER.log(Level.SEVERE, "Error while loading data types with file '" + dataTypesFile + "'.", e);
return Collections.emptyMap();
}
}

Expand Down
Expand Up @@ -33,6 +33,9 @@
{
"pattern": "\\Qschemas/xsd/datatypes.dtd\\E"
},
{
"pattern": "\\Qschemas/xsd/datatypes.xml\\E"
},
{
"pattern": "\\Qschemas/xsd/xml.xsd\\E"
},
Expand Down

0 comments on commit f0daed7

Please sign in to comment.