Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4077,6 +4077,7 @@ private interface StatisticsAggregator<T> {
STATS_DATA_CLEANER.
setName(StatisticsDataReferenceCleaner.class.getName());
STATS_DATA_CLEANER.setDaemon(true);
STATS_DATA_CLEANER.setContextClassLoader(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the risks of setting this to null?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the thread relies on the return value of Thread.currentThread().getContextClassLoader() for logical processing, it may encounter NPE, but I checked the corresponding code. This risk should not exist. In fact, this is a normal way of handling classloader references in the daemon thread. You can refer https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-7008595

STATS_DATA_CLEANER.start();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

/**
* This tests basic operations of {@link FileSystemStorageStatistics} class.
Expand Down Expand Up @@ -102,6 +103,14 @@ public void testGetLong() {
}
}

@Test
public void testStatisticsDataReferenceCleanerClassLoader() {
Thread thread = Thread.getAllStackTraces().keySet().stream()
.filter(t -> t.getName().contains("StatisticsDataReferenceCleaner")).findFirst().get();
ClassLoader classLoader = thread.getContextClassLoader();
assertNull(classLoader);
}

/**
* Helper method to retrieve the specific FileSystem.Statistics value by name.
*
Expand Down