castor-data-binding / castor

http://castor-data-binding.github.io/castor/
35 stars 29 forks source link

java.lang.NullPointerException #82

Closed RushikeshChavan96 closed 4 months ago

RushikeshChavan96 commented 4 years ago

Hi Team, Getting below issue:

Input:

inheritedAttributes: [XMLFieldDesciptor: maxExecuteTimeInMillis AS max-execute-time-in-millis]

allAttributes- [XMLFieldDesciptor: pooled AS pooled, XMLFieldDesciptor: separateThread AS separate-thread, XMLFieldDesciptor: delayPeriod AS delay-period, XMLFieldDesciptor: maxExecuteTimeInMillis AS max-execute-time-in-millis, XMLFieldDesciptor: maxExecuteTimeInMillis AS max-execute-time-in-millis]

Object XMLFieldDesciptor: maxExecuteTimeInMillis AS max-execute-time-in-millis is added twice in allAttributes but in inheritedAttributes it gets calculated as 1.

Code which had issue: // -- get local attribute descriptors by filtering out inherited ones XMLFieldDescriptor[] inheritedAttributes = _extends.getAttributeDescriptors(); XMLFieldDescriptor[] allAttributes = localAttributes; localAttributes = new XMLFieldDescriptor[allAttributes.length - inheritedAttributes.length]; 4 localIdx = 0; for (int i = 0; i < allAttributes.length; i++) { XMLFieldDescriptor desc = allAttributes[i]; boolean isInherited = false; for (int idx = 0; idx < inheritedAttributes.length; idx++) { if (inheritedAttributes[idx].equals(desc)) { isInherited = true; break; } } if (!isInherited) {

  localAttributes[localIdx] = desc;
  ++localIdx;
}

}

Exception on line:

java.lang.NullPointerException at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:1070) at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:910) at org.exolab.castor.xml.util.XMLClassDescriptorImpl.validate(XMLClassDescriptorImpl.java:910) at org.exolab.castor.xml.Validator.validate(Validator.java:135) at org.exolab.castor.xml.UnmarshalHandler.endElement(UnmarshalHandler.java:915) at org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.java:250) at org.exolab.castor.xml.util.DOMEventProducer.process(DOMEventProducer.java:183) at org.exolab.castor.xml.util.DOMEventProducer.start(DOMEventProducer.java:111) at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:637) at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:747) at org.exolab.castor.xml.Unmarshaller.unmarshal(Unmarshaller.java:877)

Please look into it.

RushikeshChavan96 commented 4 years ago

XMLClassDescriptorImpl.zip

Kindly find the fix in the attached file.