FinalizeImplementation: enable rule

This commit is contained in:
Paul Campbell 2017-07-05 15:30:33 +01:00
parent 69ee78e50e
commit 3fe3d16d42
6 changed files with 129 additions and 7 deletions

View file

@ -127,7 +127,7 @@ Rule|Level|Source|Enabled|Suppressible
[FileLength](#filelength)|complexity|checkstyle|Yes| [FileLength](#filelength)|complexity|checkstyle|Yes|
[FileTabCharacter](#filetabcharacter)|layout|checkstyle|Yes| [FileTabCharacter](#filetabcharacter)|layout|checkstyle|Yes|
[FinalClass](#finalclass)|complexity|checkstyle|Yes| [FinalClass](#finalclass)|complexity|checkstyle|Yes|
[FinalizeImplementation](#finalizeimplementation)|unspecified|sevntu|| [FinalizeImplementation](#finalizeimplementation)|tweaks|sevntu|Yes|
[FinalLocalVariable](#finallocalvariable)|tweaks|checkstyle|| [FinalLocalVariable](#finallocalvariable)|tweaks|checkstyle||
[FinalParameters](#finalparameters)|tweaks|checkstyle|Yes| [FinalParameters](#finalparameters)|tweaks|checkstyle|Yes|
[ForbidAnnotation](#forbidannotation)|unspecified|sevntu|| [ForbidAnnotation](#forbidannotation)|unspecified|sevntu||
@ -2303,6 +2303,49 @@ enum InvalidConstants {
alpha, Beta; alpha, Beta;
} }
```` ````
#### [FinalizeImplementation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/FinalizeImplementationCheck.html)
Checks that the `finalize()` implementation doesn't ignore the base class implementation, and doesn't *only* call the base class implementation.
Valid:
```java
class Valid {
protected void finalize() {
try {
doSomething();
} finally {
super.finalize();
}
}
}
```
Invalid:
```java
class InvalidNoEffect1 {
protected void finalize() {
}
}
class InvalidNoEffect2 {
protected void finalize() {
doSomething();
}
}
class InvalidUseless {
protected void finalize() {
super.finalize();
}
}
class InvalidPublic {
public void finalize() {
try {
doSomething();
} finally {
super.finalize();
}
}
}
```
#### [ForbidCCommentsInMethods](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidCCommentsInMethodsCheck.html) #### [ForbidCCommentsInMethods](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/ForbidCCommentsInMethodsCheck.html)
Prevents the use of `/* C-style */` comments inside methods. Prevents the use of `/* C-style */` comments inside methods.
@ -2730,9 +2773,6 @@ Appears to be broken as of `1.21.0`.
#### [CustomDeclarationOrder](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/CustomDeclarationOrderCheck.html) #### [CustomDeclarationOrder](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/CustomDeclarationOrderCheck.html)
The [DeclarationOrder](#declarationorder) check already imposes an order for class elements. The [DeclarationOrder](#declarationorder) check already imposes an order for class elements.
#### [FinalizeImplementation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/FinalizeImplementationCheck.html)
TODO: enable
#### [ForbidAnnotation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/ForbidAnnotationCheck.html) #### [ForbidAnnotation](http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/annotation/ForbidAnnotationCheck.html)
Generic rule; doesn't embody a 'quality' check. Generic rule; doesn't embody a 'quality' check.

View file

@ -1439,11 +1439,10 @@ rules:
- -
name: FinalizeImplementation name: FinalizeImplementation
parent: TREEWALKER parent: TREEWALKER
level: level: TWEAKS
enabled: false enabled: true
source: SEVNTU source: SEVNTU
uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/FinalizeImplementationCheck.html uri: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/FinalizeImplementationCheck.html
reason: "TODO: enable"
- -
name: ForbidAnnotation name: ForbidAnnotation
parent: TREEWALKER parent: TREEWALKER

View file

@ -0,0 +1,42 @@
Checks that the `finalize()` implementation doesn't ignore the base class implementation, and doesn't *only* call the base class implementation.
Valid:
```java
class Valid {
protected void finalize() {
try {
doSomething();
} finally {
super.finalize();
}
}
}
```
Invalid:
```java
class InvalidNoEffect1 {
protected void finalize() {
}
}
class InvalidNoEffect2 {
protected void finalize() {
doSomething();
}
}
class InvalidUseless {
protected void finalize() {
super.finalize();
}
}
class InvalidPublic {
public void finalize() {
try {
doSomething();
} finally {
super.finalize();
}
}
}
```

View file

@ -0,0 +1,39 @@
/**
* The MIT License (MIT)
*
* Copyright (c) 2017 Paul Campbell
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files (the "Software"), to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies
* or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package net.kemitix.checkstyle.regressions;
/**
* Regression test for {@code FinalizeImplementationCheck}.
*
* @author Paul Campbell pcampbell@kemitix.net
*/
class FinalizeImplementation {
/**
* Negates effect of superclass finalize.
*/
@SuppressWarnings({"nofinalizer", "finalizeimplementation"})
protected void finalize() {
// doesn't call super.finalize()
}
}

View file

@ -178,6 +178,7 @@
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSingleCatchCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.UselessSingleCatchCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSuperCtorCallCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.UselessSuperCtorCallCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.EmptyPublicCtorInClassCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.EmptyPublicCtorInClassCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.FinalizeImplementationCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.WhitespaceBeforeArrayInitializerCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.WhitespaceBeforeArrayInitializerCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.MoveVariableInsideIfCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.MoveVariableInsideIfCheck"/>

View file

@ -231,6 +231,7 @@
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSingleCatchCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.UselessSingleCatchCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.UselessSuperCtorCallCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.UselessSuperCtorCallCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.EmptyPublicCtorInClassCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.EmptyPublicCtorInClassCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.FinalizeImplementationCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.WhitespaceBeforeArrayInitializerCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.WhitespaceBeforeArrayInitializerCheck"/>
<module name="com.github.sevntu.checkstyle.checks.coding.MoveVariableInsideIfCheck"/> <module name="com.github.sevntu.checkstyle.checks.coding.MoveVariableInsideIfCheck"/>