-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Description
Detected at #14341.
Affects PR #14364
Test.java
import java.util.ArrayList;
import java.util.List;
public class Test {
List a = new ArrayList<> (); // violation expected
}
config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="TreeWalker">
<module name="GenericWhitespace"/>
</module>
</module>
Actual:
java -jar checkstyle-10.12.7-all.jar -c config.xml Test.java
Starting audit...
Audit done.
Expected: violation on line 5.
Test.java:5:26: '>' is followed by whitespace. [GenericWhitespace]
Explanation:
- As per the documentation, right angle bracket (
>
) should not be followed by whitespace for diamond operators and when preceding method name or constructor. - In
List a = new ArrayList<> ();
the right angle bracket (>
) precedes the constructor, and is also part of the diamond operator (<>
), hence shouldn't be followed by the whitespace. - The exact example is provided provided in the documentation, showcasing that it is incorrect style and should throw a violation, but this is ignored by the Check. (Also evident in the referenced PR)