Class cast exceptions with ant/jenkins generated EAR on WebSphere 6.1

我怕爱的太早我们不能终老 提交于 2019-12-11 09:51:07

问题


I'm having runtime class cast exceptions after deploying an ear generated as part of an ant build script running on Jenkins to Websphere 6.1. The cast class exceptions are in some DAO methods which cast Objects returned from SQL queries to specific classes.

If i generate the EAR from within Eclipse (RAD) then the class cast exceptions don't occur, and comparing the class files from the jenkins/ant generated ear with the ones from Eclipse show different file sizes and contents.

I'm trying to make ant execute javac with the JDK supplied with Webspehre 6.1. so I've set up a multi configuration project in Jenkins to use the IBM JDK. I'm assuming that this make the ant javac task use this jdk.

This is my ant javac task:

    <javac srcdir="${src.dir}" destdir="${build.dir}"  debug="true"  debuglevel="vars,lines,source" target="1.5">
        <classpath refid="master-classpath" />
    </javac>

The only thing I can think of now is to make sure that ant actually runs with this jdk as opposed to just executing javac with this jdk. Is there a way to check?

[edit] I 've changed the ant.bat file to output JAVA_HOME and it does run under the one I specify in jenkins.

[edit2]

Ok, finally found the cause of the problem:

In a Hibernate DAO method we have some (poor) code like this:

String sql = "select {entity.*}, {entity2.*}, ...";
SQLQuery  query = sessionFactory.getCurrentSession().createSQLQuery(sql);
...
List<Entity> queryResult = query.list();
for (Object row : queryResult) {
     Object[] arr = (Object[])row;
     Entity entity - (Entity)arr[0];
     Entity2 entity2 - (Entity2)arr[1];
}

Can you spot the schoolboy error?

queryResult is not a List<Entity> but a List<Object[]> - the class cast exception was occuring on for (Object row : queryResult)

So, now my question is - what happened to type erasure?

And what compiler option is Eclipse using that allows it to ignore, at runtime, class casts errors like this?


回答1:


It's possible it's not the JDK, but other libraries which are different. Worth checking.



来源:https://stackoverflow.com/questions/8091753/class-cast-exceptions-with-ant-jenkins-generated-ear-on-websphere-6-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!