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.

When an automated fix for this rule is provided it will remove 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 automated fix will remove 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. The XML automated fix will change 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 automated fix will remove the forward slash and updates the code to:

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