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 215402

Summary: [72cat] "Run File" is broken with Form based Java classes and Maven projects
Product: projects Reporter: jmborer <jmborer>
Component: MavenAssignee: Martin Entlicher <mentlicher>
Status: VERIFIED FIXED    
Severity: normal CC: anebuzelsky, jhavlin, jkovalsky, mentlicher, mmirilovic
Priority: P1    
Version: 7.2   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:
Attachments: A binary patch for this bug

Description jmborer 2012-07-11 12:57:18 UTC
Today I've run into a very strange issue. I have a class TableDemo with a main method in my test source files. When I try to "run file" I got this output:

cd H:\projects\inch\trunk\4-Implementation\positions\inch-laf; "JAVA_HOME=C:\\Program Files\\java\\jdk1.6.0_30" "M2_HOME=C:\\Program Files\\apache-maven-3.0.4" "\"C:\\Program Files\\apache-maven-3.0.4\\bin\\mvn.bat\"" "-Dexec.args=-classpath %classpath ch.skyguide.inch.plaf.harmony.TableDemo,ch.skyguide.inch.plaf.harmony.TableDemo" "-Dexec.executable=C:\\Program Files\\java\\jdk1.6.0_30\\bin\\java.exe" -Dexec.classpathScope=test --show-version -Djava.net.useSystemProxies=true process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec


Notice that the main class in repeated twice with a comma between (ch.skyguide.inch.plaf.harmony.TableDemo,ch.skyguide.inch.plaf.harmony.TableDemo). No idea where it comes from because when I create a new clean project the correct main class name is not repeated.
Comment 1 jmborer 2012-07-11 13:30:23 UTC
It also occurs with files in "src". I have to say that I try to run those files
from a subproject:

root 
   |
   -> subproject
               |
               -> my project

I try to clean the cache
Comment 2 jmborer 2012-07-11 14:29:16 UTC
OK further info:

Same project with same Maven version works fine with 7.1

For the 7.2fcs, I cleared completely my .netbeans. After having restored everything, I got the same result, "Run file" dumps twice the name of the main class!!

Absolutely annoying. The last times I did not use this feature so I cannot say when and how my problem appeared. It also occurs with Dev Build 201206040001 and 7.2RC1
Comment 3 jmborer 2012-07-11 15:37:40 UTC
So additional infos:

"Run file" only fails with java files that are FORM files. Plain Java files with a main work as expected.

Are .form and .java counted as two files??

Another strange thing: I created a simple Maven project with a single .form. It works, but I see difference when I run it compared to my usual projects

I don't see this line: 

cd H:\lab\mavenproject1; "JAVA_HOME=C:\\Program Files\\java\\jdk1.6.0_30" "M2_HOME=C:\\Program Files\\apache-maven-3.0.4" "\"C:\\Program Files\\apache-maven-3.0.4\\bin\\mvn.bat\"" install

but I have directly:

run:
Comment 4 jmborer 2012-07-11 15:44:17 UTC
I am able to reproduce it with several simple steps:

1) Make sure you use the bundle Maven 3.0.4
2) Create a new Maven->Java Application Project
3) Create a JFrame form (NewJFrame) in the project

DO NOT BUILD HERE

4) Right click on the Frame and select "Run file"
5) you get 

cd C:\Documents and Settings\borerjc.SKYGUIDE\My
Documents\NetBeansProjects\mavenproject1; "JAVA_HOME=C:\\Program
Files\\java\\jdk1.6.0_30" "\"C:\\Program
Files\\netbeans\\7.2fcs\\java\\maven\\bin\\mvn.bat\"" "-Dexec.args=-classpath
%classpath
com.mycompany.mavenproject1.NewJFrame,com.mycompany.mavenproject1.NewJFrame"
"-Dexec.executable=C:\\Program Files\\java\\jdk1.6.0_30\\bin\\java.exe"
-Dexec.classpathScope=runtime process-classes
org.codehaus.mojo:exec-maven-plugin:1.2:exec
Scanning for projects...

------------------------------------------------------------------------
Building mavenproject1 1.0-SNAPSHOT
------------------------------------------------------------------------

[resources:resources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory C:\Documents and
Settings\borerjc.SKYGUIDE\My
Documents\NetBeansProjects\mavenproject1\src\main\resources

[compiler:compile]
Compiling 2 source files to C:\Documents and Settings\borerjc.SKYGUIDE\My
Documents\NetBeansProjects\mavenproject1\target\classes

[exec:exec]
java.lang.NoClassDefFoundError:
com/mycompany/mavenproject1/NewJFrame,com/mycompany/mavenproject1/NewJFrame
Caused by: java.lang.ClassNotFoundException:
com.mycompany.mavenproject1.NewJFrame,com.mycompany.mavenproject1.NewJFrame
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class:
com.mycompany.mavenproject1.NewJFrame,com.mycompany.mavenproject1.NewJFrame. 
Program will exit.
Exception in thread "main" [INFO]
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.594s
Finished at: Wed Jul 11 15:40:06 GMT 2012
Final Memory: 6M/15M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec
(default-cli) on project mavenproject1: Command execution failed. Process
exited with an error: 1(Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the
following articles:
[Help 1]
http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Check Maven network proxy...



If you build first then "Run file" will work, but then you can reproduce it
again by making "clean" and then again select "Run file" on NewJFrame.

For some reason, every time I try to run a file after a build in my projects,
they get rebuilt anyway.
Comment 5 jmborer 2012-07-11 15:57:27 UTC
I also tried older versions of Maven 3. Same result.
Comment 6 jmborer 2012-07-11 16:14:26 UTC
One last time:

1) I downloaded from http://bits.netbeans.org/netbeans/7.2/fcs_awe4mn9 a new version of NB and did a fresh install. Everything default and Java 1.6_30
2) Created a new Maven Java application project
3) Added a new JFrame class (NewJFrame)
4) Right click on it "Run File"

And BOOM!


cd H:\lab\mavenproject1; "JAVA_HOME=C:\\Program Files\\java\\jdk1.6.0_30" "\"C:\\Program Files\\netbeans\\7.2\\java\\maven\\bin\\mvn.bat\"" "-Dexec.args=-classpath %classpath com.mycompany.mavenproject1.NewJFrame,com.mycompany.mavenproject1.NewJFrame" "-Dexec.executable=C:\\Program Files\\java\\jdk1.6.0_30\\bin\\java.exe" -Dexec.classpathScope=runtime process-classes org.codehaus.mojo:exec-maven-plugin:1.2:exec
Scanning for projects...
                                                                        
------------------------------------------------------------------------
Building mavenproject1 1.0-SNAPSHOT
------------------------------------------------------------------------

[resources:resources]
[debug] execute contextualize
Using 'UTF-8' encoding to copy filtered resources.
skip non existing resourceDirectory H:\lab\mavenproject1\src\main\resources

[compiler:compile]
Compiling 2 source files to H:\lab\mavenproject1\target\classes

[exec:exec]
java.lang.NoClassDefFoundError: com/mycompany/mavenproject1/NewJFrame,com/mycompany/mavenproject1/NewJFrame
Caused by: java.lang.ClassNotFoundException: com.mycompany.mavenproject1.NewJFrame,com.mycompany.mavenproject1.NewJFrame
	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:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
Could not find the main class: com.mycompany.mavenproject1.NewJFrame,com.mycompany.mavenproject1.NewJFrame.  Program will exit.
Exception in thread "main" [INFO] ------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 2.766s
Finished at: Wed Jul 11 16:12:37 GMT 2012
Final Memory: 5M/15M
------------------------------------------------------------------------
Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2:exec (default-cli) on project mavenproject1: Command execution failed. Process exited with an error: 1(Exit value: 1) -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
Comment 7 mienamoo 2012-07-12 08:08:08 UTC
(In reply to comment #6)
> 1) I downloaded from http://bits.netbeans.org/netbeans/7.2/fcs_awe4mn9 a new
> version of NB and did a fresh install. Everything default and Java 1.6_30
> 2) Created a new Maven Java application project
> 3) Added a new JFrame class (NewJFrame)
> 4) Right click on it "Run File"

I was able to reproduce this on Windows 7 with NetBeans 7.2 build 201206291011, JDK 7u5 32-bit and Maven 3.0.4.

If Compile on Save is turned on for application execution (it is by default), then the first run fails but subsequent runs succeed.
Comment 8 jmborer 2012-07-12 08:11:15 UTC
(In reply to comment #7)
> (In reply to comment #6)
> > 1) I downloaded from http://bits.netbeans.org/netbeans/7.2/fcs_awe4mn9 a new
> > version of NB and did a fresh install. Everything default and Java 1.6_30
> > 2) Created a new Maven Java application project
> > 3) Added a new JFrame class (NewJFrame)
> > 4) Right click on it "Run File"
> 
> I was able to reproduce this on Windows 7 with NetBeans 7.2 build 201206291011,
> JDK 7u5 32-bit and Maven 3.0.4.

Great that's good news for me: it is not specific for my setup and therefore can be fixed more easily.

> 
> If Compile on Save is turned on for application execution (it is by default),
> then the first run fails but subsequent runs succeed.


Unfortunately for me, this happens all the time even with compile on Save turned on which is the default setting.
Comment 9 Antonin Nebuzelsky 2012-07-12 09:19:44 UTC
Jarda, Martin, please evaluate ASAP. Thanks.
Comment 10 Martin Entlicher 2012-07-12 11:17:35 UTC
It seems to be caused by http://hg.netbeans.org/main/rev/7460c14460ad
In particular, chages in extractFileObjectsfromLookup() method.
Comment 11 jmborer 2012-07-12 11:48:30 UTC
In http://hg.netbeans.org/main/rev/7460c14460ad I can see this:

    2.37 +    private static FileObject[] extractFileObjectsfromLookup(Lookup lookup) {
    2.38 +        List<FileObject> files = new ArrayList<FileObject>(lookup.lookupAll(FileObject.class));
    2.39 +        if (files.isEmpty()) { // fallback to old nodes
    2.40 +            for (DataObject d : lookup.lookupAll(DataObject.class)) {
    2.41 +                files.add(d.getPrimaryFile());
    2.42 +            }


Is the problem not related to line 2.38 where the file is added once and then added again on line 2.41 ?
Comment 12 jmborer 2012-07-12 11:49:29 UTC
(In reply to comment #11)
> In http://hg.netbeans.org/main/rev/7460c14460ad I can see this:
> 
>     2.37 +    private static FileObject[] extractFileObjectsfromLookup(Lookup
> lookup) {
>     2.38 +        List<FileObject> files = new
> ArrayList<FileObject>(lookup.lookupAll(FileObject.class));
>     2.39 +        if (files.isEmpty()) { // fallback to old nodes
>     2.40 +            for (DataObject d : lookup.lookupAll(DataObject.class)) {
>     2.41 +                files.add(d.getPrimaryFile());
>     2.42 +            }
> 
> 
> Is the problem not related to line 2.38 where the file is added once and then
> added again on line 2.41 ?

Forget my previous comment. I missed the file.isEmpty(). Sorry
Comment 13 jmborer 2012-07-12 11:52:53 UTC
(In reply to comment #11)
> In http://hg.netbeans.org/main/rev/7460c14460ad I can see this:
> 
>     2.37 +    private static FileObject[] extractFileObjectsfromLookup(Lookup
> lookup) {
>     2.38 +        List<FileObject> files = new
> ArrayList<FileObject>(lookup.lookupAll(FileObject.class));
>     2.39 +        if (files.isEmpty()) { // fallback to old nodes
>     2.40 +            for (DataObject d : lookup.lookupAll(DataObject.class)) {
>     2.41 +                files.add(d.getPrimaryFile());
>     2.42 +            }
> 
> 

Another guess would be that on line 2.38 the lookupAll returns two objects, on for the .form and another for the .java file. This would explain that the bug occurs as I explained with "form" runs and not plain Java files. ASAIK one should only use the primary file here.
Comment 14 Martin Entlicher 2012-07-12 12:27:37 UTC
The multiple classes separated by commas should be provided to tests only. A list of a comma-separated main classes can not be executed by run/debug.

Also, it's strange, that after second Run, it's executed by ANT, not Maven. After clean, it's executed by Maven again. This explains why it has worked for you without the clean. This should be probably some separate issue...
Comment 15 Martin Entlicher 2012-07-12 12:34:41 UTC
jmborer, your guess is correct, the lookupAll returns both .java and .form files.
Since the use of DataObjects  might be reduced, I'm simply choosing unique file names...
Fixed by changeset:   226542:f93e3bcb7b87
http://hg.netbeans.org/main/rev/f93e3bcb7b87
Comment 16 Milos Kleint 2012-07-12 13:05:02 UTC
(In reply to comment #14)

> Also, it's strange, that after second Run, it's executed by ANT, not Maven.
> After clean, it's executed by Maven again. This explains why it has worked for
> you without the clean. This should be probably some separate issue...

that´s compile on save related. and source of many, many problems with user perception.  ant cmes into play onlz when CoS is enabled and certain conditions are met
Comment 17 jmborer 2012-07-12 13:40:41 UTC
Guys why is this issue targeting milestone 7.3? It must be fixed in 7.2, since it is a annoying regression.
Comment 18 Martin Entlicher 2012-07-12 14:08:24 UTC
Created attachment 121973 [details]
A binary patch for this bug

It needs to be fixed in trunk first anyay. And it's waiting for an approval...

In the mean time, could you please verify that the fix really solves this issue?
I've attached patch.jar file, which you can add to NetBeans by going to
java\modules folder in your NetBeans installation directory,
create patches\org-netbeans-modules-maven folders there
and copy the patch.jar file to java\modules\patches\org-netbeans-modules-maven directory. After NetBeans restart, you should see a message like:
"Module patch or custom extension: .../netbeans/java/modules/patches/org-netbeans-modules-maven/patch.jar" in the var\log\messages.log file in NetBeans' user directory. And this problem with Run File should be fixed...
Thanks.
Comment 19 jmborer 2012-07-12 14:10:43 UTC
(In reply to comment #18)
> Created attachment 121973 [details]
> A binary patch for this bug
> 
> It needs to be fixed in trunk first anyay. And it's waiting for an approval...
> 
> In the mean time, could you please verify that the fix really solves this
> issue?
> I've attached patch.jar file, which you can add to NetBeans by going to
> java\modules folder in your NetBeans installation directory,
> create patches\org-netbeans-modules-maven folders there
> and copy the patch.jar file to java\modules\patches\org-netbeans-modules-maven
> directory. After NetBeans restart, you should see a message like:
> "Module patch or custom extension:
> .../netbeans/java/modules/patches/org-netbeans-modules-maven/patch.jar" in the
> var\log\messages.log file in NetBeans' user directory. And this problem with
> Run File should be fixed...
> Thanks.

I'll do it immediately. I'll let you know quickly.

BTW should I reword the bug title entry now that we understand the issue?
Comment 20 Jaroslav Havlin 2012-07-12 14:16:45 UTC
(In reply to comment #15)
> Fixed by changeset:   226542:f93e3bcb7b87
> http://hg.netbeans.org/main/rev/f93e3bcb7b87
The patch works well.
Comment 21 jmborer 2012-07-12 14:17:08 UTC
Done. It works again! Everything is back working as with 7.1. Good job!
Comment 22 Martin Entlicher 2012-07-12 14:25:30 UTC
Thanks for the fast verification. Yes, please feel free to adjust the subject.
Comment 23 Marian Mirilovic 2012-07-12 14:44:14 UTC
Ok, Martin please integrate into release72 branch NOW ! 

We are still taking into account two possible scenarios :
- fix in 7.2 -> means rebuild and additional testing
- fix in 7.2.1 (7.2 Patch 1) -> means no rebuild

This alone is not a stopper, but we will for sure include it into if there is another reason for rebuild (speaking as now - the situation with GlassFish is still unclear, so it might really end up in 7.2).

Please stay tuned ...
Comment 24 Martin Entlicher 2012-07-12 14:51:50 UTC
Thanks, it in release72: changeset:   233792:d798908b04b7
http://hg.netbeans.org/releases/rev/d798908b04b7
Comment 25 Quality Engineering 2012-07-13 04:04:09 UTC
Integrated into 'main-golden', will be available in build *201207130002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/f93e3bcb7b87
User: mentlicher@netbeans.org
Log: #215402: Do not provide more arguments separated by commas, if not running tests. Also, check for duplicate class names.
Comment 26 Quality Engineering 2012-07-13 06:33:52 UTC
Integrated into 'releases', will be available in build *201207130001* or newer. Wait for official and publicly available build.
Changeset: http://hg.netbeans.org/releases/rev/d798908b04b7
User: mentlicher@netbeans.org
Log: #215402: Do not provide more arguments separated by commas, if not running tests. Also, check for duplicate class names.
(transplanted from f93e3bcb7b876a279a7f65f94cf7aa3fb4f07e34)