First of all: Very good work on this library, I love it, as it makes working with XML in Java really easy :)
The bug: when setting an element to "required=false" and trying to deserialize an empty value in the XML:
Detailed StackTrace: http://pastebin.com/m6b3bba48
To reproduce:
example class:
@Root
public class MessageWrapper {
@Element(required=false)
private String message;
// getters & setters omitted
// ...
}
try to deserialize this example XML:
<MessageWrapper>
<message/>
</MessageWrapper>
----------------------
Bugfix: (see attachment for project relative patch)
----------------------
file: org.simpleframework.xml.core.Composite.java
line number: 573
reason: source is null
fix: move lines 571 and 573 into the if statement.
source snippet after fix (lines 566-582):
private Object read(InputNode node, Object source, Label label) throws Exception {
Object object = readObject(node, source, label);
if(object == null) {
if(label.isRequired() && revision.isEqual()) {
Position line = node.getPosition();
Class type = source.getClass();
throw new ValueRequiredException("Empty value for %s in %s at %s", label, type, line);
}
} else {
if(object != label.getEmpty(context)) {
criteria.set(label, object);
}
}
return object;
}
project relative patch (stream) for the nullpointer exception
Updated test case to reproduce null pointer
Error narrowed down to case with constructor injection. (see attached jar for JUnit4 test case to reproduce)