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

  • Home
  • SEARCH
  • 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 99637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:25:32+00:00 2026-05-11T00:25:32+00:00

Based on this question it appears that the default template for CheckStyle will allow

  • 0

Based on this question it appears that the default template for CheckStyle will allow if else ladders to separate the if and else with a line break.

Meaning I would like this code to be flagged as a violation:

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

Is there a CheckStyle rule to prevent this? Looking over the docs, I don’t see one, and I’d prefer not to use the generic regex rule, if I don’t have to.

Also, if I use the GenericIllegalRegexp module, multiline regex don’t seem to work. Is there some remedy to this?

  • 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-11T00:25:33+00:00Added an answer on May 11, 2026 at 12:25 am

    I am not sure you can easily write a Checkstyle extension, since the AST browsing code of the Checkstyle SDK Gui does not make any difference between:

    else if 

    and

    else   if 

    In each case, else is a LITERAL_ELSE with in it an if…

    So the generic regexp else[ \t]*[\r\n]+[ \t]*if is indeed a quick way to detect that kind of code.


    Fix the regexp to include cases were :

    • there is no space not tab before/after newline
    • the is multiple newlines.

    Of course, you do not want to use the \s whitespace regexp expression, since it includes itself newline characters. It is clearer to separate spaces from return characters.


    Note: in Checkstyle 5.0beta, do not use "Generic Illegal Regexp", but rather the "Regexp" module:
    you can configure that RegExp module as ‘illegalPattern’ (with an associated Severity of ‘Warning’), and you do not have to use any kind af ‘multi-line’ flag: the regexp is enough.

    Regexp
    Description

    A check that makes sure that a specified pattern exists, exists less than a set number of times, or does not exist in the file.

    This check combines all the functionality provided by RegexpHeader, GenericIllegalRegexp and RequiredRegexp, except supplying the regular expression from a file.

    It differs from them in that it works in multiline mode. It’s regular expression can span multiple lines and it checks this against the whole file at once. The others work in singleline mode. Their single or multiple regular expressions can only span one line. They check each of these against each line in the file in turn.


    Thomas mentions in the comments:

    The checkstyle AST does have line number information.

    See "Is there any Checkstyle/PMD/Findbugs rule to force “else if” to be on the same line?"
    (in which one has to use a custom check, and not a regex match).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 175k
  • Answers 175k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Way 1 Put this code in the Init / Load… May 12, 2026 at 3:08 pm
  • Editorial Team
    Editorial Team added an answer boost::ptr_vector is the way to go if you can have… May 12, 2026 at 3:08 pm
  • Editorial Team
    Editorial Team added an answer An example of one tool that works as you desire… May 12, 2026 at 3:08 pm

Related Questions

A site I'm creating for a customer in D6 has various images overlaying parts
I have a UITableView with reorderable rows and I'm using the standard UITableViewCell.text property
I want to construct classes for use as decorators with the following principles intact:
Since the only operations required for a container to be used in a stack

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.