Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DynamicType with collection property not initializing as empty collection #2255

Closed
timtatt opened this issue Sep 5, 2024 · 1 comment · Fixed by #2256
Closed

DynamicType with collection property not initializing as empty collection #2255

timtatt opened this issue Sep 5, 2024 · 1 comment · Fixed by #2256

Comments

@timtatt
Copy link
Contributor

timtatt commented Sep 5, 2024

Describe the bug
DynamicEntity created from a DynamicType do not initialise collection properties with an empty list. Because the collections are not initialised, all XPath actions on these properties will result in NullPointerExceptions.

To Reproduce
Steps/resources to reproduce the behavior:

Below is a simple test case to replicate the issue.

InputStream schemaStream = ClassLoader.getSystemResourceAsStream("single.xsd");
jaxbContext = DynamicJAXBContextFactory.createContextFromXSD(schemaStream, null, null, null);

var customer = jaxbContext.newDynamicEntity("Customer");

assertNotNull(customer.get("phoneNumbers")); // currently this is null

var resolver = new NamespaceResolver();
resolver.setDefaultNamespaceURI("www.example.org/customer");

/*
currently throws a NullPointerException
java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "collection" is null

	at org.eclipse.persistence.core/org.eclipse.persistence.internal.oxm.Context.getValueByXPath(Context.java:551)
	at org.eclipse.persistence.core/org.eclipse.persistence.internal.oxm.Context.getValueByXPath(Context.java:528)
	at org.eclipse.persistence.core/org.eclipse.persistence.oxm.XMLContext.getValueByXPath(XMLContext.java:573)
	at org.eclipse.persistence.moxy/org.eclipse.persistence.jaxb.JAXBContext.getValueByXPath(JAXBContext.java:654)
*/
var phoneNumbers = jaxbContext.getValueByXPath(customer, "phone-numbers", resolver, Object.class);

assertNotNull(phoneNumbers);
assertEquals(ArrayList.class, phoneNumbers.getClass());

single.xsd

<xsd:schema
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns="www.example.org/customer"
   targetNamespace="www.example.org/customer"
   elementFormDefault="qualified">

   <xsd:complexType name="phone-number">
      <xsd:simpleContent>
         <xsd:extension base="xsd:string">
            <xsd:attribute name="type" type="xsd:string"/>
         </xsd:extension>
      </xsd:simpleContent>
   </xsd:complexType>

   <xsd:complexType name="customer">
      <xsd:sequence>
         <xsd:element name="phone-numbers" type="phone-number" minOccurs="0" maxOccurs="unbounded"/>
      </xsd:sequence>
   </xsd:complexType>

   <xsd:element name="customer" type="customer"/>

</xsd:schema>
  • EclipseLink version 4.0.4
  • Java/JDK version 17.0.11
  • Entity source (mainly applied annotations)

Expected behavior
Similar to how the static JAXB classes behave, new entities should be created with collection properties initialised with an empty collection.

@lukasj
Copy link
Member

lukasj commented Oct 9, 2024

fixed by #2256

@lukasj lukasj closed this as completed Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants