Speaking of best practices to handle "nulls" in Java(especially "List" returns), is it a good practise to return "Collections.emptyList()" from an entity class's getMethod? or should we keep the entity/data classes/methods neat and clean and always return whatever its value is(even its null) then handle that null somewhere else in the code, for example;
Class Reference{
private Reference reference;
@XmlElement(name = "Reference")
public List<Reference> getReference() {
if(reference==null){
return Collections.emptyList();
}
return reference;
}
public void setReference(List<Reference> reference) {
this.reference = reference;
}
}
Or better to handle that null "after" I use a basic get method?
EDIT/WARNING: just for my scenario I noticed this approach crashs my code I dont why, when I later call;
References ref= (References) jaxbUnmarshaller.unmarshal(xmlReader)
I get an unsupported operation exception, but works ok when I clean my getMethod from collections.emtpyList. So caution when using with a @XmlElement tag