This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 131069

Summary: Incorrect brace elimination for nested IF
Product: ide Reporter: kduling <kduling>
Component: CodeAssignee: issues@ide <issues>
Status: RESOLVED DUPLICATE    
Severity: blocker    
Priority: P3    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: DEFECT Exception Reporter:

Description kduling 2008-03-25 17:19:30 UTC
Under Options -> Java Code -> Formatting -> Alignment & Braces -> Braces Generation, selecting "Eliminate" for "if"
introduces incorrect branching.

Example:

  public void update()
  {
    // Update the player's bat position
    final int keyState = getKeyStates();
    if ((keyState & GameCanvas.LEFT_PRESSED) != 0)
    {
      if (playerBat.getRefPixelX() - 5 > BAT_SPEED)
      {
        playerBat.move(-BAT_SPEED, 0);
      }
    }
    else if ((keyState & GameCanvas.RIGHT_PRESSED) != 0)
    {
      if (playerBat.getRefPixelX() + 15 < screenWidth - BAT_SPEED)
      {
        playerBat.move(BAT_SPEED, 0);
      }
    }

becomes

  public void update()
  {
    // Update the player's bat position
    final int keyState = getKeyStates();
    if ((keyState & GameCanvas.LEFT_PRESSED) != 0)
      if (playerBat.getRefPixelX() - 5 > BAT_SPEED)
        playerBat.move(-BAT_SPEED, 0);
    else if ((keyState & GameCanvas.RIGHT_PRESSED) != 0)
      if (playerBat.getRefPixelX() + 15 < screenWidth - BAT_SPEED)
        playerBat.move(BAT_SPEED, 0);
  }
Comment 1 kduling 2008-03-25 17:48:15 UTC

*** This issue has been marked as a duplicate of 123258 ***