Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] classloading bug with xom used in servlet

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Wolfgang Hoschek <whoschek AT lbl.gov>
  • To: xom-interest AT lists.ibiblio.org
  • Subject: [XOM-interest] classloading bug with xom used in servlet
  • Date: Mon, 02 Feb 2004 11:32:47 -0800

Hi,

In d23 there seems to be a classloading bug that manifests itself when using xom in a servlet where xom.jar is put into WEB-INF/lib. Here, the Verifier cannot be initialized and throws a java.lang.ExceptionInInitializerError
at nu.xom.Element.setNamespaceURI(Element.java:719)

I tentatively patched the way the Verifier looks up characters.dat so that it works for me in the servlet case:

static {
//ClassLoader loader = ClassLoader.getSystemClassLoader();
//DataInputStream in = new DataInputStream(
// loader.getResourceAsStream("nu/xom/characters.dat"));

DataInputStream in = new
DataInputStream(getResourceAsStream("nu/xom/characters.dat"));

// no other changes
// ...
}

private static java.io.InputStream getResourceAsStream(String fileName) {
ClassLoader loader =
Thread.currentThread().getContextClassLoader();
if (loader == null) { // there may not be a context class
loader
loader = Verifier.class.getClassLoader();
}

return loader.getResourceAsStream(fileName);
}


Above patch works for me but can perhaps be improved - I'm no class loader guru either...

Regards,
Wolfgang.





Archive powered by MHonArc 2.6.24.

Top of Page