Ensure context lookups have corresponding deployment descriptor entries

This rule flags instances of context lookup method. The argument to the lookup method should be defined in the web.xml file.

The suggested action is, for each context lookup found, the user should check that there is a corresponding resource-reference , resource-env-reference , or env-entry element in the web.xml file.

For example in the following code snippet, the lookup method would be flagged.

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env/myIntialParam");

If the argument to the lookup method is "java:comp/env" or "java:comp/UserTransaction" the context lookup method is not flagged because they do not correspond to specific resources.

In the following example, the two instances of the lookup method would not be flagged.

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
UserTransaction tran = (UserTransaction)initCtx.lookup("java:comp/UserTransaction");