Inspectopedia Help

JUnit 3 'super.tearDown()' is not called from 'finally' block

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(); } } }

Inspection Details

Available in:

IntelliJ IDEA 2023.3, Qodana for JVM 2023.3

Plugin:

Java, 233.SNAPSHOT

Last modified: 13 July 2023