Topic
  • 4 replies
  • Latest Post - ‏2011-01-05T16:58:10Z by NickNewman
NickNewman
NickNewman
3 Posts

Pinned topic Bug in XML serialization of enumerations

‏2010-11-17T21:02:11Z |
Hi,

In the latest IBM JVM (6.0-8.1) enumerations are not serialized to XML correctly. This was a known issue in Sun's JVM but has been fixed. See:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5015403

This is the output from java -version:

java version "1.6.0"
Java(TM) SE Runtime Environment (build pxi3260sr8fp1-20100624_01(SR8 FP1))
IBM J9 VM (build 2.4, JRE 1.6.0 IBM J9 2.4 Linux x86-32 jvmxi3260sr8ifx-20100609_59383 (JIT enabled, AOT enabled)
J9VM - 20100609_059383
JIT - r9_20100401_15339ifx2
GC - 20100308_AA)
JCL - 20100624_01
Here is code to demonstrate the problem.

import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;

public class XMLSerializeEnumTest {

public static enum Animal { Dog, Cat, Bear; }

public static class Bean {
private Animal animal;
public Animal getAnimal() { return animal; }
public void setAnimal(Animal animal) { this.animal = animal; }
}

public static void main(String[] args) {
Bean bean = new Bean();
bean.setAnimal(Animal.Cat);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
XMLEncoder xmlEncoder = new XMLEncoder(baos);
xmlEncoder.writeObject(bean);
xmlEncoder.close();
System.out.println(new String(baos.toByteArray()));
}
}
Here is the expected output:
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0_05" class="java.beans.XMLDecoder">
<object class="test.XMLSerializeEnumTest$Bean">
<void property="animal">
<object class="test.XMLSerializeEnumTest$Animal" method="valueOf">
<string>Cat</string>
</object>
</void>
</object>
</java>
And here is the output when using the IBM JVM:

Exception during encoding:java.lang.Exception: failed to write expression: XMLSerializeEnumTest$Animal=Class.new();
Continue...
Exception during encoding:java.lang.Exception: failed to write expression: XMLSerializeEnumTest$Animal=Class.new();
Continue...
<?xml version="1.0" encoding="UTF-8"?>
<java version="1.6.0" class="java.beans.XMLDecoder">
<object class="XMLSerializeEnumTest$Bean"/>
</java>
I haven't been able to find any reference that this is a known bug, so I thought I'd mention it here. If there is some other place I should submit it to please let me know.

Many thanks,
Nick
Updated on 2011-01-05T16:58:10Z at 2011-01-05T16:58:10Z by NickNewman
  • NickNewman
    NickNewman
    3 Posts

    Re: Bug in XML serialization of enumerations

    ‏2010-12-02T20:20:05Z  
    Hmmm. No reply after a couple of weeks.

    I would have thought a clear bug (and one that's probably relatively simple to address) would have got SOME response.

    Maybe I'm posting in the wrong place? Any feedback would be appreciated.

    Thanks,
    Nick
  • SystemAdmin
    SystemAdmin
    2736 Posts

    Re: Bug in XML serialization of enumerations

    ‏2010-12-17T06:42:03Z  
    We use exactly the same RAD version and have a serious problem with JFormDesigner (http://www.formdev.com) that bases on XML serialization.
    At the moment this is a reason, why we are not able to roll out the new RAD8 installation.
  • SystemAdmin
    SystemAdmin
    2736 Posts

    Re: Bug in XML serialization of enumerations

    ‏2011-01-05T07:52:42Z  
    We use exactly the same RAD version and have a serious problem with JFormDesigner (http://www.formdev.com) that bases on XML serialization.
    At the moment this is a reason, why we are not able to roll out the new RAD8 installation.
    We have opened a PMR.
    IBM replied, that in the JRE (Version 1.6 SR9) for Linux the bug should be fixed.
    Since we use Windows, we will have to wait...
  • NickNewman
    NickNewman
    3 Posts

    Re: Bug in XML serialization of enumerations

    ‏2011-01-05T16:58:10Z  
    We have opened a PMR.
    IBM replied, that in the JRE (Version 1.6 SR9) for Linux the bug should be fixed.
    Since we use Windows, we will have to wait...
    Assuming that a PMR is an official bug report, thank you! I'm sorry that as a Windows user you will not benefit immediately yourself :-(

    Nick