Skip to content

Enable IntellijIdea inspection: 'throw' inside 'finally' block #3301

@romani

Description

@romani

From IntelijIdea: Error handling: 'throw' inside 'finally' block (Errors) (5)
good explanations: http://programmers.stackexchange.com/questions/188858/throwing-an-exception-inside-finally

Issue is blocked by: cobertura/cobertura#289

Details:

 src/main/java/com/puppycrawl/tools/checkstyle/api
 LocalizedMessage.java (1)
 src/main/java/com/puppycrawl/tools/checkstyle/checks
 NewlineAtEndOfFileCheck.java (1)
 UniquePropertiesCheck.java (1)
 src/main/java/com/puppycrawl/tools/checkstyle
 PropertyCacheFile.java (2)

Example for one file - LocalizedMessage :

 src/main/java/com/puppycrawl/tools/checkstyle/api
 LocalizedMessage.java (1)
424: newBundle() IOException might be thrown inside 'finally' block

current code:

final Reader streamReader = new InputStreamReader(stream, "UTF-8");
try {
    // Only this line is changed to make it to read properties files as UTF-8.
    resourceBundle = new PropertyResourceBundle(streamReader);
}
finally {
    stream.close();
}

Expected code:

    try (Reader streamReader = new InputStreamReader(stream, "UTF-8")) {
        // Only this line is changed to make it to read properties files as UTF-8.
        resourceBundle = new PropertyResourceBundle(streamReader);
    }

results to:

[INFO] --- cobertura-maven-plugin:2.7:check (default) @ checkstyle ---
[INFO] Cobertura 2.1.1 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[INFO] Cobertura: Loaded information on 382 classes.
[ERROR] com.puppycrawl.tools.checkstyle.api.LocalizedMessage$Utf8Control failed coverage check. Branch coverage rate of 83.3% is below 100.0%

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions