From 30bdca2a29b216eea3f05cbd331e2126b456ae32 Mon Sep 17 00:00:00 2001 From: "andreas.schildbach@gmail.com" Date: Thu, 16 Feb 2012 13:43:38 +0000 Subject: [PATCH] fixed NPE git-svn-id: https://public-transport-enabler.googlecode.com/svn/trunk@948 0924bc21-9374-b0fa-ee44-9ff1593b38f0 --- src/de/schildbach/pte/dto/Location.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/de/schildbach/pte/dto/Location.java b/src/de/schildbach/pte/dto/Location.java index 6ab3c299..62c979ea 100644 --- a/src/de/schildbach/pte/dto/Location.java +++ b/src/de/schildbach/pte/dto/Location.java @@ -123,9 +123,9 @@ public final class Location implements Serializable return false; if (this.id != other.id) return false; - if (this.id != 0) + if (this.id != 0) // TODO needed? return true; - return this.name.equals(other.name); + return nullSafeEquals(this.name, other.name); } @Override @@ -135,6 +135,24 @@ public final class Location implements Serializable hashCode += type.hashCode(); hashCode *= 29; hashCode += id; + hashCode *= 29; + hashCode += nullSafeHashCode(name); return hashCode; } + + private boolean nullSafeEquals(final Object o1, final Object o2) + { + if (o1 == null && o2 == null) + return true; + if (o1 != null && o1.equals(o2)) + return true; + return false; + } + + private int nullSafeHashCode(final Object o) + { + if (o == null) + return 0; + return o.hashCode(); + } }