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 189756

Summary: Using Refactor tools on project's "Main Class" causes exception
Product: java Reporter: peppertherj
Component: ProjectAssignee: Tomas Zezula <tzezula>
Status: RESOLVED FIXED    
Severity: normal CC: janie, jbecicka, jurimo, locked, mmirilovic
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows 7 x64   
Issue Type: DEFECT Exception Reporter:

Description peppertherj 2010-08-23 02:53:39 UTC
When you use particular refactoring tools and methods on a project's "Main Class", the project properties don't reflect the changes. As a result, running the project results in a ClassNotFoundException since it's still using the old Main Class value.

To reproduce:

1) Add a new Java project (Java > Java Application), or any Java project as long as it automatically adds the main method and its class.

2) Do one of the following to somehow change the Main.class file's package (these all produce the bug):

2a) Right-click the Main.class file's package, go to Refactor > Rename, and rename it.

2b) Open Main.class in the editor, click the package name in the package declaration at the top, and press Ctrl+R and rename the package this way.

2c) Open Main.class in the editor, change the package name directly without using the refactoring dialogs, and use the resulting error's hint in the hint box to "Move class to correct folder".

2d) Right-click the Main.class file itself, go to Refactor > Move and move it to another package.

2e) Create another package manually and drag the Main.class file to that new package without using the refactoring dialogs.

3) Try to run the project, and it will say that it can't find the main class (ClassNotFoundException is thrown, specifying the old package as the Main class' location).

4) Right-click the project in the project tree and go to "Properties".

5) Go to the "Run" submenu. Notice the package name for the "Main Class" field didn't change after the refactoring.

From what I could find, changes that don't carry over to the Main Class property for the project are a) Using Refactor > Rename or something similar on the package with the project's main class, and b) Using Refactor > Move or something similar on the Main Class itself (indirectly renames the package). When a package is refactored or when the main class is moved, it should change all functionally dependent package references in the IDE, including the main class field in the project properties.

Note that using Refactor > Rename on the Main Class file is working and shows how the IDE should behave. Renaming the Main Class file changes the field in the project properties.

Version: NetBeans IDE 6.9.1, Build 07-28-2010
System: Windows 7 x64 (6.1) on x86

Also occurs in my older version:
NetBeans 6.8, Build 12-04-2009.
Comment 1 Jan Becicka 2010-10-19 12:04:24 UTC
*** Bug 110169 has been marked as a duplicate of this bug. ***
Comment 2 Jan Becicka 2011-01-03 13:00:12 UTC
*** Bug 193963 has been marked as a duplicate of this bug. ***
Comment 3 Jan Becicka 2011-01-03 15:31:47 UTC
works for class rename. Does not work for move and package rename.
Comment 4 Tomas Zezula 2011-01-05 14:41:30 UTC
Fixed jet-main 97517ec72ebc
Comment 5 Quality Engineering 2011-01-06 09:09:20 UTC
Integrated into 'main-golden', will be available in build *201101060001* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/97517ec72ebc
User: Tomas Zezula <tzezula@netbeans.org>
Log: #189756:Using Refactor tools on project's "Main Class" causes exception
Comment 6 Jan Becicka 2011-01-21 10:49:22 UTC
*** Bug 194571 has been marked as a duplicate of this bug. ***