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 183578 - NoClassDefFoundError when trying to profile a test class
Summary: NoClassDefFoundError when trying to profile a test class
Status: RESOLVED FIXED
Alias: None
Product: profiler
Classification: Unclassified
Component: Base (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 normal (vote)
Assignee: J Bachorik
URL:
Keywords:
Depends on: 203519
Blocks:
  Show dependency tree
 
Reported: 2010-04-06 15:07 UTC by darbie
Modified: 2012-04-05 13:36 UTC (History)
0 users

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 darbie 2010-04-06 15:07:15 UTC
I have a test class with its own main method.  The class name is Test_Assert.  If I right click on the class in the projects pane and select "run file" it runs without problems.  When I right click and select "profile file" I get the following:

Profiler Agent: Waiting for connection on port 5140, timeout 10 seconds (Protocol version: 9)
Profiler Agent: Established local connection with the tool
java.lang.NoClassDefFoundError: com/spectra/util/Test_Assert
Caused by: java.lang.ClassNotFoundException: com.spectra.util.Test_Assert
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: com.spectra.util.Test_Assert.  Program will exit.
Profiler Agent: Initializing...
Profiler Agent: Connection with agent closed
Profiler Agent: Options: >D:\apps\NetBeans6.8\profiler3\lib,5140,10<
Profiler Agent: Connection with agent closed
Profiler Agent: Initialized succesfully
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)
Comment 1 Tomas Hurka 2010-04-06 15:27:28 UTC
Can you please provide a small project with a test class, where we can reproduce it? Thanks.
Comment 2 darbie 2010-04-11 15:39:37 UTC
Any class with a main in the "Test Packages" will have this problem.  But here are step by step directions to reproduce it:

File->New Project
select Java Application
Type "ProfilerBug" as the project name
uncheck "Create Main Class"

Under the ProfilerBug project right click on the "Test Packages" and select "New class"
Type in "Test_Me" for the class name and click finish

In class Test_Me add this method:
  public static void main(String[] args)
  {
    System.out.println("Hello world");
  }

save the file
In the project pane right click on "Test_Me.java" and select "Run File"
confirm that the string "hello world" is seen in the output window

Now go to the project pane and right click on "Test_Me.java" and select "Profile file"
click OK on the dialog about modifying the project
click run on the analyze performance dialog.

You will get this output:
java.lang.NoClassDefFoundError: Test_Me
Caused by: java.lang.ClassNotFoundException: Test_Me
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Test_Me.  Program will exit.

NOTE: This fails only with a main in a class in the test packages directory.  There is definately a CLASSPATH problem where the profiler is not looking in the test directory to pick up classes.
Comment 3 Tomas Hurka 2010-04-12 18:43:36 UTC
Thanks. I am able to reproduce it.
Comment 4 J Bachorik 2010-08-09 13:27:27 UTC
One possible solution would be to construct the "profile" macro in the project's build-impl.xml such that it accepts "${run.test.classpath}" property as a path in the classpath provided to the JVM being started. I would defer this change after the patch for #189151 has been integrated.

However, this will not solve the situation with "Compile on save" turned on - in this particular situation the ant is completely bypassed and "org.netbeans.api.java.project.runner.JavaRunner", which knows nothing about profiler, is used instead. 
A non-trivial change in the profiler integration will be required to provide profiler support in such cases.
Comment 5 J Bachorik 2011-10-06 12:49:07 UTC
Given the current implementation of the profiler IDE integration the solution to this problem would be rather hackish. Postponing to the next version where we will, hopefully, rewrite the profiler actions to be fully compatible with run/debug.
Comment 6 J Bachorik 2012-04-05 13:36:35 UTC
Should be fixed by http://hg.netbeans.org/profiler-main/rev/cf681524d222