Bug 1127318 - [GSS] (6.4) JAXB Unmarshaller sets the incorrect element as nil
Summary: [GSS] (6.4) JAXB Unmarshaller sets the incorrect element as nil
Alias: None
Product: JBoss Enterprise Application Platform 6
Classification: JBoss
Component: XML Frameworks
Version: 6.3.0
Hardware: Unspecified
OS: Unspecified
Target Milestone: DR1
: EAP 6.4.0
Assignee: Jason T. Greene
QA Contact: Pavel Slavicek
Depends On:
Blocks: 1127326 1127320 1127946
TreeView+ depends on / blocked
Reported: 2014-08-06 15:59 UTC by Kyle Lape
Modified: 2018-12-06 17:37 UTC (History)
2 users (show)

Doc Type: Bug Fix
Doc Text:
Clone Of:
: 1127320 (view as bug list)
Last Closed:
Type: Bug

Attachments (Terms of Use)

Description Kyle Lape 2014-08-06 15:59:38 UTC
Upstream Jira link: https://java.net/jira/browse/JAXB-1028

Given the following schema: 

<xs:schema xmlns:tns="http://jaxb.gss.redhat.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://jaxb.gss.redhat.com/">
  <xs:element name="team" type="tns:team"/>
  <xs:complexType name="team">
      <xs:element ref="tns:abstractName"/>
      <xs:element ref="tns:member"/>
  <xs:element abstract="true"  name="abstractName" nillable="false"/>
  <xs:element abstract="false" name="name"         nillable="true" substitutionGroup="tns:abstractName" type="xs:string"/>
  <xs:element abstract="true"  name="member"       nillable="false"/>
  <xs:element abstract="false" name="programmer"   nillable="true" substitutionGroup="tns:member" type="xs:string"/>

And the following XML:

<team xmlns="http://jaxb.gss.redhat.com/">
  <name xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

A JAXB unmarshaller will mark the <programmer> element as nil, yet still have the value of "Kyle" associated with the JAXBElement.

Code to test:

package com.redhat.gss.jaxb;

import java.net.URL;
import javax.xml.bind.Unmarshaller;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;

public class Test {
  private static JAXBContext ctx = null;

  public static void main(String[] args) throws Exception {
    ctx = JAXBContext.newInstance(ObjectFactory.class, Team.class, String.class);
    URL inputUrl = Test.class.getResource("/no-nil.xml");
    System.out.println("Non-nil test.");
    System.out.println("\nNil test.  Member should NOT be nil");
    inputUrl = Test.class.getResource("/nil.xml");

  public static void doTest(URL inputUrl) throws Exception {
    Unmarshaller unm = ctx.createUnmarshaller();
    Object o = unm.unmarshal(inputUrl);
    Team team = ((JAXBElement<Team>)o).getValue();
    System.out.println("Name: " + team.getAbstractName().getValue());
    System.out.println("Name nil? " + (team.getAbstractName().isNil() ? "YES" : "NO"));
    System.out.println("Member: " + team.getMember().getValue());
    System.out.println("Member nil? " + (team.getMember().isNil() ? "YES" : "NO"));

Comment 1 Kabir Khan 2014-08-23 10:30:24 UTC
Should be fixed by jaxb upgrade to 2.2.5-redhat-9: https://bugzilla.redhat.com/show_bug.cgi?id=1127326

Comment 2 Jan Blizňák 2014-09-18 10:19:40 UTC
Verified on 6.4.0.DR1

Note You need to log in before you can comment on or make changes to this bug.