Relates :
|
|
Relates :
|
|
Relates :
|
Classes in the Java DTrace API that encode/decode successfully in Java 5 no longer encode/decode successfully in Java 6 (using XMLEncoder and XMLDecoder). To demonstrate the behavior on Java 5: ; su root ... ; rm /usr/java ; ln -s /usr/jdk/jdk1.5.0_08 /usr/java ; java -version java version "1.5.0_08" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03) Java HotSpot(TM) Server VM (build 1.5.0_08-b03, mixed mode) Then compile and run the attached TestBean.java in another window as non-root: ; javac TestBean.java ; java TestBean out serialized: TestBean[id = 1, list = [1, 2, 3]] deserialized: TestBean[id = 1, list = [1, 2, 3]] XML-encoded: TestBean[id = 1, list = [1, 2, 3]] XML-decoded: TestBean[id = 1, list = [1, 2, 3]] ; The above test writes a TestBean with id 1 and list of integers (1,2,3) to a file named "out" then reads it back in using object serialization first then XML encoding. The output above represents a successful test result. To demonstrate the failure on Java 6: ; rm /usr/java ; ln -s /usr/jdk/jdk1.6.0 /usr/java ; java -version java version "1.6.0-rc" Java(TM) SE Runtime Environment (build 1.6.0-rc-b100) Java HotSpot(TM) Server VM (build 1.6.0-rc-b100, mixed mode) Then re-compile and re-run the attached TestBean.java in another window as non-root: ; javac TestBean.java ; java TestBean out serialized: TestBean[id = 1, list = [1, 2, 3]] deserialized: TestBean[id = 1, list = [1, 2, 3]] XML-encoded: TestBean[id = 1, list = [1, 2, 3]] java.lang.NoSuchMethodException: TestBean.getId Continuing ... java.lang.InstantiationException: java.util.Collections$UnmodifiableRandomAccessList Continuing ... java.lang.Exception: XMLEncoder: discarding statement XMLEncoder.writeObject(TestBean); Continuing ... Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at com.sun.beans.ObjectHandler.dequeueResult(ObjectHandler.java:139) at java.beans.XMLDecoder.readObject(XMLDecoder.java:201) at TestBean.performBeanTest(TestBean.java:203) at TestBean.main(TestBean.java:243) In Java 6, the "id" property no longer maps to the public getID() method: BeanInfo info = Introspector.getBeanInfo(TestBean.class); PersistenceDelegate persistenceDelegate = new DefaultPersistenceDelegate( new String[] {"id", "list"}); ... public int getID() { return id; } This problem is fixed by changing the spelling of the "id" property to "iD": PersistenceDelegate persistenceDelegate = new DefaultPersistenceDelegate( new String[] {"iD", "list"}); Still, this is inconsistent with the behavior of Java 5 and breaks existing classes in the Java DTrace library (source in ON gate: http://onnv/): /usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/Aggregation.java /usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/ProbeDescription.java Since the TestBean class is immutable, the getList() method returns an immutable view of its internal list member: public List <Integer> getList() { return Collections. <Integer> unmodifiableList(list); } In Java 5, the list property returned by this method is successfully encoded and decoded using XMLEncoder and XMLDecoder, but not in Java 6. This breaks another existing class in the Java DTrace API: /usr/src/lib/libdtrace_jni/java/src/org/opensolaris/os/dtrace/PrintfRecord.java
|