Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-16801: Set previous context class loader after loading plugin #1645

Merged
merged 5 commits into from
May 18, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 13 additions & 3 deletions solr/core/src/java/org/apache/solr/core/CoreContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,22 @@ private void registerV2ApiIfEnabled(Class<? extends JerseyResource> clazz) {
reason =
"Set the thread contextClassLoader for all 3rd party dependencies that we cannot control")
public void load() {
final ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
try {
// Set the thread's contextClassLoader for any plugins that are loaded via Modules or Packages
// and have dependencies that use the thread's contextClassLoader
Thread.currentThread().setContextClassLoader(loader.getClassLoader());
loadInternal();
Copy link

Choose a reason for hiding this comment

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

7% of developers fix this issue

THREAD_SAFETY_VIOLATION: Unprotected write. Non-private method CoreContainer.load() indirectly writes to field noggit.JSONParser.devNull.buf outside of synchronization.
Reporting because another access to the same memory occurs on a background thread, although this access may not.


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

} finally {
Thread.currentThread().setContextClassLoader(originalContextClassLoader);
}
}

/** Load the cores defined for this CoreContainer */
private void loadInternal() {
if (log.isDebugEnabled()) {
log.debug("Loading cores into CoreContainer [instanceDir={}]", getSolrHome());
}
// Set the thread's contextClassLoader for any plugins that are loaded via Modules or Packages
Thread.currentThread().setContextClassLoader(loader.getClassLoader());

logging = LogWatcher.newRegisteredLogWatcher(cfg.getLogWatcherConfig(), loader);

ClusterEventProducerFactory clusterEventProducerFactory = new ClusterEventProducerFactory(this);
Expand Down