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

Javac should give a warning for empty code blocks after condition statements

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.2, 5.0
    • tools
    • b49
    • x86, sparc
    • solaris_8, windows_xp
    • Verified

      Name: gm110360 Date: 08/13/2003


      A DESCRIPTION OF THE REQUEST :
      Hi! Consider the following code:

      String foo = "testing";
      String bar = "failure";

      if (foo.equals(bar));
      {
          // do something
      }

      Due to the semicolon after the comparison, the code block after the code control statement is always executed. To catch this type of programming mistake (which can slip to quite far in the development cycle), javac should warn there's an empty block immediately after the if statement.

      JUSTIFICATION :
      The enhancement would make javac more useful as a development tool. I can't come up with a single useful code sample with would utilize the described (faulty) code structure so logically a warning should be given to the programmer.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      During compilation of the above code, a warning in style

      WARNING! Empty code block following a code control structure on line 123: if (foo.equals(bar));
      ACTUAL -
      No warnign is given.

      ---------- BEGIN SOURCE ----------
      String foo = "testing";
      String bar = "failure";

      if (foo.equals(bar));
      {
          // do something
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Not applicable.
      (Incident Review ID: 198976)
      ======================================================================

            jjg Jonathan Gibbons
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: