From b498d2cf84942bcb697928b0e6176c5a03d31dbc Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 6 Oct 2014 22:50:20 +0900 Subject: [PATCH] Fix a possible NPE in Dicttool I've never seen the NPE happen and only happened to notice this by chance. Let's fix the code. Change-Id: If458646229f9cadcd6c15779348133f382fde783 --- tools/dicttool/compat/android/util/Pair.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/dicttool/compat/android/util/Pair.java b/tools/dicttool/compat/android/util/Pair.java index 5bf34848d..ab6096ee3 100644 --- a/tools/dicttool/compat/android/util/Pair.java +++ b/tools/dicttool/compat/android/util/Pair.java @@ -17,6 +17,7 @@ package android.util; import java.util.Arrays; +import java.util.Objects; public class Pair { public final T1 mFirst; @@ -29,7 +30,8 @@ public class Pair { @Override public int hashCode() { - return Arrays.hashCode(new Object[] { mFirst, mSecond }); + return (mFirst == null ? 0 : mFirst.hashCode()) + ^ (mSecond == null ? 0 : mSecond.hashCode()); } @Override @@ -37,7 +39,6 @@ public class Pair { if (o == this) return true; if (!(o instanceof Pair)) return false; Pair p = (Pair)o; - return ((mFirst == null && p.mFirst == null) || mFirst.equals(p.mFirst)) - && ((mSecond == null && p.mSecond == null) || mSecond.equals(p.mSecond)); + return Objects.equals(mFirst, p.mFirst) && Objects.equals(mSecond, p.mSecond); } }