Fixed null pointers when reading null properties in xml importer/exporter

pull/14/head
Sam Bosley 14 years ago
parent fec4c77af3
commit 61ddbcbeec

@ -218,10 +218,14 @@ public class TasksXmlExporter {
private final XmlWritingPropertyVisitor xmlWritingVisitor = new XmlWritingPropertyVisitor();
private class XmlWritingPropertyVisitor implements PropertyVisitor<Void, AbstractModel> {
private static final String NULL = "null"; //$NON-NLS-1$
@Override
public Void visitInteger(Property<Integer> property, AbstractModel data) {
try {
xml.attribute(null, property.name, data.getValue(property).toString());
Integer value = data.getValue(property);
String valueString = (value == null) ? NULL : value.toString();
xml.attribute(null, property.name, valueString);
} catch (UnsupportedOperationException e) {
// didn't read this value, do nothing
} catch (IllegalArgumentException e) {
@ -237,7 +241,9 @@ public class TasksXmlExporter {
@Override
public Void visitLong(Property<Long> property, AbstractModel data) {
try {
xml.attribute(null, property.name, data.getValue(property).toString());
Long value = data.getValue(property);
String valueString = (value == null) ? NULL : value.toString();
xml.attribute(null, property.name, valueString);
} catch (UnsupportedOperationException e) {
// didn't read this value, do nothing
} catch (IllegalArgumentException e) {
@ -253,7 +259,9 @@ public class TasksXmlExporter {
@Override
public Void visitDouble(Property<Double> property, AbstractModel data) {
try {
xml.attribute(null, property.name, data.getValue(property).toString());
Double value = data.getValue(property);
String valueString = (value == null) ? NULL : value.toString();
xml.attribute(null, property.name, valueString);
} catch (UnsupportedOperationException e) {
// didn't read this value, do nothing
} catch (IllegalArgumentException e) {

@ -296,12 +296,16 @@ public class TasksXmlImporter {
private final XmlReadingPropertyVisitor xmlReadingVisitor = new XmlReadingPropertyVisitor();
private class XmlReadingPropertyVisitor implements PropertyVisitor<Void, AbstractModel> {
private static final String NULL = "null"; //$NON-NLS-1$
@Override
public Void visitInteger(Property<Integer> property,
AbstractModel data) {
String value = xpp.getAttributeValue(null, property.name);
if(value != null)
data.setValue(property, Integer.parseInt(value));
data.setValue(property, NULL.equals(value) ?
null : Integer.parseInt(value));
return null;
}
@ -309,7 +313,8 @@ public class TasksXmlImporter {
public Void visitLong(Property<Long> property, AbstractModel data) {
String value = xpp.getAttributeValue(null, property.name);
if(value != null)
data.setValue(property, Long.parseLong(value));
data.setValue(property, NULL.equals(value) ?
null : Long.parseLong(value));
return null;
}
@ -318,7 +323,8 @@ public class TasksXmlImporter {
AbstractModel data) {
String value = xpp.getAttributeValue(null, property.name);
if(value != null)
data.setValue(property, Double.parseDouble(value));
data.setValue(property, NULL.equals(value) ?
null : Double.parseDouble(value));
return null;
}

Loading…
Cancel
Save