forked from spotbugs/spotbugs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
spotbugs-tests/src/test/java/edu/umd/cs/findbugs/detect/Issue79Test.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package edu.umd.cs.findbugs.detect; | ||
|
||
import edu.umd.cs.findbugs.AbstractIntegrationTest; | ||
import edu.umd.cs.findbugs.BugInstance; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcher; | ||
import edu.umd.cs.findbugs.test.matcher.BugInstanceMatcherBuilder; | ||
import org.junit.Test; | ||
|
||
import static edu.umd.cs.findbugs.test.CountMatcher.containsExactly; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* SpotBugs should remove the ResultSet obligation from all set | ||
* when one occurrence of that type of obligation is Statement | ||
* from all states. | ||
* | ||
* @see <a href="https://github.com/spotbugs/spotbugs/issues/79">GitHub issue</a> | ||
* @since 4.1.3 | ||
*/ | ||
public class Issue79Test extends AbstractIntegrationTest { | ||
|
||
@Test | ||
public void test(){ | ||
performAnalysis("ghIssues/Issue79.class"); | ||
BugInstanceMatcher bugMatcher = new BugInstanceMatcherBuilder().build(); | ||
assertThat(getBugCollection(), containsExactly(0, bugMatcher)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ghIssues; | ||
|
||
import java.sql.Connection; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class Issue79 { | ||
private static final String QUERY = ""; | ||
|
||
public void f(Connection cnx) throws SQLException { | ||
PreparedStatement st = null; | ||
ResultSet rs = null; | ||
try { | ||
st = cnx.prepareStatement(QUERY); | ||
rs = st.executeQuery(); | ||
while (rs.next()) { | ||
System.out.println(rs.getString("ID")); | ||
} | ||
} finally { | ||
/* | ||
* The statement closes the result set, and there is no scenario where st may be null | ||
* but not the resultset, however an unsatisfied obligation is reported on the resultset | ||
*/ | ||
if (st != null) { | ||
st.close(); | ||
} | ||
} | ||
} | ||
} |