IBM Support

java.lang.ClassCastException error occurs during a JNDI lookup of a queue connection factory

Troubleshooting


Problem

In WebSphere® Application Server, the following exception might occur when an application attempts to do a Java™ Naming and Directory Interface (JNDI) lookup of a queue connection factory that is defined under the WebSphere MQ Java Message Service (JMS) provider: [] java.lang.ClassCastException: com/ibm/ejs/jms/JMSConnectionFactoryHandle incompatible with javax/jms/QueueConnectionFactory []

Cause

The ClassCastException occurs when a queue connection factory is defined as a WebSphere MQ Connection Factory instead of a WebSphere MQ Queue Connection Factory.

The application code is similar to the following example:


javax.jms.QueueConnectionFactory myQCF = null;
InitialContext ic = null;
//... setup InitialContext here ...
try
{
myQCF = (QueueConnectionFactory)ic.lookup("jms/myQCF");
}
catch(Throwable e)
{
e.printStackTrace();
}

Resolving The Problem

You can resolve the problem using one of the following methods:

  • Define the queue connection factory as a WebSphere MQ Queue Connection Factory.
  • Use a javax.jms.ConnectionFactory object in the application code rather than a javax.jms.QueueConnectionFactory object.

[{"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Java Message Service (JMS)","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"8.5.5;8.5;8.0;7.0;6.1","Edition":"Base;Express;Network Deployment","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SSNVBF","label":"Runtimes for Java Technology"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Component":"Java SDK","Platform":[{"code":"","label":""}],"Version":"","Edition":"","Line of Business":{"code":"LOB36","label":"IBM Automation"}}]

Document Information

Modified date:
15 June 2018

UID

swg21238470