[jdom-interest] SAXBuilder / JAXP error

Laurent Bihanic laurent.bihanic at atosorigin.com
Mon Nov 5 00:46:46 PST 2001


Jason Hunter wrote:

> I wonder if Weblogic 6.1 reimplemented the JAXP libraries and added this
> as a bug.
> 

This is actually a known problem in SAXBuilder: On the first call to 
createParser (via build), SAXBuilder caches the class name of the SAX parser, 
even when JAXP was used to create the parser instance:
462              saxDriverClass = parser.getClass().getName();

If you try to reuse a SAXBuilder instance, it will not longer use JAXP to 
create the parser but will use:
         if (saxDriverClass != null) {
             // The user knows that they want to use a particular class
             parser = XMLReaderFactory.createXMLReader(saxDriverClass);
             // System.out.println("using specific " + saxDriverClass);
         } else {

In this case, BEA are not wrong: they just have no no-args public contructor 
for their parser, which makes it inedible by XMLReaderFactory.

This issue has already been discussed on this list but no changes were made to 
SAXBuilder (but I don't remember why!). So, my fix is just to comment out the 
line "saxDriverClass = ..." in the JAXP part of createParser every time I get 
a new JDOM version.

Hope this helps,

Laurent

> 
> Alastair Rodgers wrote:
> 
>>Hi,
>>
>>I have been using JDOM within Weblogic 6.0 for some time, but have come across a  JAXP / SAXBuilder problem when trying to migrate to Weblogic 6.1. The problem arises in a custom Weblogic startup class I've written. Basically, if I code it as follows I don't get a problem:
>>
>>        File[] oFiles = ...[get list of files]...
>>      for (int i = 0; i < oFiles.length; i++) {
>>        Document oDoc = new SAXBuilder().build(oFiles[i]);
>>        ...[do stuff]...
>>      }
>>
>>However, if instead of creating a new SAXBuilder on each iteration, I just create a single instance and reuse it:
>>
>>      SAXBuilder oBuilder = new SAXBuilder();
>>        File[] oFiles = ...[get list of files]...
>>      for (int i = 0; i < oFiles.length; i++) {
>>        Document oDoc = oBuilder.build(oFiles[i]);
>>        ...[do stuff]...
>>      }
>>
>>...then it executes OK for the first file, but when it tries to do oBuilder.build() for the second time, I get the following error:
>>
>>Error in building: SAX2 driver class weblogic.xml.jaxp.RegistryXMLReader loaded but cannot be instantiated (no empty public constructor?)
>>org.jdom.JDOMException: Error in building: SAX2 driver class weblogic.xml.jaxp.RegistryXMLReader loaded but cannot be instantiated (no empty public constructor?)
>>        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:306)
>>        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:617)
>>        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:599)
>>        ...[etc]...
>>Root cause: java.lang.InstantiationException: weblogic.xml.jaxp.RegistryXMLReader
>>        at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:124)
>>        at org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:360)
>>        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:283)
>>        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:617)
>>        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:599)
>>        ...[etc]...
>>
>>Does anyone know why this is? Both mechanisms work in Weblogic 6.0 but I can't see what's different in 6.1 which would cause it to fail. I seem to remember a while back someone on this mailing list saying that its wisest to always create a new SAXBuilder instance for each build() call, but I haven't been able to track this down in the archives. Is this true? If so, why?
>>
>>Thanks for any help.
>>
>>Al Rodgers
>>Senior Developer
>>Phocis Ltd





More information about the jdom-interest mailing list