Avoid using the invalid initial context java:/comp

This rule flags any string literal that starts with java:/comp in Java files or XML files. This string usually represents a naming context lookup. The Java EE specification defines the lookup string as java:comp without the forward slash (/) preceding comp. However, Apache Tomcat allows the noncompliant string.

A Java quick fix for this rule is available in the source scanner. The quick fix for this rule removes the / from the string.

For example, consider the following code snippet which includes the extra forward slash.

private static String final SOME_LOOKUP_NAME = "java:/comp/env/someValue";
String anEnvValue = (String) initialContext.lookup("java:/comp/myEnvString");

The quick fix removes the forward slash and updates the code to:

private static String final SOME_LOOKUP_NAME = "java:comp/env/someValue";
String anEnvValue = (String) initialContext.lookup("java:comp/myEnvString");

The XML rule only flags the first instance of the string in the file if there are multiple. An XML quick fix is available in the source scanner. The XML quick fix changes all instances of the problem string in the file.

For example, consider the following XML code snippet.

<PROPERTY key="LookupName" value="java:/comp/env/someValue"/>

The quick fix removes the forward slash and updates the code to:

<PROPERTY key="LookupName" value="java:comp/env/someValue"/>