checkstyle / checkstyle/checkstyle

Indentation#lineWrappingIndentation is strictly enforced on 'annotation array initialization'

Open
#12,150 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
9.6k
Forks
4.2k
Avg merge
22h 23m
Merged PRs (30d)
232

Description

Check documentation: [Indentation](https://checkstyle.sourceforge.io/config_misc.html#Indentation)

---

```bash
javac Test.java

cat Test.java
package ladem.shop.middleware.service.shopware.client.schema;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Test.JsonSubTypes(value = {
@Test.JsonSubTypes.Type(),
@Test.JsonSubTypes.Type()
})
public class Test {

@Target({ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface JsonSubTypes {
JsonSubTypes.Type[] value();

@interface Type {
}
}
}
```

```bash
cat checkstyle_lineWrappingIndentation4.xml










java -jar checkstyle-10.3.3-all.jar -c checkstyle_lineWrappingIndentation4.xml Test.java
Starting audit...
[ERROR] /Users/mgrein/Downloads/checkstyle/Test.java:9:9: 'annotation array initialization' child has incorrect indentation level 8, expected level should be 4. [Indentation]
[ERROR] /Users/mgrein/Downloads/checkstyle/Test.java:10:9: 'annotation array initialization' child has incorrect indentation level 8, expected level should be 4. [Indentation]
Audit done.
Checkstyle ends with 2 errors.
```

```bash
cat checkstyle_lineWrappingIndentation8.xml










java -jar checkstyle-10.3.3-all.jar -c checkstyle_lineWrappingIndentation8.xml Test.java
Starting audit...
Audit done.
```

---

Expected: with _lineWrappingIndentation_ set to 4 and _forceStrictCondition_ not set (default: _false_) the provided java file should be valid for both config files.

Contributor guide

Open the contributing guide

Research direction

Reproduce the report with Test.java and the two checkstyle_lineWrappingIndentation XML configurations, using the commands shown. Start by tracing Indentation's handling of annotation array initialization and its lineWrappingIndentation and forceStrictCondition properties; done means the sample passes with lineWrappingIndentation set to 4 when forceStrictCondition remains false.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.