Issue Details (XML | Word | Printable)

Key: VISUALVM-545
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: thurka
Reporter: cuteredstorm
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
VisualVM

Loading profiler for OC4J fails with NullPointerException - easy fix

Created: 30/Jan/13 05:36 PM   Updated: 14/Jun/13 12:00 PM   Resolved: 14/Jun/13 12:00 PM
Component/s: code
Affects Version/s: 1.3.5
Fix Version/s: 1.3.6

Time Tracking:
Original Estimate: 15 minutes
Original Estimate - 15 minutes
Remaining Estimate: 15 minutes
Remaining Estimate - 15 minutes
Time Spent: Not Specified
Time Spent - Not Specified

Environment:

Oracle OC4J and any other environment where agent is loaded by bootstrap class loader.


Tags:
Participants: cuteredstorm and thurka


 Description  « Hide

Class ProfilerActivate15 uses SystemClassLoader to access the jar it was loaded from. This use asumes that the agent (and thus ProfilerActivate15) was loaded by SystemClassLoader, which is not always the case. For instance, OC4J does not load the agent in SystemClassLoader. If visualvm is used to profile OC4J, loading of the agent fails with NullPointerException in ProfilerActivate15:78, since url=null. I recommend that the method ProfilerActivate15.activate be modified to support these cases.

Modifiy this code:
98 URL classUrl = ClassLoader.getSystemClassLoader().getResource("org/netbeans/lib/profiler/server/ProfilerActivate15.class");
99 File jar = getArchiveFile(classUrl);
to
98 URL classUrl = classLoader.getSystemClassLoader().getResource("org/netbeans/lib/profiler/server/ProfilerActivate15.class");
if (classUrl == null)
classUrl = Thread.currentThread().getContextClassLoader().getResource("org/netbeans/lib/profiler/server/ProfilerActivate15.class");
99 File jar = getArchiveFile(classUrl);



thurka added a comment - 04/Feb/13 04:29 PM

Can you please provide steps how to reproduce it? Thanks.


cuteredstorm added a comment - 05/Feb/13 05:52 AM

There are no steps other than:

  • Prepare/find an OC4J instance
  • start VisualVM (I only tried locally)
  • go to Profiler tab
  • click CPU or Memory
  • VisualVM fails to start profiler. Log shows "agent jar loaded but agent failed".

Reason for failure is described above.


thurka added a comment - 05/Feb/13 08:43 AM

I am sorry, I don't know nothing about OC4J. Where do I get OC4J? Which version of OC4J should I use? How do I start it?


cuteredstorm added a comment - 05/Feb/13 08:51 AM

OC4J is part of JDeveloper, although I used standalone Oracle Application Server. Version is 10.1.3.5, but I believe any version older should produce same results. 10.1.3.5 is also the latest OC4J version. All later versions of Oracle Application Server and JDeveloper use Weblogic instead of OC4J. All this software can be downloaded from oracle.com, ie http://www.oracle.com/technetwork/developer-tools/jdev/downloads/soft10135-098811.html

The change I suggested resolve a general problem when the server is not using SystemClassLoader to load the agent. If you look at the change, you will see, that it changes nothing when the original code works. But when it doesn't, it tries an alternative method. I actually believe that the alternative method is better in either case, but to minimize the impact, I suggest you use the above code so it only works, when "classUrl == null" as suggested.


thurka added a comment - 05/Feb/13 09:15 AM

Thanks. I would like to find out, why ProfilerActivate15 is not loaded by SystemClassLoader. It looks strange to me. Once this is know, I can think about the fix. BTW: This bug needs to fixed filled and fixed in NetBeans, since the problem is in NetBeans code and not in VisualVM.


cuteredstorm added a comment - 05/Feb/13 09:25 AM

Since I have the environment set-up, I can check things if you like, I just need to know what information you need. I can tell you already that ProfilerActivate15.class.getClassLoader() returns null, which indicates that it was loaded by the bootstrap class loader.


thurka added a comment - 05/Feb/13 03:57 PM

In normal circumstances "boot class loader" is parent classloader of "system class loader" and therefore everything works fine. I don't know, why this is not true for OC4J.


cuteredstorm added a comment - 11/Feb/13 02:55 PM

I have done some more research. ClassLoader.getSystemClassLoader() returns an oracle.classloader.PolicyClassLoader instance named oc4j:10.1.3. Although this is a child of bootstrap classloader, by J2EE standards (as I understand them), classes loaded by bootstrap are not always visible by child classloader. So this is indeed a bug in netbeans. Can you file it?

I used http://www.objectsource.com/j2eechapters/Ch21-ClassLoaders_and_J2EE.htm 21.1 and 21.3 for the research.


thurka added a comment - 25/Feb/13 01:10 PM

system class loader has nothing to do with J2EE specification. It should delegate to bootstrap class loader.


thurka added a comment - 14/Jun/13 11:57 AM

The problem is now tracked as NetBeans Profiler issue: https://netbeans.org/bugzilla/show_bug.cgi?id=231027


thurka added a comment - 14/Jun/13 12:00 PM

Fixed in NetBeans Profiler. The fix was transplanted to profiler-release73 branch <http://hg.netbeans.org/releases/rev/2206ed2aaf9d> and will be available in the next VisualVM release.