From 7bac88383744af7b93302019d8a2e288a45fb776 Mon Sep 17 00:00:00 2001 From: Shay Banon Date: Mon, 7 May 2012 16:54:32 +0300 Subject: [PATCH] better handling of value from array when cleaning thread locals --- .../org/elasticsearch/common/thread/ThreadLocals.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/elasticsearch/common/thread/ThreadLocals.java b/src/main/java/org/elasticsearch/common/thread/ThreadLocals.java index 73f79297f89..e0dd365a81e 100644 --- a/src/main/java/org/elasticsearch/common/thread/ThreadLocals.java +++ b/src/main/java/org/elasticsearch/common/thread/ThreadLocals.java @@ -98,14 +98,15 @@ public class ThreadLocals { int staleEntriesCount = 0; if (table != null) { for (int j = 0; j < table.length; j++) { - if (table[j] != null) { + Object tableValue = table[j]; + if (tableValue != null) { boolean remove = false; // Check the key - Object key = ((Reference) table[j]).get(); + Object key = ((Reference) tableValue).get(); // Check the value - Field valueField = table[j].getClass().getDeclaredField("value"); + Field valueField = tableValue.getClass().getDeclaredField("value"); valueField.setAccessible(true); - Object value = valueField.get(table[j]); + Object value = valueField.get(tableValue); if ((value != null && CleanableValue.class.isAssignableFrom(value.getClass()))) { remove = true; }