Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 330679

Summary: NPE with byte[] and @XmlValue
Product: z_Archived Reporter: Blaise Doughan <blaise.doughan>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: denise.mahar
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Attachments:
Description Flags
Proposed changes and test none

Description Blaise Doughan CLA 2010-11-19 11:28:27 EST
When I use the following class:

import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlValue;

@XmlRootElement
public class Foo {

    private byte[] bytes;

    @XmlValue
    //@XmlSchemaType(name = "hexBinary")
    public byte[] getBytes() {
        return bytes;
    }

    public void setBytes(byte[] bytes) {
        this.bytes = bytes;
    }

}

With the following demo code:

import javax.xml.bind.JAXBContext;
import javax.xml.bind.Unmarshaller;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.dom.DOMSource;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class Demo {

    public static void main(String[] args) throws Exception {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        Document document = db.newDocument();
        Element element = document.createElement("foo"); element.setTextContent("YTM0NZomIzI2OTsmIzM0NTueYQ==");

        JAXBContext jc = JAXBContext.newInstance(Foo.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        Foo foo = (Foo) unmarshaller.unmarshal(new DOMSource(element));
        System.out.println(foo.getBytes().length);
        jc.createMarshaller().marshal(foo, System.out);
    }
}

I get the following Exception:

Exception in thread "main" java.lang.NullPointerException
	at forum97.Demo.main(Demo.java:23)


Meaning somehow the byte[] is not being populated.
Comment 1 Denise Smith CLA 2011-04-06 10:54:10 EDT
Created attachment 192648 [details]
Proposed changes and test
Comment 2 Denise Smith CLA 2011-04-12 09:22:28 EDT
April 6th - Checked in changed to MappingsGenerator to create the appropriate mapping (xpath '.' instead of text())
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:28:17 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink