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 usinggetConnection(...)
either before the try or in thetry(...)
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?