checkstyle / checkstyle/checkstyle

Anonymous class indentation is wrongly reported as incorrect in some cases

Open
#2,829 6 comments 0 reactions 0 assignees View on GitHub
approved indentation
Dominant language
Java
Stars
9.6k
Forks
4.2k
Avg merge
1d 2h
Merged PRs (30d)
227

Description

When trying to check the code, formatted according to the provided configuration, I see some strange behaviour of `checkstyle`.

The example `config.xml`:

``` xml















```

For the sample `CheckstyleProblem.java`:

``` java
package example;

/**
* Inner class formatting identified by checkstyle wrongly.
*/
public class CheckstyleProblem {

public interface Watcher {
public void process(CheckstyleProblem problem);
}

public CheckstyleProblem(String name, int intArgument, Watcher watcher) {
// bla bla
}

/**
* This is an example call that shows how inner class instance.
*
* @return checkstyle problem
*/
public CheckstyleProblem init() {
// some example code that gets a Watcher

CheckstyleProblem result;
result =
new CheckstyleProblem(
"problematic code formatting?",
3334,
//
// here checkstyle considers the indentation is wrong
//
new Watcher() {
@Override
public void process(CheckstyleProblem problem) {}
});

return new CheckstyleProblem(
"code formatting is ok from the point of view of checkstyle",
3334,
//
// here no warning from checkstyle
//
new Watcher() {
@Override
public void process(CheckstyleProblem problem) {}
});
}
}
```

running `checkstyle` on the example file shows warning that should not be there:

```
$ java -jar checkstyle-6.14.1-all.jar -c config.xml CheckstyleProblem.java
Starting audit...
[WARN] CheckstyleProblem.java:33: 'method def modifier' have incorrect indentation level 14, expected level should be one of the following: 8, 10, 12. [Indentation]
[WARN] CheckstyleProblem.java:35: 'object def rcurly' have incorrect indentation level 12, expected level should be one of the following: 6, 8. [Indentation]
Audit done.
```
##

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.