yashk / thread-weaver

Automatically exported from code.google.com/p/thread-weaver
Apache License 2.0
0 stars 0 forks source link

SAXParser cannot be cast to XMLReader #3

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
--What steps will reproduce the problem?
1. make sure that your test uses NEW xerces or jdom api to parse xml files
2. use BaseThreadedTestRunner subclasses to run tests
3. use SAXBuilder.build(XMLReader) in test
--> ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast
to org.xml.sax.XMLReader

--What version of the product are you using? On what operating system?
0.1

--Please provide any additional information below.
That exception occured on old xerces implementations.

Original issue reported on code.google.com by ytri...@gmail.com on 24 Nov 2009 at 1:29

GoogleCodeExporter commented 8 years ago
Sorry for not responding sooner - I did not have notifications set up for 
issues, so I didn't get an e-mail about this.

Do you have a stack trace that shows the problem?

Original comment by alasdair.mackintosh on 12 Jun 2010 at 11:14

GoogleCodeExporter commented 8 years ago
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
    at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:179)
    at com.google.testing.threadtester.BaseThreadedTestRunner.runTests(BaseThreadedTestRunner.java:165)
    at voldemort.client.rebalance.RebalanceMetadataConsistencyTest.testThreading(RebalanceMetadataConsistencyTest.java:160)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:44)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
    at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
    ... 27 more
Caused by: java.lang.RuntimeException: 
java.lang.reflect.InvocationTargetException
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:71)
    at com.google.testing.threadtester.AnnotatedTestWrapper$MainTestCaseRunner.initialize(AnnotatedTestWrapper.java:311)
    at com.google.testing.threadtester.InterleavedRunner.doInterleave(InterleavedRunner.java:137)
    at com.google.testing.threadtester.InterleavedRunner.interleave(InterleavedRunner.java:80)
    at com.google.testing.threadtester.AnnotatedTestWrapper.runTestCases(AnnotatedTestWrapper.java:258)
    at com.google.testing.threadtester.AnnotatedTestWrapper.runTests(AnnotatedTestWrapper.java:242)
    ... 32 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.google.testing.threadtester.MethodCaller.invoke(MethodCaller.java:68)
    ... 37 more
Caused by: voldemort.xml.MappingException: org.jdom.JDOMException: Could not 
load default SAX parser: org.apache.xerces.parsers.SAXParser: SAX2 driver class 
org.apache.xerces.parsers.SAXParser does not implement XMLReader: 
org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
    at voldemort.xml.ClusterMapper.readCluster(ClusterMapper.java:122)
    at voldemort.xml.ClusterMapper.readCluster(ClusterMapper.java:95)
    at voldemort.utils.RebalanceUtils.createUpdatedCluster(RebalanceUtils.java:329)
    at voldemort.client.rebalance.RebalanceMetadataConsistencyTest.before(RebalanceMetadataConsistencyTest.java:85)
    ... 42 more
Caused by: org.jdom.JDOMException: Could not load default SAX parser: 
org.apache.xerces.parsers.SAXParser: SAX2 driver class 
org.apache.xerces.parsers.SAXParser does not implement XMLReader: 
org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
    at org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:618)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:460)
    at org.jdom.input.SAXBuilder.build(SAXBuilder.java:888)
    at voldemort.xml.ClusterMapper.readCluster(ClusterMapper.java:102)
    ... 45 more
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser 
cannot be cast to org.xml.sax.XMLReader
    at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:199)
    at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:180)
    at org.jdom.input.SAXBuilder.createParser(SAXBuilder.java:610)
    ... 48 more
Caused by: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser 
cannot be cast to org.xml.sax.XMLReader
    at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:187)
    ... 50 more

Original comment by abhinayn...@gmail.com on 10 May 2013 at 11:09

GoogleCodeExporter commented 8 years ago
Hmm. When ThreadWeaver runs the tests, it has to reload the class under test 
using a custom class loader. I wonder if the loaded class has something missing 
in its classpath, which means that it cannot load the necessary parser?

Is there any chance that you can can send me the code that you are trying to 
test?

Original comment by alasdair.mackintosh on 12 May 2013 at 1:30

GoogleCodeExporter commented 8 years ago
sure it is open source ;-) I will push my changes in half a day

Original comment by abhinayn...@gmail.com on 13 May 2013 at 5:35

GoogleCodeExporter commented 8 years ago
https://github.com/abh1nay/voldemort/tree/atomicupdate

https://raw.github.com/abh1nay/voldemort/3f3c9a389d9693dab7dab00581c24ef339273ba
5/test/unit/voldemort/client/rebalance/RebalanceMetadataConsistencyTest.java

is the test file

Original comment by abhinayn...@gmail.com on 13 May 2013 at 8:15

GoogleCodeExporter commented 8 years ago
OK, thanks. I'll try and take a look tomorrow.

Original comment by alasdair.mackintosh on 14 May 2013 at 4:40

GoogleCodeExporter commented 8 years ago
This is caused by an error that we get when we try to invoke a native method 
inside the org.jdom. parser code. This causes SAXBuilder to silently swallow 
the error, and then try and use the DEFAULT_SAX_DRIVER instead.

The underlying problem is that we can't load classes containing native methods 
inside the ThreadWeaver test framework. We have a hardcoded list of various 
system and system-like classes that we don't load and instrument, and I've 
added "org.jdom" rto the list. See 
https://code.google.com/p/thread-weaver/source/detail?r=26

I'm not going to cut a new release yet as I want to fix things up a bit more, 
but if you download the source you should be able to build easily.

Note that your RebalanceMetadataConsistencyTest.java class has some problems. 
The static{} block needs to move into an instance method with the 
@ThreadedBefore annotation, and there are still some null pointer issues.

You have:

        rebalancer = new Rebalancer(null, metadataStore, null, null);
        ....
        metadataStore = new MetadataStore(innerStore, 0);

which means that the Rebalancer has a null input. The two ines need to be 
reversed, and even then I got some NPEs in the after() method.

Let me know if you have further issues with the test framework.

Original comment by alasdair.mackintosh on 15 May 2013 at 1:12

GoogleCodeExporter commented 8 years ago
Hi Alasdair,
thanks!
yes the tests has problems as I was trying to mock the class to get around the 
xml issue .. and well it messed up the test. I will write a new test to see if 
it works

best
abhinay

Original comment by abhinayn...@gmail.com on 15 May 2013 at 3:27

GoogleCodeExporter commented 8 years ago
I have released a new build which includes revision r26, which should fix this 
specific problem.

Original comment by alasdair.mackintosh on 8 Aug 2013 at 1:08

GoogleCodeExporter commented 8 years ago
I've hit this with version 0.2 which is the newest on Maven Central. Does that 
version have the fix? We're not using any native code.

Original comment by bimargul...@gmail.com on 16 May 2014 at 12:03

GoogleCodeExporter commented 8 years ago
The code that blows up for us is just:

XMLReader xr = XMLReaderFactory.createXMLReader();

No jdom, just good old sax.

Original comment by bimargul...@gmail.com on 16 May 2014 at 12:07

GoogleCodeExporter commented 8 years ago
Can you send me an example that reproduces this? Thanks.

Original comment by alasdair.mackintosh on 16 May 2014 at 5:10

GoogleCodeExporter commented 8 years ago
Closing, as I don't have a way to reproduce this. 

Original comment by alasdair.mackintosh on 4 Nov 2014 at 7:05