jaxb
  1. jaxb
  2. JAXB-964

JAXB unmarshalling failing when whitespace is present around token enumerations

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Won't Fix
    • Affects Version/s: 2.2.7
    • Fix Version/s: None
    • Component/s: runtime, xjc
    • Labels:
      None
    • Environment:

      JDK 1.7.0_21, Ubuntu 12.04.2

      Description

      SO post on the subject: http://stackoverflow.com/questions/17114304/jaxb-unmarshalling-not-tolerating-whitespace-around-token-enumerations

      Here's the code that demonstrates the issue, for completeness purposes:

      A.xsd

      <xs:schema targetNamespace="foo://a"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns="foo://a">

      <xs:element name="type" type="Type"/>

      <xs:simpleType name="Type">
      <xs:restriction base="xs:token">
      <xs:enumeration value="Archive"/>
      <xs:enumeration value="Organisation"/>
      </xs:restriction>
      </xs:simpleType>

      </xs:schema>

      a.xml

      <a:type xmlns:a="foo://a" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="foo://a A.xsd"
      >Organisation </a:type>

      (notice the space after the 'Organisation')

      unmarshalling code that fails

      import java.io.*;
      import javax.xml.XMLConstants;
      import javax.xml.bind.*;
      import javax.xml.validation.Validator;
      import javax.xml.validation.SchemaFactory;
      import javax.xml.validation.Schema;

      import javax.xml.transform.Source;
      import javax.xml.transform.stream.StreamSource;

      import a.*;

      public class FooMain {

      public static void main(String args[]) throws Exception {
      SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
      JAXBContext payloadContext = JAXBContext.newInstance("a");
      Unmarshaller unmarshaller = payloadContext.createUnmarshaller();
      unmarshaller.setSchema(schemaFactory.newSchema(new Source[]

      {new StreamSource(new FileInputStream(new File("A.xsd")))}

      ));
      unmarshaller.setAdapter(new StringTrimAdapter());
      JAXBElement<?> oUnmarshalled = (JAXBElement<?>) unmarshaller.unmarshal(new File("a.xml"));
      Object o = oUnmarshalled.getValue();
      System.out.println("o==null? "+(o==null?"YES":"NO"));
      System.out.println("the type of object is: "+o.getClass().getName()); // NPE here
      }
      }

        Activity

        Hide
        laune added a comment -

        From XML Schema Part 2: Datatypes Second Edition, section 3.3.2, token:

        [Definition:] token represents tokenized strings. The ·value space· of token is the set of strings that do not contain the carriage return (#xD), line feed (#xA) nor tab (#x9) characters, that have no leading or trailing spaces (#x20) and that have no internal sequences of two or more spaces. The ·lexical space· of token is the set of strings that do not contain the carriage return (#xD), line feed (#xA) nor tab (#x9) characters, that have no leading or trailing spaces (#x20) and that have no internal sequences of two or more spaces.

        Show
        laune added a comment - From XML Schema Part 2: Datatypes Second Edition, section 3.3.2, token: [Definition:] token represents tokenized strings. The ·value space· of token is the set of strings that do not contain the carriage return (#xD), line feed (#xA) nor tab (#x9) characters, that have no leading or trailing spaces (#x20) and that have no internal sequences of two or more spaces. The ·lexical space· of token is the set of strings that do not contain the carriage return (#xD), line feed (#xA) nor tab (#x9) characters, that have no leading or trailing spaces (#x20) and that have no internal sequences of two or more spaces.
        Hide
        m_perdikeas added a comment -

        @laune: if I read you right, JAXB RI should then complain during validation. The current behavior is that it stays silent at validation and returns null when trying to get the token.

        Show
        m_perdikeas added a comment - @laune: if I read you right, JAXB RI should then complain during validation. The current behavior is that it stays silent at validation and returns null when trying to get the token.
        Hide
        Iaroslav Savytskyi added a comment -

        Hi,

        This is probably not a JAXB bug. JAXB relies on JAXP XML validation.

        What we can do - we can try to file an issue for JAXP and will see. Do you want me to do this OR you will do it by yourself?

        Thank you for reporting.


        Iaroslav.

        Show
        Iaroslav Savytskyi added a comment - Hi, This is probably not a JAXB bug. JAXB relies on JAXP XML validation. What we can do - we can try to file an issue for JAXP and will see. Do you want me to do this OR you will do it by yourself? Thank you for reporting. – Iaroslav.
        Hide
        m_perdikeas added a comment -

        @Iaroslav

        I wouldn't want to post the exact same code sample on JAXP bug tracker as it uses JAXB unmarshalling.

        I would rather you did it since you may be able to narrow it down further to only JAXP code to make it crystal clear the ball is on their side.

        Show
        m_perdikeas added a comment - @Iaroslav I wouldn't want to post the exact same code sample on JAXP bug tracker as it uses JAXB unmarshalling. I would rather you did it since you may be able to narrow it down further to only JAXP code to make it crystal clear the ball is on their side.
        Hide
        m_perdikeas added a comment -

        OK, so I reported it to JAXP as: https://java.net/jira/browse/JAXP-78

        Show
        m_perdikeas added a comment - OK, so I reported it to JAXP as: https://java.net/jira/browse/JAXP-78

          People

          • Assignee:
            Iaroslav Savytskyi
            Reporter:
            m_perdikeas
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: