Menu

#1142 ECMAScript: getCatchClause() is buggy

PMD-5.1.0
closed
ECMAScript (9)
PMD
3-Major
Bug
5.0.x
2013-10-15
2013-10-15
No

Hello,

I think that in pmd.lang.ecmascript.ast.ASTTryStatement the function getCatchClause() is buggy.

public ASTCatchClause getCatchClause(int index) {
    return (ASTCatchClause) jjtGetChild(index - 1);
}

For an ASTTryStatement
- The child at index 0 is associated to body of the try.
- The child at index 1 is the (first) CatchClause.

So, if we agree to number the catch clauses from 0, the code should be

return (ASTCatchClause) jjtGetChild(index + 1);

But it is valid to use try/finally without catch. In this case the child at index 1 is associated to the finally block.
So, jjtGetChild(index + 1) must be an instance of ASTCatchClause.

Regards

Discussion

  • Andreas Dangel

    Andreas Dangel - 2013-10-15
    • status: open --> closed
    • assigned_to: Andreas Dangel
    • Milestone: New Tickets --> PMD-5.1.0
     

Log in to post a comment.