From 4cc70343bebd8c6748d2e77ba9e60f6cb9f43f5b Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 30 May 2017 15:01:05 +0100 Subject: [PATCH] builder: ExplicitInitilization only applies to object references --- CHANGELOG | 1 + README.md | 8 +++++--- builder/src/main/resources/application.yml | 2 ++ .../src/main/resources/rules/ExplicitInitialization.md | 8 +++++--- .../checkstyle/regressions/ExplicitInitialization.java | 8 -------- .../main/resources/net/kemitix/checkstyle-4-tweaks.xml | 4 +++- .../resources/net/kemitix/checkstyle-5-complexity.xml | 4 +++- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5f4612a..fa87ae3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ CHANGELOG * Upgrade sevntu to 1.24.0 * Add Rule: MoveVariableInsideIf * Add Rule: ForbidWildcardAsReturnType +* Modify Rule: ExplicitInitialization only applies to objects * Add Wercker CI * Add Shippable CI diff --git a/README.md b/README.md index ac39463..5e53626 100644 --- a/README.md +++ b/README.md @@ -903,13 +903,15 @@ Checks that when a class overrides the `equals()` method, that it also overrides Limits the number of executable statements in a method to 30. #### [ExplicitInitialization](http://checkstyle.sourceforge.net/config_coding.html#ExplicitInitialization) -Checks that fields are not being explicitly initialised to their already default value. +Checks that object fields are not being explicitly initialised to their already default value. + +Does not check primitive field types. Valid: ```` class Valid { - private int foo; + private int foo = 0; private Object bar; } @@ -919,7 +921,7 @@ Invalid: ```` class Invalid { - private int foo = 0; + private Integer foo = 0; private Object bar = null; } diff --git a/builder/src/main/resources/application.yml b/builder/src/main/resources/application.yml index 3b60a5d..ec5e0d0 100644 --- a/builder/src/main/resources/application.yml +++ b/builder/src/main/resources/application.yml @@ -275,6 +275,8 @@ rules: enabled: true source: CHECKSTYLE uri: http://checkstyle.sourceforge.net/config_coding.html#ExplicitInitialization + properties: + onlyObjectReferences: true - name: FallThrough parent: TREEWALKER diff --git a/builder/src/main/resources/rules/ExplicitInitialization.md b/builder/src/main/resources/rules/ExplicitInitialization.md index 62b851c..507d64b 100644 --- a/builder/src/main/resources/rules/ExplicitInitialization.md +++ b/builder/src/main/resources/rules/ExplicitInitialization.md @@ -1,11 +1,13 @@ -Checks that fields are not being explicitly initialised to their already default value. +Checks that object fields are not being explicitly initialised to their already default value. + +Does not check primitive field types. Valid: ```` class Valid { - private int foo; + private int foo = 0; private Object bar; } @@ -15,7 +17,7 @@ Invalid: ```` class Invalid { - private int foo = 0; + private Integer foo = 0; private Object bar = null; } diff --git a/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java b/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java index 322b589..d2987c1 100644 --- a/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java +++ b/regressions/src/main/java/net/kemitix/checkstyle/regressions/ExplicitInitialization.java @@ -29,16 +29,8 @@ package net.kemitix.checkstyle.regressions; @SuppressWarnings("hideutilityclassconstructor") class ExplicitInitialization { - /** - * This will become valid in next release. - */ - @SuppressWarnings("explicitinitialization") private boolean validBoolean = false; - /** - * This will become valid in next release. - */ - @SuppressWarnings("explicitinitialization") private int validInt = 0; private String validString = ""; diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml index 4a5e460..08ac646 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-4-tweaks.xml @@ -50,7 +50,9 @@ - + + + diff --git a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml index 7181911..95ead8f 100644 --- a/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml +++ b/ruleset/src/main/resources/net/kemitix/checkstyle-5-complexity.xml @@ -69,7 +69,9 @@ - + + +