UAST
JUnit 3 'super.tearDown()' is not called from 'finally' block
Warning
Reliability
New
Last modified: 03 December 2024 Reports calls of the JUnit 3's super.tearDown()
method that are not performed inside a finally
block. If an exception is thrown before super.tearDown()
is called it could lead to inconsistencies and leaks.
Example:
public class AnotherTest extends CompanyTestCase {
private Path path;
@Override
protected void setUp() throws Exception {
super.setUp();
path = Files.createTempFile("File", ".tmp");
}
@Override
protected void tearDown() throws Exception {
Files.delete(path);
super.tearDown();
}
}
Improved code:
public class AnotherTest extends CompanyTestCase {
private Path path;
@Override
protected void setUp() throws Exception {
super.setUp();
path = Files.createTempFile("File", ".tmp");
}
@Override
protected void tearDown() throws Exception {
try {
Files.delete(path);
} finally {
super.tearDown();
}
}
}
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
SuperTearDownInFinally
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | JUnit, 243.23126 |
Thanks for your feedback!
Was this page helpful?