[jira] [Commented] (NETBEANS-6062) Static block not executed in Java Ant project

2021-09-25 Thread Andrew James (Jira)


[ 
https://issues.apache.org/jira/browse/NETBEANS-6062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17420142#comment-17420142
 ] 

Andrew James commented on NETBEANS-6062:


This appears to be a duplicate of [NETBEANS-5757] and [NETBEANS-5832]. It 
appears to be fixed in NetBeans 12.5.

> Static block not executed in Java Ant project
> -
>
> Key: NETBEANS-6062
> URL: https://issues.apache.org/jira/browse/NETBEANS-6062
> Project: NetBeans
>  Issue Type: Bug
>Affects Versions: 12.4
> Environment: NetBeans 12.4
> Java 15.0.2 (Adopt Open JDK)
> Windows 10
>Reporter: Andrew James
>Priority: Major
> Attachments: NETBEANS-6062.zip
>
>
> A simple Java Ant project in NetBeans 12.4 (using Java 15) does not execute 
> the static code block, when the project is executed from within the IDE.
> Steps to reproduce:
> File > New Project > Java with Ant
> Create two classes:
> -(Whenever I try to format the below code, it looks completely wrong in the 
> ticket, so it's just presented as plain text - sorry I do not know how this 
> system handles code snippets).-
> *1) Main.java*
> {code:java}
> public class Main {
>  public static void main(String args[]) {
>  System.out.println(Test.i);
>  }
> }
> {code}
> *2) Test.java*
> {code:java}
> class Test {
>  static int i;
>  static {
>  i = 10;
>  }
> }
> {code}
>  
> *Actual results:*
> When the project is run from within the IDE, the output is "0". The static 
> block in Test is not executed.
> *Expected results:*
> The expected output is "10". The static block in Test is executed.
> *Note also:*
> The JAR built by the project runs correctly, when executed from the command 
> line, outside of the IDE.
> The same code shown above also runs as expected in the IDE when built using a 
> Java Maven project, instead of a Java Ant project.
> This behavior does not appear when executing the same code, using NetBeans 
> 12.0 and Java 11.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



[jira] [Commented] (NETBEANS-6062) Static block not executed in Java Ant project

2021-09-25 Thread Andrew James (Jira)


[ 
https://issues.apache.org/jira/browse/NETBEANS-6062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17420109#comment-17420109
 ] 

Andrew James commented on NETBEANS-6062:


Regarding the JAR vs. IDE execution: (1) Yes, both executions used the same 
version of Java (Java 15.0.2 Adopt Open JDK). And they gave different results. 
I dug deeper by comparing the *{{javap -c}}* output for the following two class 
files:

a) The Test.class file in the build\classes directory.

b) The Test.class file extracted from the assembled JAR file (the one 
auto-created by NetBeans).

I changed the code to assign a different value to i (just to double-check 
execution behavior):
{code:java}
i = 123; {code}
I also performed a full clean and build.

The execution results were unchanged: I got an output of {{*0*}} from the IDE 
but I got *{{123}}* from the JAR.

The *{{javap -c}}* results showed that *the compiled contents from the 
build\classes directory are different from the compiled contents from the JAR 
file*.

Results from build\classes:
{code:java}
>javap -c build\classes\foo4\Test.class

Compiled from "Test.java"
class foo4.Test {
  static int i;  foo4.Test();
Code:
   0: aload_0
   1: invokespecial #1  // Method 
java/lang/Object."":()V
   4: return
}{code}
Results from the unzipped JAR file:
{code:java}
>javap -c unjar\foo4\Test.class

Compiled from "Test.java"
class foo4.Test {
  static int i;  foo4.Test();
Code:
   0: aload_0
   1: invokespecial #1  // Method 
java/lang/Object."":()V
   4: return  static {};
Code:
   0: bipush123
   2: putstatic #7  // Field i:I
   5: return
}{code}
As we can see, the version from the JAR file contains the code for the static 
block. This is missing from the build\classes version.

This was surprising.

(I have not installed NetBeans 12.5 yet - I will update when I have had a 
chance to do so).

> Static block not executed in Java Ant project
> -
>
> Key: NETBEANS-6062
> URL: https://issues.apache.org/jira/browse/NETBEANS-6062
> Project: NetBeans
>  Issue Type: Bug
>Affects Versions: 12.4
> Environment: NetBeans 12.4
> Java 15.0.2 (Adopt Open JDK)
> Windows 10
>Reporter: Andrew James
>Priority: Major
> Attachments: NETBEANS-6062.zip
>
>
> A simple Java Ant project in NetBeans 12.4 (using Java 15) does not execute 
> the static code block, when the project is executed from within the IDE.
> Steps to reproduce:
> File > New Project > Java with Ant
> Create two classes:
> -(Whenever I try to format the below code, it looks completely wrong in the 
> ticket, so it's just presented as plain text - sorry I do not know how this 
> system handles code snippets).-
> *1) Main.java*
> {code:java}
> public class Main {
>  public static void main(String args[]) {
>  System.out.println(Test.i);
>  }
> }
> {code}
> *2) Test.java*
> {code:java}
> class Test {
>  static int i;
>  static {
>  i = 10;
>  }
> }
> {code}
>  
> *Actual results:*
> When the project is run from within the IDE, the output is "0". The static 
> block in Test is not executed.
> *Expected results:*
> The expected output is "10". The static block in Test is executed.
> *Note also:*
> The JAR built by the project runs correctly, when executed from the command 
> line, outside of the IDE.
> The same code shown above also runs as expected in the IDE when built using a 
> Java Maven project, instead of a Java Ant project.
> This behavior does not appear when executing the same code, using NetBeans 
> 12.0 and Java 11.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



[jira] [Commented] (NETBEANS-6062) Static block not executed in Java Ant project

2021-09-25 Thread Andrew James (Jira)


[ 
https://issues.apache.org/jira/browse/NETBEANS-6062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17420108#comment-17420108
 ] 

Andrew James commented on NETBEANS-6062:


Thank you for the formatting help [~asbachb] - I have now found 
[this|[https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=advanced],|https://jira.atlassian.com/secure/WikiRendererHelpAction.jspa?section=advanced),]
 also.

> Static block not executed in Java Ant project
> -
>
> Key: NETBEANS-6062
> URL: https://issues.apache.org/jira/browse/NETBEANS-6062
> Project: NetBeans
>  Issue Type: Bug
>Affects Versions: 12.4
> Environment: NetBeans 12.4
> Java 15.0.2 (Adopt Open JDK)
> Windows 10
>Reporter: Andrew James
>Priority: Major
> Attachments: NETBEANS-6062.zip
>
>
> A simple Java Ant project in NetBeans 12.4 (using Java 15) does not execute 
> the static code block, when the project is executed from within the IDE.
> Steps to reproduce:
> File > New Project > Java with Ant
> Create two classes:
> -(Whenever I try to format the below code, it looks completely wrong in the 
> ticket, so it's just presented as plain text - sorry I do not know how this 
> system handles code snippets).-
> *1) Main.java*
> {code:java}
> public class Main {
>  public static void main(String args[]) {
>  System.out.println(Test.i);
>  }
> }
> {code}
> *2) Test.java*
> {code:java}
> class Test {
>  static int i;
>  static {
>  i = 10;
>  }
> }
> {code}
>  
> *Actual results:*
> When the project is run from within the IDE, the output is "0". The static 
> block in Test is not executed.
> *Expected results:*
> The expected output is "10". The static block in Test is executed.
> *Note also:*
> The JAR built by the project runs correctly, when executed from the command 
> line, outside of the IDE.
> The same code shown above also runs as expected in the IDE when built using a 
> Java Maven project, instead of a Java Ant project.
> This behavior does not appear when executing the same code, using NetBeans 
> 12.0 and Java 11.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



[jira] [Commented] (NETBEANS-6062) Static block not executed in Java Ant project

2021-09-24 Thread Benjamin Asbach (Jira)


[ 
https://issues.apache.org/jira/browse/NETBEANS-6062?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=17420055#comment-17420055
 ] 

Benjamin Asbach commented on NETBEANS-6062:
---

[~andrewjames] I modified your ticket and added code tags.

I tried to reproduce your problem with NetBeans 12.5 on OpenJDK 16. Any chance 
you tried NetBeans 12.5 to check if this is still a problem.

Are you sure when you execute the jar manually you're using the same JDK while 
executing it inside NetBeans?

> Static block not executed in Java Ant project
> -
>
> Key: NETBEANS-6062
> URL: https://issues.apache.org/jira/browse/NETBEANS-6062
> Project: NetBeans
>  Issue Type: Bug
>Affects Versions: 12.4
> Environment: NetBeans 12.4
> Java 15.0.2 (Adopt Open JDK)
> Windows 10
>Reporter: Andrew James
>Priority: Major
>
> A simple Java Ant project in NetBeans 12.4 (using Java 15) does not execute 
> the static code block, when the project is executed from within the IDE.
> Steps to reproduce:
> File > New Project > Java with Ant
> Create two classes:
> -(Whenever I try to format the below code, it looks completely wrong in the 
> ticket, so it's just presented as plain text - sorry I do not know how this 
> system handles code snippets).-
> *1) Main.java*
> {code:java}
> public class Main {
>  public static void main(String args[]) {
>  System.out.println(Test.i);
>  }
> }
> {code}
> *2) Test.java*
> {code:java}
> class Test {
>  static int i;
>  static {
>  i = 10;
>  }
> }
> {code}
>  
> *Actual results:*
> When the project is run from within the IDE, the output is "0". The static 
> block in Test is not executed.
> *Expected results:*
> The expected output is "10". The static block in Test is executed.
> *Note also:*
> The JAR built by the project runs correctly, when executed from the command 
> line, outside of the IDE.
> The same code shown above also runs as expected in the IDE when built using a 
> Java Maven project, instead of a Java Ant project.
> This behavior does not appear when executing the same code, using NetBeans 
> 12.0 and Java 11.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

-
To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org
For additional commands, e-mail: commits-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists