Affects Sonarqube Version:
Sonarqube version: 8.1.0.31237
sonar-scanner version: 4.2.0.1873-windows
Rule:
S1174: “Object.finalize()” should remain protected (versus public) when overriding
Description:
This rule detected Override of finalize() with arguments, for example: public void finalize(Foo foo)
,
This rule is implemented in sonar-java-plugin-6.2.0.21135.jar!\org\sonar\java\checks\ObjectFinalizeOverridenNotPublicCheck.class,
This rule detects public void finalize
by if (isFinalize(methodTree) && isPublic(methodTree)) {
, but it seems that there is no check for arguments.
In the implementation of a similar rule S1111, it explicitly includes checking whether the argument is included: if (!this.isInFinalizeMethod && “finalize”.equals(methodName.name()) && methodInvocationTree.arguments().isEmpty()) {
Code Sample demonstrating the issue:
@Override
public void finalize(WritableRaster raster) { // This line is marked as an error
int[][] screenHits = getScreenHits();
double logMaxHits = Math.log((double)getMaxHits());
int width = raster.getWidth();
int height = raster.getHeight();
for(int x = 0; x < width; x++) {
for(int y = 0; y < height; y++) {
int hits = screenHits[x][y];
double value = Math.log((double)hits)/logMaxHits;
raster.setSample(x, y, 3, value * 255);
}
}
}
Expected outcome:
false-positive
Running Sonarqube through:
command line