Skip to content

Commit f0c151a

Browse files
committed
Fix NullPointerException in ThreadLocalCleaner.
1 parent 51a95c0 commit f0c151a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

gwtmockito/src/main/java/com/google/gwtmockito/ThreadLocalCleaner.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ public static void cleanUpThreadLocalValues(ClassLoader classLoader) {
2626
if (mapEntry != null && mapEntry.get() != null) {
2727
ClassLoader mapEntryKeyClassLoader = mapEntry.get().getClass().getClassLoader();
2828
Field mapEntryValueField = getPrivateAttributeAccessibleField(mapEntry.getClass(), "value");
29-
ClassLoader mapEntryValueClassLoader = mapEntryValueField.get(mapEntry).getClass().getClassLoader();
30-
if (mapEntryKeyClassLoader == classLoader || mapEntryValueClassLoader == classLoader) {
31-
mapEntry.clear();
32-
mapEntryValueField.set(mapEntry, null);
33-
// The ThreadLocalMap is able to expunge the remaining stale entries, no need to remove it from the map
29+
Object value = mapEntryValueField.get(mapEntry);
30+
if (value != null) {
31+
ClassLoader mapEntryValueClassLoader = value.getClass().getClassLoader();
32+
if (mapEntryKeyClassLoader == classLoader || mapEntryValueClassLoader == classLoader) {
33+
mapEntry.clear();
34+
mapEntryValueField.set(mapEntry, null);
35+
// The ThreadLocalMap is able to expunge the remaining stale entries, no need to remove it from the map
36+
}
3437
}
3538
}
3639
}

0 commit comments

Comments
 (0)