Permalink
Browse files

better handling of value from array when cleaning thread locals

  • Loading branch information...
1 parent f0007fd commit 7bac88383744af7b93302019d8a2e288a45fb776 @kimchy kimchy committed May 7, 2012
Showing with 5 additions and 4 deletions.
  1. +5 −4 src/main/java/org/elasticsearch/common/thread/ThreadLocals.java
@@ -98,14 +98,15 @@ private static void clearThreadLocalMap(Object map, Field internalTableField) th
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;
}

0 comments on commit 7bac883

Please sign in to comment.