Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 111447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:23:13+00:00 2026-05-11T02:23:13+00:00

We are using CheckStyle to enforce our style standards. One of the style rules

  • 0

We are using CheckStyle to enforce our style standards. One of the style rules we opted to include was the NeedBraces module.

NeedBraces specifies that every block type statement (such as if, else, for) must have opening and closing curly braces. However, as far as I can tell it isn’t working entirely correctly.

This example will trigger a CheckStyle error.

    if (true)     {         System.out.println('20');        }     else         System.out.println('30'); 

Because the else case doesn’t have braces. However, the next example fails to trigger a CheckStyle error.

    if (true)     {         System.out.println('20');        }     else         if (true)         {             System.out.println('30');         } 

This should have failed because of the missing braces on the else case, but checkstyle lets it pass. After double checking the documentation, I can’t find any reason why this isn’t working right.

So… Can the CheckStyle module ‘NeedBraces’ work with nested if/else blocks? Any ideas?


The answer to this question begs another question: is there a rule to flag the above undesirable code as a violation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T02:23:13+00:00Added an answer on May 11, 2026 at 2:23 am

    I believe it is making an exception because, though formatted strangely, what you have is an ‘else if’. It shouldn’t force you to put braces around the ‘if’ in this case because you would end up with ‘… else { if { … } }

    Your code should be formatted:

    if (true) {     System.out.println('20');    } else if (true) {     System.out.println('30'); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello, Background: I'm using Checkstyle 4.4.2 with a RegExp checker module to detect when
For our CI builds, we are using a company-wide set of rules for PMD
I'm using Checkstyle for Java in Eclipse IDE. I don't know in every java
Never was good at these things. We are using Checkstyle (for Java) to enforce
I am using eclipse checkstyle plugin. I have few methods in a class A
I'm running a maven project using Jenkins. The project is using the checkstyle plugin
I am using checkstyle in my codebase, http://checkstyle.sourceforge.net/ , and I am having a
Is there any functional advantage of using checkstyle instead of Eclipse own code formatter?
I'd like to write my own Check using CheckStyle and incorporate this in my
I want to get the result in one list using three different models in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.