users@jaxb.java.net

JAXB differences in JDK 7 for Lists

From: Mukundha Madhavan <mukundha.madhavan_at_gmail.com>
Date: Mon, 18 Feb 2013 20:32:15 +0530

Hello Folks,

We are migrating our project to JDK7, we ran into an issue with JAXB in
JDK7.

The issue is for the sample class below,

@XmlRootElement(name="a")
public class TestBean {
    private List<String> b ;
        @XmlElement(name="b")
    public List<String> getB(){
        return b ;
    }
    public void setB(List<String> b){
        this.b = b ;
    }
}

Order of method invocation in JDK 6 was
1. getB() - b was null
2. setB() - b was empty

But the Order of method invocation in JDK 7 is,
1. getB() - b was null
2. setB() - b was empty
3. setB() - (this.b==b) is true and b is my list full of elements

We are running into an issue because of this behavior.

With debug in JDK 6 and JDK 7 i guess, we found the code causing this
changed behavior.

refer to endPackaging method on CollectionLister,

this is the JDK 6 source code,
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/6-b14/com/sun/xml/internal/bind/v2/runtime/reflect/Lister.java#Lister.CollectionLister.endPacking%28java.util.Collection%2Cjava.lang.Object%2Ccom.sun.xml.internal.bind.v2.runtime.reflect.Accessor%29

this is the JDK 7 source code,
http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/com/sun/xml/internal/bind/v2/runtime/reflect/Lister.java#Lister.CollectionLister.startPacking%28java.lang.Object%2Ccom.sun.xml.internal.bind.v2.runtime.reflect.Accessor%29

Can someone pls explain me why this is changed? I do not understand why
bean is called with the setter with the same reference?

Thanks for your help! Let me know if you need any additional information

Cheers!
Mukundha