From aa897730085d17e131768caf40f9b30f2aa7a0bc Mon Sep 17 00:00:00 2001 From: Joel Leitch Date: Tue, 7 Jun 2011 01:28:30 +0000 Subject: [PATCH] Quick fix for threading issue. Should maybe look into synchronizing this method instead. --- gson/src/main/java/com/google/gson/FieldAttributes.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gson/src/main/java/com/google/gson/FieldAttributes.java b/gson/src/main/java/com/google/gson/FieldAttributes.java index b69ebf92..0aa47511 100644 --- a/gson/src/main/java/com/google/gson/FieldAttributes.java +++ b/gson/src/main/java/com/google/gson/FieldAttributes.java @@ -159,12 +159,13 @@ public final class FieldAttributes { public Collection getAnnotations() { if (annotations == null) { Pair, String> key = new Pair, String>(declaringClazz, name); - annotations = ANNOTATION_CACHE.getElement(key); - if (annotations == null) { - annotations = Collections.unmodifiableCollection( + Collection cachedValue = ANNOTATION_CACHE.getElement(key); + if (cachedValue == null) { + cachedValue = Collections.unmodifiableCollection( Arrays.asList(field.getAnnotations())); - ANNOTATION_CACHE.addElement(key, annotations); + ANNOTATION_CACHE.addElement(key, cachedValue); } + annotations = cachedValue; } return annotations; }