package sfBugs;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Bug3566803 {

    public void notReported(String url, String username, String password) throws Exception {
        for (int i = 0; i < 10; i++) {
            if (i > 5) {
                Connection connection = DriverManager.getConnection(url, username, password);
                PreparedStatement pstmt = connection.prepareStatement("SELECT count(1) from tab");
                ResultSet rs = pstmt.executeQuery();
                while (rs.next()) {
                    System.out.println(rs.getString(1));
                }
            }
        }
    }

    public void isReported(String url, String username, String password) throws Exception {
        Connection connection = DriverManager.getConnection(url, username, password);
        PreparedStatement pstmt = connection.prepareStatement("SELECT count(1) from tab");
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            System.out.println(rs.getString(1));
        }
    }

    public static void main(String... strings) {
        Connection connection = null;
        PreparedStatement pstmt = null;
        ResultSet rs = null;
        try {
                String driverName = "oracle.jdbc.driver.OracleDriver";
                Class.forName(driverName);
                String url = "";
                String username = "";
                String password = "";
                for (int i = 0; i < 10; i++) {
                                connection = DriverManager.getConnection(url, username,
                                                password);

                                pstmt = connection
                                                .prepareStatement("SELECT count(1) from tab");

                                rs = pstmt.executeQuery();
                                while (rs.next()) {
                                        System.out.println(rs.getString(1));
                                }
                }
        } catch (ClassNotFoundException e) {
                e.printStackTrace();
        } catch (SQLException sql) {
                System.out.println("SQLException" + sql.getMessage());
        } finally {
                try {
                        if (rs != null)
                                rs.close();
                } catch (SQLException e) {
                        e.printStackTrace();
                }
                try {
                        if (pstmt != null)
                                pstmt.close();
                } catch (SQLException e) {
                        e.printStackTrace();
                }
                try {
                        if (connection != null)
                                connection.close();
                } catch (SQLException e) {
                        e.printStackTrace();
                }
        }
}


}

@@ -166,34 +166,212 @@
 n;%0A%0A
-public class Bug3566803 %7B%0A
+import edu.umd.cs.findbugs.annotations.DesireWarning;%0Aimport edu.umd.cs.findbugs.annotations.ExpectWarning;%0A%0A/** Now Bug1116 */%0A%0Apublic class Bug3566803 %7B%0A%0A    @ExpectWarning(%22ODR_OPEN_DATABASE_RESOURCE%22)
 %0A   
@@ -904,32 +904,81 @@
        %7D%0A    %7D%0A%0A
+    @ExpectWarning(%22ODR_OPEN_DATABASE_RESOURCE%22)%0A
     public void 
@@ -1365,24 +1365,73 @@
    %7D%0A    %7D%0A%0A
+    @DesireWarning(%22ODR_OPEN_DATABASE_RESOURCE%22)%0A
     public s
@@ -1807,24 +1807,122 @@
 sword = %22%22;%0A
+                %0A                // Bug: We only close the resources opened in the last iteration%0A
             

update description