Semgrep rule for a try/catch block

Viewed 71

I recently tried to create a Semgrep rule for Java code which detects if for a database connection happening in a try/catch block a proper rollback is done.

So what it needs to do is:

  • A Connection object is created using getConnection(...) either before the try or in the try(...) initializer statement
  • A catch block contains a call to connection.rollback()

How would I write such a rule in semgrep which matches a pattern before the try and in the catch block?

0 Answers
Related