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

javac incorrectness

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 1.4.2
    • tools
    • x86
    • linux



      Name: js151677 Date: 06/30/2004


      FULL PRODUCT VERSION :
      1.4.2_04

      ADDITIONAL OS VERSION INFORMATION :
      Linux frix 2.4.26 #1 Po m�j 3 09:28:22 CEST 2004 i686 GNU/Linux

      A DESCRIPTION OF THE PROBLEM :
      Here is an example (Incorrectness.java listing):
      public class Incorrectness {
        public static void main(String[] args) {
          boolean condition = true;
          if (condition)
            String[] strArray = new String[] {"one", "two", "three"};
        }
      }

      When I try compile it with 'javac Incorrectness.java' this error message occur:
      Incorrectness.java:5: '.class' expected
            String[] strArray = new String[] {"one", "two", "three"};
                     ^
      Incorrectness.java:5: not a statement
            String[] strArray = new String[] {"one", "two", "three"};
                  ^
      2 errors

      Really crazy error messages. In generaly, when I initialize arbitrary object inside implicit one-statement block, the error is reported.
      Ok, I know that has no sense to assign object reference inside one-statement block (because it is accessible only from that block), but explicit one-statement block (brackets added) works fine. Here is an exapmle (IncorrectnessFixed.java listing):
      public class IncorrectnessFixed {
        public static void main(String[] args) {
          boolean condition = true;
          if (condition) {
            String[] strArray = new String[] {"one", "two", "three"};
          }
        }
      }

      I think that both Incorrectness.java and IncorrectnessFixed.java source codes are equivalent.

      My javac version:
      Linux: from j2sdk-1_4_2_04-linux-i586.bin package
      Windows: from j2sdk_1_4_2_03-windows-i586-p.exe package


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      ncorrectness.java:5: '.class' expected
            String[] strArray = new String[] {"one", "two", "three"};
                     ^
      Incorrectness.java:5: not a statement
            String[] strArray = new String[] {"one", "two", "three"};
                  ^
      2 errors


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Incorrectness {
        public static void main(String[] args) {
          boolean condition = true;
          if (condition)
            String[] strArray = new String[] {"one", "two", "three"};
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Introduce explicit one-statement block. Simply add brackets.
      (Incident Review ID: 281910)
      ======================================================================

            ahe Peter Ahe
            jssunw Jitender S (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: