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

Java compiler unable to detect comma in 2-d array creation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Not an Issue
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      A DESCRIPTION OF THE PROBLEM :
       System.out.println(new Object[][]{
                      new Object[]{new Integer[]{1, 20, 2, 10}, new Integer(2)},
                      new Object[]{new Integer[]{10, 1, 2, 3, 4, 5, 6, 7, 8, 9}, new Integer(9)},
              });

      even after 2nd object, even if I put an additional comma(,), compiler never detects that. However, I feel it is an syntactical error which must be detected by the compiler.

      Here is another example,
      int[]arr = {1,2,3,}

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      public class MyClass {
          public static void main(String args[]) {
            int[]arr = {1,2,3,};
             System.out.println(new Object[][]{
                      new Object[]{new Integer[]{1, 20, 2, 10}, new Integer(2)},
                      new Object[]{new Integer[]{10, 1, 2, 3, 4, 5, 6, 7, 8, 9}, new Integer(9)},
              });
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Compilation issue due to comma (,)
      ACTUAL -
      No compilation error is detected.

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            adev ANUPAM DEV
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: