[jdom-interest] ClassCastException

kenk at boxerlearning.com kenk at boxerlearning.com
Tue Sep 10 07:48:13 PDT 2002


Hi,

I looked through the archives, and found a thread on june 26 (subject 
"ClassCastException"), where people were having virtually the same problem I'm 
having now.

The problem is that when I call new SAXBuilder(true).build(file), I get a 
ClassCastException in the SAXBuilder.createParser() method.  The errors 
reported in the june 26 thread are essentially the same as what I see.  Here's 
my stack-trace:

org.jdom.JDOMException: Error in building: org.apache.xerces.parsers.SAXParser
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:373)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
        at com.boxerlearning.app.xml.WebXmlReader.process(WebXmlReader.java:67)
        at com.boxerlearning.app.xml.WebXmlReaderTest.testBuild(WebXmlReaderTes
t.java:35)
        at java.lang.reflect.Method.invoke(Native Method)
        at junit.framework.TestCase.runTest(TestCase.java:166)
        at junit.framework.TestCase.runBare(TestCase.java:140)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:131)
        at junit.framework.TestSuite.runTest(TestSuite.java:173)
        at junit.framework.TestSuite.run(TestSuite.java:168)
        at junit.awtui.TestRunner$10.run(TestRunner.java:403)
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser
        at org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:459)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:335)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
        at com.boxerlearning.app.xml.WebXmlReader.process(WebXmlReader.java:67)
        at com.boxerlearning.app.xml.WebXmlReaderTest.testBuild(WebXmlReaderTes
t.java:35)
        at java.lang.reflect.Method.invoke(Native Method)
        at junit.framework.TestCase.runTest(TestCase.java:166)
        at junit.framework.TestCase.runBare(TestCase.java:140)
        at junit.framework.TestResult$1.protect(TestResult.java:106)
        at junit.framework.TestResult.runProtected(TestResult.java:124)
        at junit.framework.TestResult.run(TestResult.java:109)
        at junit.framework.TestCase.run(TestCase.java:131)
        at junit.framework.TestSuite.runTest(TestSuite.java:173)
        at junit.framework.TestSuite.run(TestSuite.java:168)
        at junit.awtui.TestRunner$10.run(TestRunner.java:403)


I'm not running under ant, but I am using junit.  When I de-select the "reload 
classes" button in junit, the problem goes away.  Unfortunately, I'm testing 
some class-initializations, so that solution does not work, in general.

The assessment made on June 26 by Bob McWhirter was that the object being 
created is an XMLReader, as loaded by one ClassLoader, but it's being cast to 
XMLReader, loaded by a different ClassLoader, so the cast fails.

He also recommends messing with the AntClassLoader, which doesn't do me any 
good, since my problem is with junit, not ant.

What I'd like to know is:

1) Has this been officially reported as a bug in JDOM?
2) Does anyone know of any plans to address the problem?
3) Has anyone contacted the junit people about this bug?  It seems to me like 
it's a bug in junit, as well.

Thanks,
-- Ken





More information about the jdom-interest mailing list