Search code examples
javacheckstylesuppress-warnings

How to fix Checkstyle empty block warning


I wanted to know the proper way of resolving this issue with a Checkstyle report where it points out an empty else block: "Must have at least one statement". We do not log anything in those classes and I think printing anything on console is also not a good idea. What would be the best way to handle this?

code example with empty "else if" block


Solution

  • you can just add ; between that braces

    .
    .
    .
    else if(condition){
        ;
    }
    .
    .
    .
    

    or as @Fred Larson said you can just insert a comment if you have any comment that why this section is empty

    .
    .
    .
    else if(condition){
        //the reason why this section is empty
    }
    .
    .
    .