Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-5757

Compile-on-Save drops static initializer (vanilla javac)

Attach filesAttach ScreenshotVotersWatch issueWatchersLinkUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 12.4
    • Next
    • java - Compiler
    • None
    • NetBeans 12.4 without nb-javac installed (started from clean user and cache directories to ensure no trace of nb-javac was left from my old installation). Java 11.0.11 or Java 17-ea+25. Windows 10.

    Description

      Very great to see Compile-on-Save now working without the external nb-javac plugin! Here's the first bug I've found around this. To reproduce, create an empty maven-based Java project and add the following class:

      public class StaticInitializerExample {
        private static final String SOME_CONSTANT;
        static {
          SOME_CONSTANT = "I am a constant.";
        }
      
        public static final void main(String args[]) {
          System.out.println(SOME_CONSTANT);
        }
      }
      

      Do a clean build and run. The application will print, "I am a constant."

      Now do any trivial change to the code, such as adding a comment, and save. Run again. The application will now print "null", rather than the correct output.

      Tested on both Java 11.0.11 and Java 17-ea+25. I also tested with NetBeans 11.3 with nb-javac installed; in that case the output is correct (still "I am a constant."). In the latter case you can also change the constant in the static initializer, and CoS will apply the change correctly.

      Attachments

        Issue Links

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            Unassigned Unassigned
            ebakke Eirik Bakke
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment