Browse files

Fixes #94 - Gives a better Stack trace (includes underlying cause) if…

… a singleton has failed to intialize
  • Loading branch information...
1 parent 804eb7b commit 690e795723283df2d0b301637cbe47ccd3658823 @rolfl rolfl committed Sep 27, 2012
Showing with 7 additions and 1 deletion.
  1. +7 −1 core/src/java/org/jdom2/input/sax/XMLReaders.java
View
8 core/src/java/org/jdom2/input/sax/XMLReaders.java
@@ -96,13 +96,15 @@ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
/** the actual SAXParserFactory in the respective singletons. */
private final SAXParserFactory jaxpfactory;
+ private final Exception failcause;
/** Is this a validating parser */
private final boolean validates;
/** Private constructor */
private XMLReaders(int validate) {
SAXParserFactory fac = SAXParserFactory.newInstance();
boolean val = false;
+ Exception problem = null;
// All JDOM parsers are namespace aware.
fac.setNamespaceAware(true);
switch (validate) {
@@ -124,21 +126,25 @@ private XMLReaders(int validate) {
} catch (SAXException se) {
// we could not get a validating system, set the fac to null
fac = null;
+ problem = se;
} catch (IllegalArgumentException iae) {
// this system does not support XSD Validation.... which is true for android!
// we could not get a validating system, set the fac to null
fac = null;
+ problem = iae;
} catch (UnsupportedOperationException uoe) {
// SAXParserFactory throws this exception when setSchema is called.
// Therefore every factory throws this exception unless it overrides
// setSchema. A popular example is Apache Xerces SAXParserFactoryImpl
// before version 2.7.0.
fac = null;
+ problem = uoe;
}
break;
}
jaxpfactory = fac;
validates = val;
+ failcause = problem;
}
/**
@@ -153,7 +159,7 @@ private XMLReaders(int validate) {
public XMLReader createXMLReader() throws JDOMException {
if (jaxpfactory == null) {
throw new JDOMException("It was not possible to configure a " +
- "suitable XMLReader to support " + this);
+ "suitable XMLReader to support " + this, failcause);
}
try {
return jaxpfactory.newSAXParser().getXMLReader();

0 comments on commit 690e795

Please sign in to comment.