Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8020216

javac, compile time error isn't shown when final static field is not assigned

    XMLWordPrintable

Details

    • b01
    • windows_xp
    • Verified

    Description

      FULL PRODUCT VERSION :
      javac -version
      javac 1.6.0_25

      java -version
      java version " 1.7.0 "
      Java(TM) SE Runtime Environment (build 1.7.0-b147)
      Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      ver - 5.1.2600 Service Pack 2 Build 2600
      ver- 6.1.7601 Service Pack 1 Build 7601

      A DESCRIPTION OF THE PROBLEM :
      If a blank final class variable in a class is not initialized and the constructor of that class is not allowed to complete by making it to throw an Exception, before it could be completed, the program compiles successfully.

      Although, it is mentioned in JLS (JLS8.3.1.2) that :
      It is a compile-time error if a blank final class variable is not definitely assigned by a static initializer of the class in which it is declared.

      REGRESSION. Last worked in version 6u45

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Declare a blank final static field in a class.
      2. Make the constructor of that class to throw an Exception.
      3. Compile the class file on command prompt .

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compilation should be unsuccessful. It should show an error : variable i might not have been initialized
      ACTUAL -
      Compilation is successful.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Main
      {
          private final static int i ;
          public Main()throws InstantiationException
          {
              throw new InstantiationException( " Can't instantiate " );
          }
      }


      ---------- END SOURCE ----------

      SUPPORT :
      YES

      Attachments

        Issue Links

          Activity

            People

              vromero Vicente Arturo Romero Zaldivar
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: