fix TreeMap NPE in XML namespace context
This commit is contained in:
parent
6f932191b6
commit
c2e4bb8646
2 changed files with 18 additions and 11 deletions
|
@ -27,14 +27,17 @@ public class XmlNamespaceContext implements NamespaceContext {
|
|||
private static final XmlNamespaceContext DEFAULT_CONTEXT = newDefaultInstance();
|
||||
|
||||
// sort namespace by length in descending order, useful for compacting prefix
|
||||
protected final SortedMap<String, String> namespaces = new TreeMap<>();
|
||||
private final SortedMap<String, String> namespaces;
|
||||
|
||||
private final SortedMap<String, Set<String>> prefixes = new TreeMap<>();
|
||||
private final SortedMap<String, Set<String>> prefixes;
|
||||
|
||||
protected XmlNamespaceContext() {
|
||||
this.namespaces = new TreeMap<>();
|
||||
this.prefixes = new TreeMap<>();
|
||||
}
|
||||
|
||||
protected XmlNamespaceContext(ResourceBundle bundle) {
|
||||
this();
|
||||
Enumeration<String> en = bundle.getKeys();
|
||||
while (en.hasMoreElements()) {
|
||||
String prefix = en.nextElement();
|
||||
|
@ -79,6 +82,8 @@ public class XmlNamespaceContext implements NamespaceContext {
|
|||
}
|
||||
|
||||
public void addNamespace(String prefix, String namespace) {
|
||||
if (prefix != null && namespace != null) {
|
||||
synchronized (namespaces) {
|
||||
namespaces.put(prefix, namespace);
|
||||
if (prefixes.containsKey(namespace)) {
|
||||
prefixes.get(namespace).add(prefix);
|
||||
|
@ -88,6 +93,8 @@ public class XmlNamespaceContext implements NamespaceContext {
|
|||
prefixes.put(namespace, set);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SortedMap<String, String> getNamespaces() {
|
||||
return namespaces;
|
||||
|
@ -98,7 +105,7 @@ public class XmlNamespaceContext implements NamespaceContext {
|
|||
if (prefix == null) {
|
||||
return null;
|
||||
}
|
||||
return namespaces.containsKey(prefix) ? namespaces.get(prefix) : null;
|
||||
return namespaces.getOrDefault(prefix, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
group = org.xbib
|
||||
name = content
|
||||
version = 1.2.2
|
||||
version = 1.2.3
|
||||
|
||||
jackson.version = 2.8.11
|
||||
xbib-net.version = 1.0.0
|
||||
|
|
Loading…
Reference in a new issue