1

The problem - I am receiving the following message:

java.lang.ClassCastException: com.ibm.connector2.cics.ECIConnectionFactory incompatible with com.ibm.connector2.cics.ECIConnectionFactory

I am receiving it when trying to make the following statement:

eisDci = (ECIConnectionFactory)ctx.lookup(eisn);

The 'eisDci' has been defined previously: private static ECIConnectionFactory eisDci = null;

And the 'eisn' is the String with the name of the conection like 'eis/DCIXxxxECI'

These connection is defined in the Server.xml:

<connectionFactory id="DCIXxxxECI" jndiName="eis/DCIXxxxECI">
        <properties.cicseci ServerName="XXXX" TPNName="xx" connectionUrl="url" portNumber="2006"/>
</connectionFactory>

I understand that this is warning me that the cast is not possible. What I don't know is what I'm doing wrong. That must be comparing one version of the ECIConnectionFactory class with a different version of ECIConnectionFactory.

The server I'm working with is a Liberty, I'm going crazy, I can't figure out why Eclipse is comparing two different versions.

Similar problems I have searched for:

ClassCastException when casting to the same class

Waxwing's answer seems good, but I don't have access to make those changes, This connection is carried out by an external library.

First Thank you for your answer Ben Cox, in Liberty's server.xml (for LOCAL) I have declared the library:

<fileset caseSensitive="false" dir="C:\CICSECI"/>

And in the Liberty Runtime/Shared/resources I have cicseci.rar which I have declared in the server.xml as a resourceAdapter:

<resourceAdapter autoStart="true" id="cicseci" location="${shared.resource.dir}/cicseci.rar">
    <classloader apiTypeVisibility="spec, ibm-api, api, third-party"/>
</resourceAdapter>

I have checked the rest of the libraries that I am importing into the project, and so far I have not seen that I have the repeated library.

Lastmonkey
  • 11
  • 3
  • 1
    Sounds like you've more than one JAR with ECIConnectionFactory on the classpath at runtime. Can you add to your question what dependencies - JARs - you're adding, and how? – Ben Cox Nov 22 '22 at 11:14
  • Glad to hear you got it fixed! Would you mind providing your answer as a proper answer below, and then ticking it to say it's an accepted answer? It'll help future visitors to know what fixed it for you. – Ben Cox Nov 28 '22 at 13:18

3 Answers3

0

I think the issue here has to do with classloading between your resource adapter and your application. This is something we more commonly see with DataSources but the results are the same.

The problem is that the same jar is being loaded by two different classloaders. One classloader for the resource adapter, and another classloader for your application. The solution is to use a commonLibraryRef

<library id=cicseci>
  <file name="${shared.resource.dir}/cicseci.rar"/>
</library>

<resourceAdapter autoStart="true" id="cicseciRA">
    <classloader commonLibraryRef="cicseci"/>
</resourceAdapter>

<connectionFactory id="DCIXxxxECI" jndiName="eis/DCIXxxxECI">
        <properties.cicseci ServerName="XXXX" TPNName="xx" connectionUrl="url" portNumber="2006"/>
</connectionFactory>

<!-- Location of app that is trying to cast ECIConnectionFactory -->
<application location="${shared.resource.dir}/cicseci.rar">
  <classloader commonLibraryRef="cicseci"/>
</application>

In this configuration, the cicseci.rar will only be loaded once.

KyleAure
  • 465
  • 4
  • 15
0

ClassCastException can happen when the same class is loaded by two different class loaders, making what otherwise looks like the same class incompatible.

The mechanism that you should be using to avoid this involves configuring the application's class loader with a classProviderRef to the resourceAdapter, which is documented here. For example,

<application location=...>
  <classloader classProviderRef="cicseci"/>
</application>
njr
  • 3,399
  • 9
  • 7
0

Already resolved

I import global libraries from different directories of my computer, in two of them the libraries were repeated with different versions, the obsolete versions were renamed, but it doesn't matter, the system recognized them as .jar and loaded them, producing the conflict.

I deleted the leftover libraries and it started working.

You have helped me a lot, and for that, Thank you.

Lastmonkey
  • 11
  • 3