[Checkers] Question about the flow algorithm

Adam Warski adam at warski.org
Sun Mar 22 06:16:44 EDT 2009


Hello,

I've got a question about the flow algorithm, more specifically about  
the try-catch-finally handling.

In visitTry(), there's a code block:

if (node.getCatches() != null) {
         boolean catchAlive = true;
         for (CatchTree ct : node.getCatches()) {
             scan(ct, p);
             catchAlive &= alive;
         }
         // Conservative: only if there's no finally
         if (!catchAlive && node.getFinallyBlock() == null)
             annos = GenKillBits.copy(annoAfterBlock);
     }

which, after scanning the try{} block, scans the catch{} blocks, if  
there are any. Now, the last part says that if the caches aren't  
alive, that is, control can't "pass" through them, the state of the  
annotations after the whole try-catch should be the state of the  
annotations as it was at the end of the catch{} block - which is  
correct. However, I think this should happen only if ALL catches  
aren't alive. And right now, the "catchAlive" variable will be false  
if at least one catch isn't alive. So if one catch is alive, and a  
second isn't, the state of the annotations will be restored.

So in short, I think that the lines:

             boolean catchAlive = true;
             catchAlive &= alive;

should be changed to:

             boolean catchAlive = false;
             catchAlive |= alive;

-- 
Adam



More information about the checkers mailing list