From 6347e9b9c60b01eb397823d546b29f13c817e0b1 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Fri, 12 Apr 2013 21:10:21 +0000 Subject: [PATCH] ensuring that LinkedHashTreeMap.contains() returns false when non-Comparable() keys are passed to it --- .../java/com/google/gson/internal/LinkedHashTreeMap.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/LinkedHashTreeMap.java b/gson/src/main/java/com/google/gson/internal/LinkedHashTreeMap.java index 44270fc8..bb30bbac 100644 --- a/gson/src/main/java/com/google/gson/internal/LinkedHashTreeMap.java +++ b/gson/src/main/java/com/google/gson/internal/LinkedHashTreeMap.java @@ -196,9 +196,13 @@ public final class LinkedHashTreeMap extends AbstractMap implements return created; } - @SuppressWarnings("unchecked") // this method throws ClassCastExceptions! + @SuppressWarnings("unchecked") Node findByObject(Object key) { - return key != null ? find((K) key, false) : null; + try { + return key != null ? find((K) key, false) : null; + } catch (ClassCastException e) { + return null; + } } /**