Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 324269

Summary: "Could not find the main class. Program will exit" When an exception is thrown in a static variable
Product: [Eclipse Project] JDT Reporter: Chaiavi <avraham2>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: RESOLVED NOT_ECLIPSE QA Contact:
Severity: normal    
Priority: P3 CC: amj87.iitr, darin.eclipse
Version: 3.7   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Chaiavi CLA 2010-09-02 02:31:43 EDT
Build Identifier: 20100617-1415

I have a simple runnable class (uses "public static void main(.....).

The class has a static variable which gets its value from using an other class in my case the line of code is as follows:

"private final static String TERM_ID = DBUtilsHS.lookupUserByName(hsSession, HS_TERM_NAME).getUserid().toString();"

The line of code above throws a null pointer exception which causes the IDE to show the following error message box:
"Could not find the main class. Program will exit"



IMHO this is just wrong! because it's misleading - the IDE can actually find the main class (it exists in the build directory as it should), it just can't instantiate it because of a prior exception thrown in a static variable.

Reproducible: Always

Steps to Reproduce:
1. Create a simple runnable java class (using (static public void main....)
2. Create a static variable which executes a method which throws a NullPointerException
3. See the misleading error message box
4. fix it

Thanks
:-)
Comment 1 Ayushman Jain CLA 2010-09-02 02:50:07 EDT
Moving to JDT/Debug

Testcase:

----------8<----------------------------------------------
package test;
public class Test {
    private static final String abc = test().toString();
    public static Object test(){
       return null;
    }
}
----------8<----------------------------------------------
Comment 2 Ayushman Jain CLA 2010-09-02 02:54:59 EDT
(In reply to comment #1)
> Moving to JDT/Debug
> 
> Testcase:

Correction 

----------8<----------------------------------------------
package test;
public class Test {
    private static final String abc = test().toString();
    public static Object test(){
       return null;
    }
    public static void main(String[] args) {
    }
}
----------8<----------------------------------------------
Comment 3 Darin Wright CLA 2010-09-02 09:16:15 EDT
The error is reported from the Java VM, not Eclipse.