new Check: ClassHeaderWrapOpenjdk
Author: Aman-BaliyanCreated Jul 7, 2026Updated Sep 28, 2026
Labelsnew moduleopenjdk style
I have executed the cli and showed it below, as cli describes the problem better than 1,000 words
According to openjdk's updated java-style guidelines on Wrapping Class Declarations:
Wrapping Class Declarations A class header should not be wrapped unless it approaches the maximum column limit. If it does, it may be wrapped before extends and/or implements keywords. Declarations of type parameters may, if necessary, be wrapped the same way as method arguments
Dos
public class MyGenericClass<T, S>
extends HashMap<T, S>
implements Comparable<T> {
…
}
public class AnotherClass<K, R> implements Collector<T extends K,
Set<? extends R>,
List<R>> {
…
}Don’ts
public class MyGenericClass<T> implements Comparable<T>,
Predicate<T> {
…
}Is your feature request related to a problem? Please describe.
Currently checkstyle does not have any check to inforce the rules given in the styleguide.
Solution
A new Check is needed to follow these rules . Structure of the check :
<module name="ClassHeaderWrapOpenjdk">
<property name="maxColumnLimit" value="80">
</module>
Rules covered by the proposed check -
- A class header should not be wrapped unless it approaches the maximum column limit.
- If it does, it may be wrapped before extends and/or implements keywords.
Sample Inputs
C:\Users\amanc\Downloads\Ai_Interviewer\PracticeCheckStyle\src\temp>cat Test.java
package temp;
import java.util.HashMap;
import java.util.function.Predicate;
public class Test {
abstract class MyGenericClass<T, S> // no violation
extends HashMap<T, S>
implements Comparable<T> {
}
abstract class MyGenericClass1<T, S>
extends HashMap<T, S> implements Comparable<T> { // violation implements should be at start of a new line
}
abstract class MyGenericClass2<T> implements Comparable<T>,
Predicate<T> { // violation above implements should be at start of a new line
}
class Temp
extends Test { // violation class header able to fit in character limit
}
class Temp1 extends Test {} // ok
}
Exception given in style guide
package temp;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.stream.Collector;
public class Test {
abstract class AnotherClass<K, R> implements Collector<K,
Set<? extends R>,
List<R>> { // no violation here
}
}
Source: checkstyle/checkstyle