Use the default InitialContext JNDI properties

Use the default values for the java.naming.factory.initial and java.naming.provider.url JNDI properties when you migrate to Liberty. The following WebSphere Application Server traditional values for these properties are not valid:

The migration tool scans Java and properties files for the properties mentioned earlier.

In jndi.properties files the java.naming.factory.initial and java.naming.provider.url property keys are flagged regardless of the value. If the properties file rule detects a jndi.properties file, check the properties in the file. Either remove the java.naming.factory.initial and java.naming.provider.url properties, or delete the file if none of the properties are needed.

The following example illustrates application code that this rule will flag:


import java.util.Hashtable;
import javax.naming.InitialContext;
...
void main( String[] args ) {
Hashtable ht = new Hashtable();

ht.put(java.naming.factory.initial, com.ibm.websphere.naming.WsnInitialContextFactory);
ht.put(java.naming.provider.url, corbaloc:iiop:localhost:2809);

InitialContext ctx = new InitialContext(ht);
}

When you use the InitialContext(Hashtable) constructor, remove these two properties. If no other properties are being used, you can use the default constructor.

The following example illustrates the proper use of the code shown in the previous example:


import javax.naming.InitialContext;
...
void main( String[] args ) {
InitialContext ctx = new InitialContext();
}

When you use the InitialContext(Hashtable) constructor, remove these two properties. If no other properties are being used, you can use the default constructor.

This rule has an automated fix to remove those two properties. Copy the custom configuration to your application build file to enable it.

The rule will also flag com.ibm.websphere.naming.WsnInitialContextFactory anywhere in Java code. Remove this string and verify that it is not being used as part of InitialContext initialization.