The InitialContext lookup method can return primitive types

This rule flags javax.naming.InitialContext.lookup method calls where the result is cast to a java.lang.String.

On Liberty, the javax.naming.InitialContext lookup method returns an object whose type is determined by interpreting the value stored in the jndiEntry element as a Java literal string or primitive data type. If the parsing fails, the exact value is provided as an unmodified string. On WebSphere traditional, primitive data types are returned as strings.

It is important to understand this difference when migrating your JNDI entry configuration from WebSphere traditional to Liberty. For example, If you configured a JNDI value to be 100 in WebSphere traditional, the application would be written to handle a string with an initial value of "100". In Liberty, if you configured an entry as the following:

<jndiEntry jndiName=myjndi/initialLimit value= ‘100’ />

Liberty will convert that value to an integer primitive. To have the application work the same way in Liberty as it did in WebSphere traditional, the JNDI entry should be coded as:

<jndiEntry jndiName=myjndi/initialLimit value=‘100’ />

The Liberty configuration produced in the server.xml file generated by the Migration Toolkit for Application Binaries quotes JNDI entry values to create String values so that the application works the same way in Liberty as it did on WebSphere traditional.

For more information, see the Using JNDI binding for constants from the server configuration files documentation.