Uploaded image for project: 'SonarJava'
  1. SonarJava
  2. SONARJAVA-3471

Performance Issue when computing SE of loops and method throwing exceptions

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Symbolic Execution
    • Labels:
      None

      Description

      Analyzing the following code in SonarLint takes 10 seconds with only one SE rule activated (like S2222, S3518, S2583, S3959), without SE rules it takes 200 ms.

      import java.math.BigDecimal;
      import java.sql.Connection;
      import java.sql.Date;
      import java.sql.PreparedStatement;
      import java.sql.ResultSet;
      import java.sql.Timestamp;
      import java.sql.Types;
      import java.util.LinkedList;
      import java.util.List;
      import java.util.Map;
      import java.util.TreeMap;
      
      public class Foo {
      
        public static void foo(Connection con) throws Exception {
          Map<Integer, List<Long>> results = new TreeMap<>();
          for (int repeat = 0; repeat < 1; repeat++) {
            for (int numberOfRows = 10; numberOfRows < 10000; numberOfRows *= 2) {
              List<Long> forThisRowCount = results.get(numberOfRows);
              if (forThisRowCount == null) {
                forThisRowCount = new LinkedList<>();
                results.put(numberOfRows, forThisRowCount);
              }
              con.createStatement().execute("DROP TABLE test");
              con.createStatement().execute("CREATE TABLE test (ID)");
              PreparedStatement stmt = con.prepareStatement("INSERT INTO test (ID) VALUES (?)");
              try {
                con.setAutoCommit(false);
                con.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
                Date d1 = new Date(System.currentTimeMillis());
                Date d2 = new Date(System.currentTimeMillis() + 1000000);
                Date d3 = new Date(System.currentTimeMillis() + 1250000);
                for (int i = 0; i < numberOfRows; i++) {
                  stmt.setObject(1, i, Types.INTEGER);
                  stmt.setObject(2, String.valueOf(i), Types.VARCHAR);
                  stmt.setObject(3, String.valueOf(i * 0.1), Types.VARCHAR);
                  stmt.setObject(4, String.valueOf(i / 3), Types.VARCHAR);
                  stmt.setObject(5, new Timestamp(d1.getTime()), Types.TIMESTAMP);
                  stmt.setObject(6, new Timestamp(d2.getTime()), Types.TIMESTAMP);
                  stmt.setObject(7, new Timestamp(d3.getTime()), Types.TIMESTAMP);
                  stmt.setObject(8, new BigDecimal(i + 0.1), Types.DECIMAL);
                  stmt.setObject(9, new BigDecimal(i * 0.1), Types.DECIMAL);
                  stmt.setObject(10, new BigDecimal(i / 3), Types.DECIMAL);
                  stmt.addBatch();
                }
                ResultSet rs = con.createStatement().executeQuery("SELECT COUNT(*) FROM testBug41532");
                rs.next();
                if (rs.getInt(1) != numberOfRows) {
                  System.out.println("Failed!");
                }
              } finally {
              }
            }
          }
        }
      }
      

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              alban.auzeill Alban Auzeill
            • Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: