This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 252098 - Incorrect context classloader in threads created by RequestProcessor
Summary: Incorrect context classloader in threads created by RequestProcessor
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 8.1
Hardware: All All
: P3 normal (vote)
Assignee: Tomas Hurka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-04-26 16:12 UTC by Tomas Hurka
Modified: 2015-04-28 02:58 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
init RequestProcessor$TickTac (15.32 KB, image/png)
2015-04-26 16:12 UTC, Tomas Hurka
Details
init RequestProcessor$Processor (12.53 KB, image/png)
2015-04-26 16:13 UTC, Tomas Hurka
Details
Proposed patch (1.90 KB, patch)
2015-04-26 16:52 UTC, Tomas Hurka
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tomas Hurka 2015-04-26 16:12:23 UTC
Created attachment 153395 [details]
init RequestProcessor$TickTac

[From email communication with Ron van Grinsven]:

The thread in the screenshot below (JboDatabaseCanaryRule) is exclusively constructed to ping the database. It needs its own context classloader, so the JDBC drivers and other db related code can run with the relevant classes available. One of the calls made is shown in the screenshot, which apparently ends up using the RequestProcessor to get a socket connection.
This creates a RequestProcessor$TickTac thread, which inherits the context loader from its parent, which is explicitly the URLClassLoader.

Subsequently, a RequestProcessor$Processor gets created, which is also getting the context loader from the original thread (so also the URLClassLoader).

Now, I'm speculating that the Processor thread is later re-used for other work. I don't know what the pool size is but there seem to be 3 or so of these threads available. Typically, these threads are spawned from other threads that have the ContextFinder.
If the indexer process gets assigned to a thread with ContextFinder, then everything works as planned. But if it ends up with the Processor that has the URLClassLoader, then the bug occurs.
Comment 1 Tomas Hurka 2015-04-26 16:13:08 UTC
Created attachment 153396 [details]
init RequestProcessor$Processor
Comment 2 Tomas Hurka 2015-04-26 16:17:22 UTC
[From email communication with Ron van Grinsven]:

I (thurka) discussed the problem with Tomas Pavek (tpavek) and there are several possible solutions. 

One is to get rid of NBProxySelector - according to Tomas it is not used in JDeveloper. This could be problem due to dependencies in NetBeans code and there could be another cases, where RequestProcessor threads are created from code, which has custom context classloader.

Second solution is to avoid RequestProcessor usage from NBProxySelector. This could be easier than first solution, but still there can be other cases, where threads are created with custom context classloader.

Third solution is to remember context classloader of calling thread and set it to thread created or reused by RequestProcessor

Fourth solution is similar to third one, but  context classloader will be some externally defined classloader.

If we need to fix it, we think that the third solution is the right one. Hopefully that this solution will not have some unwanted side effects.
Comment 3 Tomas Hurka 2015-04-26 16:52:36 UTC
Created attachment 153397 [details]
Proposed patch

Patch to implement proposed (third one) solution.
Comment 4 Tomas Hurka 2015-04-27 17:08:54 UTC
Fixed in core-main.

changeset:   287259:b3691ba57054
user:        Tomas Hurka <thurka@netbeans.org>
date:        Mon Apr 27 13:02:13 2015 +0200
summary:     bugfix #252098, remember context classloader of calling thread and set it to thread created or reused by RequestProcessor
Comment 5 Quality Engineering 2015-04-28 02:58:16 UTC
Integrated into 'main-silver', will be available in build *201504280001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/b3691ba57054
User: Tomas Hurka <thurka@netbeans.org>
Log: bugfix #252098, remember context classloader of calling thread and set it to thread created or reused by RequestProcessor