Subjects
Home
VOTE Move XML Commons to Xerces
Commented: (XERCESJ 589) Bug with pattern restriction on long strings
: Xerces J 2 8 1 Release on Wednesday, September 13th
: Xerces J 2 9 0 Release on Wednesday, November 22nd
Commented: (XERCESJ 1066) Restriction+choice+substitutionGroup error
Commented: (XERCESJ 1178) Error getting prefix for an attribute with no n
Updated: (XERCESJ 1244) XMLSchemaValidator does not contribute element 's
Some consideration about the xerces DOM implementation
Updated: (XERCESJ 1066) Restriction+choice+substitutionGroup error
Commented: (XERCESJ 1227) Poor performance / OutOfMemoryError for sequenc
retain exception stack traces
Updated: (XERCESJ 1193) NPE or hang when parsing using the "continue afte
Future of NekoHTML
Commented: (XERCESJ 1203) NPE in XMLDTDProcessor
DOM Level 3 APIs for Xalan J and a new Xalan release (2 7 1)
: xml commons external 1 3 04 Release on Wednesday, November 22nd
Commented: (XERCESJ 1247) Incorrect location information on SAX when usin
XInclude exceptions how to mirror Xerces J functionality into Xerces C++?
First proposal on SoC project "Add support for the StAX (JSR 173) cursor API
: xml commons resolver 1 2 Release on Wednesday, November 22nd
Typo in RangeToken java Please check
Validator features
java lang ClassCastException when adopting Node
using the org apache xerces impl xs identity package
Updated: (XERCESJ 1257) buffer overflow in UTF8Reader for characters out
Problem with ref attributes and schema validation
Updated: (XERCESJ 122) XMLSchemaValidator does not contribute element 's d
Performance problem under load Xerces with Weblogic 9 x
remove ignored memory allocation
Commented: (XERCESJ 1177) SAXXMLStreamReader doesn 't always report namesp
Commented: (XERCESJ 977) Null pointer exception during DOM parsing
Commented: (XERCESJ 1197) Code cleanup for org apache xml serialize
Commented: (XERCESJ 1201) Initial contribution for StAX Event API
Updated: (XERCESJ 1061) Regex "$ " and "^ " characters treated as special c
Commented: (XERCESJ 1199) SAXXMLStreamReader should attempt to register a
Commented: (XERCESJ 1061) Regex "$ " and "^ " characters treated as special
Updated: (XERCESJ 589) Bug with pattern restriction on long strings
StackOverflow
xerces Range unnecessarily not garbage collectable if not detached
Updated: (XERCESJ 1178) Error getting prefix for an attribute with no nam
Bug in xs:redefine
Commented: (XERCESJ 1204) Can not set XMLEntityResolver for LSParser
Updated: (XERCESJ 1253) Prototype for SoC2007 project "Add support for th
Updated: (XERCESJ 1259) Add SteamFilter Function to SoC2007 project "Add
Assigned: (XERCESJ 444) SAXException thrown by EntityResolver is reported
Google Summer of Code 2007
Xerces J and XInclude relative path issue
Assigned: (XERCESJ 206) Stack overflow when using a schema validation
Commented: (XERCESJ 1215) Restrictions involving two levels of substituti
Closed: (XERCESJ 1203) NPE in XMLDTDProcessor
non overriding equals methoda
Resolved: (XERCESJ 1079) invalid value returned for TOTALDIGITS facet in
Xerces AS3 port
Updated: (XERCESJ 325) Regular Expression; Pattern "| " clause order de
Updated: (XERCESJ 1196) Javadoc generation fails on Java SE 5 0
Closed: (XERCESJ 1202) DTD validation on XIncluded documents when the sch
Created: (XERCESJ 1124) Nonspecific schema error message
a bug in xerces
Updated: (XERCESJ 1201) Initial contribution for StAX Event API
Closed: (XERCESJ 1254) Empty uris in targetNamespace attribute not report
Links
Home
Oracle database error code
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Classloader issues with DOM3 & JDK 1.4.2

Classloader issues with DOM3 & JDK 1.4.2

2004-03-17       - By Alex Twisleton-Wykeham-Fiennes
Reply:     1     2     3     4  

All,

apologies if this is an FAQ, but I haven't been able to track down what the
solution to this one is either in the docs or the mailing lists.

I have a small code snippet that tries to create a DOMImplementation like so:-

import org.apache.xerces.dom3.bootstrap.*;
import org.w3c.dom.*;

public class Test2
{
 public static void main(String[] args)
   throws Exception
 {
   System.setProperty(DOMImplementationRegistry.PROPERTY,
          "org.apache.xerces.dom.DOMImplementationSourceImpl");
   DOMImplementationRegistry registry
     = DOMImplementationRegistry.newInstance();
   DOMImplementation impl
     = (DOMImplementation) registry.getDOMImplementation("LS");
 }
}

Unfortunately this fails with the following:-
Exception in thread "main" java.lang.ClassCastException
       at org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry
.getDOMImplementation(Unknown Source)
       at Test2.main(Test2.java:12)


I am using the following version of java:-
alex@(protected):~/java/src> java -version
java version "1.4.2_04"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)

and am invoking the command utilising:-
java -Xbootclasspath/p:/home/alex/java/lib/dom3-xml-apis.jar Test2

If I run the application utilising the -verbose flag, and filter out all
non-DOM related lines I get the following:-

alex@(protected):~> java -Xbootclasspath/p:/home/alex/java/lib/dom3-xml-apis.jar
-verbose Test2 | grep DOM
[Loaded org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry]
[Loaded org.apache.xerces.dom3.DOMImplementationList]
[Loaded org.w3c.dom.DOMImplementationSource from /home/alex/java/lib/dom3-xml
-apis.jar]
[Loaded org.apache.xerces.dom.DOMImplementationSourceImpl]
[Loaded org.w3c.dom.DOMImplementationList from /home/alex/java/lib/dom3-xml
-apis.jar]
[Loaded org.apache.xerces.dom3.DOMImplementationSource]
Exception in thread "main" java.lang.ClassCastException
       at org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry
.getDOMImplementation(Unknown Source)
       at Test2.main(Test2.java:13)

and without the bootclasspath option gives me:-

alex@(protected):~> java -verbose:class Test2 | grep DOM
[Loaded org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry]
[Loaded org.apache.xerces.dom3.DOMImplementationList]
[Loaded org.w3c.dom.DOMImplementationSource]
[Loaded org.apache.xerces.dom.DOMImplementationSourceImpl]
[Loaded org.w3c.dom.DOMImplementationList]
[Loaded org.apache.xerces.dom3.DOMImplementationSource]
Exception in thread "main" java.lang.ClassCastExceptionisnt instanceof
DOMImplementationSource
       at org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry
.getDOMImplementation(Unknown Source)
       at Test2.main(Test2.java:13)

which implies that the bootclasspath is forcing the bootstrap ClassLoader
to load the DOMImplementationSource and the DOMImplementationList with all
the other classes being loaded by some other ClassLoader (that doesn't
specify which location they are being got from).  At least the org.w3c.dom
classes are being got from the appropriate xerces jar which is a step in the
right direction.

I then did a little bit of hacking around and added some debugging information
into the DOMImplementationRegistry, to debug a bit what is going on, namely
this:-

 public static void debug(Class c,
        StringBuffer buf)
 {
   buf.append("debug(")
     .append(c.getName())
     .append(")\n");
   buf.append("  .getSuperclass() [ ")
     .append(c.getSuperclass() == null
       ? "null"
       : c.getSuperclass().getName())
     .append(" ]\n");
   buf.append("  .getClassLoader() [ ")
     .append(c.getClassLoader())
     .append(" ]\n");
   buf.append("  .getInterfaces() [ ");
   Class[] classes = c.getInterfaces();
   for (int i = 0; i < classes.length; i++) {
     buf.append(classes[i].getName())
  .append(".getClassLoader()=")
  .append(classes[i].getClassLoader())
  .append(" ");
   }
   buf.append("]");
 }
 
 public static String debug(Class c)
 {
   StringBuffer buf = new StringBuffer();
   debug(c,
   buf);
   return buf.toString();
 }

and then added this into the DOMImplementationRegistry.newInstance() method to
give some feedback on what is being created like so:-

 public static DOMImplementationRegistry newInstance()    
   throws ClassNotFoundException, InstantiationException,
IllegalAccessException
 {
   Vector _sources = new Vector();      
   // fetch system property:
   String p = System.getProperty(PROPERTY);
   if (p != null) {
     StringTokenizer st = new StringTokenizer(p);
     while (st.hasMoreTokens()) {
  String sourceName = st.nextToken();
  // Use context class loader, falling back to Class.forName
  // if and only if this fails...
  Object source = getClass(sourceName).newInstance();
  System.out.println(debug(source.getClass()));
  System.out.println((source instanceof DOMImplementationSource)
              ? "is instanceof DOMImplementationSource"
        : "isnt instanceof DOMImplementationSource");
  _sources.add(source);
     }
   }
   return new DOMImplementationRegistry(_sources);
 }

Now my both my bootclasspath option and default options output the following:-

debug(org.apache.xerces.dom.DOMImplementationSourceImpl)
 .getSuperclass() [ java.lang.Object ]
 .getClassLoader() [ sun.misc.Launcher$AppClassLoader@(protected) ]
 .getInterfaces() [ org.w3c.dom.DOMImplementationSource.getClassLoader()=null ]
isnt instanceof DOMImplementationSource
Exception in thread "main" java.lang.ClassCastException
       at org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry
.getDOMImplementation(Unknown Source)
       at Test2.main(Test2.java:13)

The alarm bell for me was that although the DOMImplementationsSourceImpl had
been created with a sun.misc.Launcher$AppClassLoader ClassLoader, the
DOMImplementationSource interface had been instantiation by the bootstrap
ClassLoader.

Then when we say "source instanceof DOMImplementationSource", this will utilise
the default ClassLoader for the DOMImplementationRegistry (which is not the
bootstrap ClassLoader from the -verbose tests above) and create a seperate
instance of the DOMImplementationSource interface for the equivalent
ClassLoader.
This is therefore not equal to the bootstrap provided instance of
DOMImplementationSource
and therefore the result of "source instanceof DOMImplementationSource" is
false.

This is all pretty new to me, but I am reasonably convinced that my steps in
getting to this point are relatively sane (and if they are not then would be
very grateful for anyones rapid enlightenment) and I am now in a position where
I do not know how to move forwards.  Is this a quirk of the JVM that I am using
and will it be necessary to downgrade to an earlier version or is there a more
complex underlying problem.

Many thanks for anyones help.

Alex

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@(protected)
For additional commands, e-mail: xerces-j-user-help@(protected)