Looking for a way to detect when lifecycle methods are not called (or not in the correct sequence)

I'm looking for a way to perform flow analysis to detect methods that are not called but should be. I haven't found anything comparable in IntelliJ inspections or FindBugs, so I will outline my ideal requirement and perhaps someone knows of a similar or equivalent solution.

This is for identifying when a method should be called on every instance of a class, not whether a method is technically reachable somewhere in the code. For example, if a transaction is created, and the commit/rollback methods are never called for that instance, it should be flagged as a potential problem. For a more specific example, look at the way that Android database transactions are used.

    try {
        mDatabase = mHelper.getWritableDatabase();
       // ... some database activity here ...
    } finally {

Once beginTransaction() has been called, endTransaction() must be called on the same object no matter which execution path(s) are taken in between. Also, at least one of those paths must contain a call to setTransactionSuccessful(). I would like to be able to specify these rules for specific classes, either as class annotations (similar to how @Nullable is used), or in a config file (or UI panel) for library classes that I can't directly annotate.

Does anyone know if something like this exists?

(nb. when I say "must be called", I mean in terms of correct usage. I know that in most cases, 'open' objects which fall out of scope are automatically cleaned up, but I prefer to do it explicity).

Please sign in to leave a comment.