Skip to content

Commit 18cf9d9

Browse files
committed
Help debugging XML issues
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 4f918b6 commit 18cf9d9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/main/java/org/scijava/util/XML.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ public class XML {
7676
/** XPath evaluation mechanism. */
7777
private final XPath xpath;
7878

79+
private final boolean debug =
80+
"debug".equals(System.getProperty("scijava.log.level"));
81+
7982
/** Parses XML from the given file. */
8083
public XML(final File file) throws ParserConfigurationException,
8184
SAXException, IOException
@@ -123,6 +126,10 @@ public XML(final String path, final Document doc) {
123126
// (because the XPathFactory will ask the context class loader to find the
124127
// configured services, including the
125128
// com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl).
129+
if (debug) {
130+
System.err.println(ClassUtils.getLocation(XPathFactory.class));
131+
}
132+
126133
XPath xpath = null;
127134
final Thread thread = Thread.currentThread();
128135
final ClassLoader contextClassLoader = thread.getContextClassLoader();
@@ -135,10 +142,17 @@ public XML(final String path, final Document doc) {
135142
// expressions (i.e. *not* throw NoSuchMethodErrors).
136143
xpath.evaluate("//dummy", doc);
137144
} catch (Throwable t) {
145+
if (debug) {
146+
System.err.println("There was a problem with " +
147+
xpath.getClass() + " in " +
148+
ClassUtils.getLocation(xpath.getClass()) + ":");
149+
t.printStackTrace();
150+
}
138151
throw new Error(t);
139152
}
140153
break;
141154
} catch (Error e) {
155+
if (debug) e.printStackTrace();
142156
loader = loader.getParent();
143157
if (loader == null) throw e;
144158
thread.setContextClassLoader(loader);

0 commit comments

Comments
 (0)