You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by Alex Twisleton-Wykeham-Fiennes <al...@screenbase.com> on 2004/03/17 19:14:11 UTC

Classloader issues with DOM3 & JDK 1.4.2

All,

I posted this email to the xerces-j-user list earlier today, but haven't had any
joy as yet.  Since then, I've checked out the latest version from CVS and applied
the same tests with no joy:-

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@nova:~/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@nova:~> 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@nova:~> 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@136228 ]
  .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-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Classloader issues with DOM3 & JDK 1.4.2

Posted by Elena Litani <el...@ca.ibm.com>.



> I have a small code snippet that tries to create a DOMImplementation like
> so:-
>
> import org.apache.xerces.dom3.bootstrap.*;

You are mixing the DOM L3 API in org.w3c.dom package with the DOM Level 2
implementation (which includes dom3.bootsrap package).

Instead specify:
java -Xbootclasspath/p:/home/alex/java/lib/dom3-xml-apis.jar;
p:/home/alex/java/lib/dom3-xercesImpl.jar

For more information read Xerces FAQ and see the download page:
http://xml.apache.org/xerces2-j/faq-dom.html#faq-6
http://www.apache.org/dist/xml/xerces-j/

Thx,
----
Elena Litani / IBM Toronto



                                                                           
             Alex                                                          
             Twisleton-Wykeham                                             
             -Fiennes                                                   To 
             <alex@screenbase.         xerces-j-dev@xml.apache.org         
             com>                                                       cc 
                                                                           
             03/22/2004 01:04                                      Subject 
             PM                        Re: Classloader issues with DOM3 &  
                                       JDK 1.4.2                           
                                                                           
             Please respond to                                             
               xerces-j-dev                                                
                                                                           
                                                                           
                                                                           




Apologies for repeating myself, but I was wondering whether or not anyone
had
had a chance to cast their eye across this problem.  I was advised by Jacob

Kjome on the xerces-j-user list to try utilising the
JAVA_HOME/jre/lib/endorsed classloading technique, but this came up with
the
same result.  If anyone has any suggestions of other tests to try or online

resources then it would be greatly appreciated.

many thanks

Alex

On Wednesday 17 March 2004 18:14, Alex Twisleton-Wykeham-Fiennes wrote:
> All,
>
> I posted this email to the xerces-j-user list earlier today, but haven't
> had any joy as yet.  Since then, I've checked out the latest version from
> CVS and applied the same tests with no joy:-
>
> 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.getDOMImplementa
>tion(Unknown Source) at Test2.main(Test2.java:12)
>
>
> I am using the following version of java:-
> alex@nova:~/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@nova:~> 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.getDOMImplementa
>tion(Unknown Source) at Test2.main(Test2.java:13)
>
> and without the bootclasspath option gives me:-
>
> alex@nova:~> 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.getDOMImplementa
>tion(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@136228 ]
>   .getInterfaces() [
> org.w3c.dom.DOMImplementationSource.getClassLoader()=null ] isnt
instanceof
> DOMImplementationSource
> Exception in thread "main" java.lang.ClassCastException
>         at
>
org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry.getDOMImplementa
>tion(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-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org


Re: Classloader issues with DOM3 & JDK 1.4.2

Posted by Elena Litani <el...@ca.ibm.com>.



> I have a small code snippet that tries to create a DOMImplementation like
> so:-
>
> import org.apache.xerces.dom3.bootstrap.*;

You are mixing the DOM L3 API in org.w3c.dom package with the DOM Level 2
implementation (which includes dom3.bootsrap package).

Instead specify:
java -Xbootclasspath/p:/home/alex/java/lib/dom3-xml-apis.jar;
p:/home/alex/java/lib/dom3-xercesImpl.jar

For more information read Xerces FAQ and see the download page:
http://xml.apache.org/xerces2-j/faq-dom.html#faq-6
http://www.apache.org/dist/xml/xerces-j/

Thx,
----
Elena Litani / IBM Toronto



                                                                           
             Alex                                                          
             Twisleton-Wykeham                                             
             -Fiennes                                                   To 
             <alex@screenbase.         xerces-j-dev@xml.apache.org         
             com>                                                       cc 
                                                                           
             03/22/2004 01:04                                      Subject 
             PM                        Re: Classloader issues with DOM3 &  
                                       JDK 1.4.2                           
                                                                           
             Please respond to                                             
               xerces-j-dev                                                
                                                                           
                                                                           
                                                                           




Apologies for repeating myself, but I was wondering whether or not anyone
had
had a chance to cast their eye across this problem.  I was advised by Jacob

Kjome on the xerces-j-user list to try utilising the
JAVA_HOME/jre/lib/endorsed classloading technique, but this came up with
the
same result.  If anyone has any suggestions of other tests to try or online

resources then it would be greatly appreciated.

many thanks

Alex

On Wednesday 17 March 2004 18:14, Alex Twisleton-Wykeham-Fiennes wrote:
> All,
>
> I posted this email to the xerces-j-user list earlier today, but haven't
> had any joy as yet.  Since then, I've checked out the latest version from
> CVS and applied the same tests with no joy:-
>
> 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.getDOMImplementa
>tion(Unknown Source) at Test2.main(Test2.java:12)
>
>
> I am using the following version of java:-
> alex@nova:~/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@nova:~> 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.getDOMImplementa
>tion(Unknown Source) at Test2.main(Test2.java:13)
>
> and without the bootclasspath option gives me:-
>
> alex@nova:~> 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.getDOMImplementa
>tion(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@136228 ]
>   .getInterfaces() [
> org.w3c.dom.DOMImplementationSource.getClassLoader()=null ] isnt
instanceof
> DOMImplementationSource
> Exception in thread "main" java.lang.ClassCastException
>         at
>
org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry.getDOMImplementa
>tion(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-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org


Re: Classloader issues with DOM3 & JDK 1.4.2

Posted by Alex Twisleton-Wykeham-Fiennes <al...@screenbase.com>.
Apologies for repeating myself, but I was wondering whether or not anyone had 
had a chance to cast their eye across this problem.  I was advised by Jacob 
Kjome on the xerces-j-user list to try utilising the 
JAVA_HOME/jre/lib/endorsed classloading technique, but this came up with the 
same result.  If anyone has any suggestions of other tests to try or online 
resources then it would be greatly appreciated.

many thanks

Alex

On Wednesday 17 March 2004 18:14, Alex Twisleton-Wykeham-Fiennes wrote:
> All,
>
> I posted this email to the xerces-j-user list earlier today, but haven't
> had any joy as yet.  Since then, I've checked out the latest version from
> CVS and applied the same tests with no joy:-
>
> 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.getDOMImplementa
>tion(Unknown Source) at Test2.main(Test2.java:12)
>
>
> I am using the following version of java:-
> alex@nova:~/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@nova:~> 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.getDOMImplementa
>tion(Unknown Source) at Test2.main(Test2.java:13)
>
> and without the bootclasspath option gives me:-
>
> alex@nova:~> 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.getDOMImplementa
>tion(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@136228 ]
>   .getInterfaces() [
> org.w3c.dom.DOMImplementationSource.getClassLoader()=null ] isnt instanceof
> DOMImplementationSource
> Exception in thread "main" java.lang.ClassCastException
>         at
> org.apache.xerces.dom3.bootstrap.DOMImplementationRegistry.getDOMImplementa
>tion(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-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-j-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org