XStream

TextAttributeConverter uses reflection to access non-portable instanceMap field.

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.2.2
  • Component/s: None
  • Labels:
    None
  • JDK version and platform:
    Apache Harmony on Debian

Description

TextAttributeConverter uses reflection to access non-portable instanceMap field which is not present on all VM's. Apache Harmony, specifically, does not have this field, leading to;

java.lang.InternalError: Missing TextAttribute.instanceMap
at com.thoughtworks.xstream.converters.extended.TextAttributeConverter.<clinit>(TextAttributeConverter.java:30)
at com.thoughtworks.xstream.XStream.setupConverters(XStream.java:583)
at com.thoughtworks.xstream.XStream.<init>(XStream.java:370)
at com.thoughtworks.xstream.XStream.<init>(XStream.java:316)

The source as shown at http://svn.codehaus.org/xstream/trunk/xstream/src/java/com/thoughtworks/xstream/converters/extended/TextAttributeConverter.java

contains this;

instanceMap = TextAttribute.class.getDeclaredField("instanceMap");

Can this class be changed to work on all VM's, not just Sun's RI?

Issue Links

Activity

Hide
Robert Newson added a comment -


fyi: Using "attrMap" works on Harmony.

Show
Robert Newson added a comment - fyi: Using "attrMap" works on Harmony.
Hide
Joerg Schaible added a comment -

Robert,

I solved the issue by a complete new implementation. Can you give the version in the repository a try? Should work now independent of the JDK.

  • Jörg
Show
Joerg Schaible added a comment - Robert, I solved the issue by a complete new implementation. Can you give the version in the repository a try? Should work now independent of the JDK.
  • Jörg
Hide
Robert Newson added a comment -

Running the tests in converter.extended now no longer complains about the innards of TextAttribute, however I now get this;

junit.framework.AssertionFailedError: Exception in constructor: testSupportsConstructor (com.thoughtworks.xstream.XStream$InitializationException: Could not instatiate converter : com.thoughtworks.xstream.converters.enums.EnumSetConverter : null
at com.thoughtworks.xstream.XStream.dynamicallyRegisterConverter(XStream.java:659)
at com.thoughtworks.xstream.XStream.setupConverters(XStream.java:630)
at com.thoughtworks.xstream.XStream.<init>(XStream.java:374)
at com.thoughtworks.xstream.XStream.<init>(XStream.java)
at com.thoughtworks.acceptance.AbstractAcceptanceTest.createXStream(AbstractAcceptanceTest.java:29)
at com.thoughtworks.acceptance.AbstractAcceptanceTest.<init>(AbstractAcceptanceTest.java:24)
at com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest.<init>(JavaMethodConverterTest.java)
at java.lang.reflect.VMReflection.newClassInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at junit.framework.TestSuite.createTest(TestSuite.java:131)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:113)
at junit.framework.TestSuite.<init>(TestSuite.java:75)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:58)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:385)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:195)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.VMReflection.newClassInstance(Native Method)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.thoughtworks.xstream.XStream.dynamicallyRegisterConverter(XStream.java:651)
at com.thoughtworks.xstream.XStream.setupConverters(XStream.java:630)
... 16 more
Caused by: java.lang.RuntimeException: Could not access java.util.EnumSet.elementType field
at com.thoughtworks.xstream.core.util.Fields.find(Fields.java:18)
at com.thoughtworks.xstream.converters.enums.EnumSetConverter.<init>(EnumSetConverter.java:31)
at java.lang.reflect.VMReflection.newClassInstance(Native Method)
... 19 more
)
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.TestSuite$1.runTest(TestSuite.java)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java)
at junit.framework.TestResult.runProtected(TestResult.java)
at junit.framework.TestResult.run(TestResult.java:104)
at junit.framework.TestCase.run(TestCase.java)
at junit.framework.TestSuite.runTest(TestSuite.java)
at junit.framework.TestSuite.run(TestSuite.java:202)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:126)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:385)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:195)

Show
Robert Newson added a comment - Running the tests in converter.extended now no longer complains about the innards of TextAttribute, however I now get this; junit.framework.AssertionFailedError: Exception in constructor: testSupportsConstructor (com.thoughtworks.xstream.XStream$InitializationException: Could not instatiate converter : com.thoughtworks.xstream.converters.enums.EnumSetConverter : null at com.thoughtworks.xstream.XStream.dynamicallyRegisterConverter(XStream.java:659) at com.thoughtworks.xstream.XStream.setupConverters(XStream.java:630) at com.thoughtworks.xstream.XStream.<init>(XStream.java:374) at com.thoughtworks.xstream.XStream.<init>(XStream.java) at com.thoughtworks.acceptance.AbstractAcceptanceTest.createXStream(AbstractAcceptanceTest.java:29) at com.thoughtworks.acceptance.AbstractAcceptanceTest.<init>(AbstractAcceptanceTest.java:24) at com.thoughtworks.xstream.converters.extended.JavaMethodConverterTest.<init>(JavaMethodConverterTest.java) at java.lang.reflect.VMReflection.newClassInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Unknown Source) at junit.framework.TestSuite.createTest(TestSuite.java:131) at junit.framework.TestSuite.addTestMethod(TestSuite.java:113) at junit.framework.TestSuite.<init>(TestSuite.java:75) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.getTest(JUnit3TestLoader.java:102) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestLoader.loadTests(JUnit3TestLoader.java:58) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:445) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:385) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:195) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.VMReflection.newClassInstance(Native Method) at java.lang.reflect.Constructor.newInstance(Unknown Source) at com.thoughtworks.xstream.XStream.dynamicallyRegisterConverter(XStream.java:651) at com.thoughtworks.xstream.XStream.setupConverters(XStream.java:630) ... 16 more Caused by: java.lang.RuntimeException: Could not access java.util.EnumSet.elementType field at com.thoughtworks.xstream.core.util.Fields.find(Fields.java:18) at com.thoughtworks.xstream.converters.enums.EnumSetConverter.<init>(EnumSetConverter.java:31) at java.lang.reflect.VMReflection.newClassInstance(Native Method) ... 19 more ) at junit.framework.Assert.fail(Assert.java:47) at junit.framework.TestSuite$1.runTest(TestSuite.java) at junit.framework.TestCase.runBare(TestCase.java:125) at junit.framework.TestResult$1.protect(TestResult.java) at junit.framework.TestResult.runProtected(TestResult.java) at junit.framework.TestResult.run(TestResult.java:104) at junit.framework.TestCase.run(TestCase.java) at junit.framework.TestSuite.runTest(TestSuite.java) at junit.framework.TestSuite.run(TestSuite.java:202) at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:126) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:385) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:195)
Hide
Joerg Schaible added a comment -

This simply means that there is another converter (EnumSetConverter) that relies on some internals that do not apply to Harmony. Can you open a new issue for this please?

Show
Joerg Schaible added a comment - This simply means that there is another converter (EnumSetConverter) that relies on some internals that do not apply to Harmony. Can you open a new issue for this please?
Hide
Robert Newson added a comment -


I think you're right, I've logged XSTR-379 to track the EnumSetConverter bug.

Show
Robert Newson added a comment - I think you're right, I've logged XSTR-379 to track the EnumSetConverter bug.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: