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 43603 - Bad context classloader in RP threads
Summary: Bad context classloader in RP threads
Status: CLOSED WONTFIX
Alias: None
Product: platform
Classification: Unclassified
Component: -- Other -- (show other bugs)
Version: 4.x
Hardware: All All
: P1 blocker (vote)
Assignee: Jesse Glick
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-20 10:59 UTC by Maros Sandor
Modified: 2008-12-22 20:40 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maros Sandor 2004-05-20 10:59:54 UTC
Debugger uses RequestProcessor.getDefault().post
(Runnable) in JPDAStart ANT task to start 
debugging sessions. When executing the Runnable 
object in a RP thread, the context classloader is 
sometimes set to 
org.apache.tools.ant.module.bridge.AntBridge$AllPe
rmissionURLClassLoader. Since the code runs in a 
RP thread, we expect it to be a NB system 
classloader. This issue prevents resourse 
lookups, etc.
Comment 1 Jan Chalupa 2004-05-21 10:52:07 UTC
Please note that issue #41280 is a Q-build stopper. If the analysis is
correct, this needs to be resolved asap.
Comment 2 _ ttran 2004-05-21 11:04:08 UTC
understood, but Jesse is probably packing his luggage or even already
on his way to the airport and Nejedly is on vacation.  I can't
guarantee they can look at this before next Monday
Comment 3 Jesse Glick 2004-05-21 16:41:17 UTC
Well, the Ant module is correctly setting the context class loader to
be Ant's loader for all Ant tasks. This is required for many Ant tasks
to behave correctly.

What calls you make within the Ant task is irrelevant; if you are
running inside the thread group that corresponds to the Ant run, that
is what the context loader will be. AFAIK there is no documented
contract that RequestProcessor must run tasks in any particular thread
or thread group. It *could* create new threads in the system thread
group, regardless of the caller's location, but I think this would be
undesirable in general; for one thing, it would prevent the execution
engine from reliably knowing when a task using RP had fully completed.
RequestLevel.Processor does call super with getTopLevelThreadGroup
(apparently this is not working) but I don't what the original
justification for this was, and I tend to disagree with it.

If you temporarily need a different context class loader for whatever
reason, set one yourself, and be sure to reset it in a finally block:

ClassLoader desiredCCL = ...;
Thread t = Thread.currentThread();
ClassLoader origCCL = t.getContextClassLoader();
t.setContextClassLoader(desiredCCL);
try {
    // whatever you need to do
} finally {
    t.setContextClassLoader(origCCL);
}

Anyway you should avoid relying on the context class loader in most
cases. For "resource lookup" (details??), please use
Class.getResource(String) or NbBundle variants taking a Class
argument, which are insensitive to the context class loader. There are
a few situations where some library code you do not control, e.g.
JAXP, requires the CCL to be set in a certain way; in such cases use
the idiom above to set it to what you need for the dynamic scope you
require.
Comment 4 Marian Mirilovic 2005-07-15 07:53:42 UTC
closed