Javassist在hibernate中失败:无效的常量类型:60 [英] Javassist failure in hibernate: invalid constant type: 60

查看:156
本文介绍了Javassist在hibernate中失败:无效的常量类型:60的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个cli工具来管理现有的应用程序。应用程序和测试都可以正常运行并且运行正常,但是尽管如此,在运行jar中存在的cli工具时,我仍然收到javassist失败:

I'm creating a cli tool to manage an existing application. Both the application and the tests build fine and run fine but despite that I receive a javassist failure when running my cli tool that exists within the jar:

INFO: Bytecode provider name : javassist
...
INFO: Hibernate EntityManager 3.5.1-Final
Exception in thread "main" javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
        ...
        at com.sophware.flexipol.admin.AdminTool.<init>(AdminTool.java:40)
        at com.sophware.flexipol.admin.AdminTool.main(AdminTool.java:69)
Caused by: java.lang.RuntimeException: Error while reading file:flexipol-jar-with-dependencies.jar
        at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:131)
        at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:467)
        at org.hibernate.ejb.Ejb3Configuration.addMetadataFromScan(Ejb3Configuration.java:457)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:347)
        ... 11 more
Caused by: java.io.IOException: invalid constant type: 60
        at javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
        at javassist.bytecode.ConstPool.read(ConstPool.java:970)
        at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
        at javassist.bytecode.ClassFile.read(ClassFile.java:693)
        at javassist.bytecode.ClassFile.<init>(ClassFile.java:85)
        at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:243)
        at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:209)
        at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:170)
        at org.hibernate.ejb.packaging.FileZippedJarVisitor.doProcessElements(FileZippedJarVisitor.java:119)
        at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:146)
        at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:128)
        ... 14 more

由于我知道jar在单元和集成测试中运行时很好,我认为这可能是javassist的一个问题,所以我尝试了cglib。字节码提供程序然后显示为cglib,但仍然得到与javassist中存在的完全相同的堆栈跟踪。

Since I know the jar is fine as the unit and integration tests run against it, I thought it might be a problem with javassist, so I tried cglib. The bytecode provider then shows as cglib but I still get the exact same stack trace with javassist present in it.

cglib绝对在类路径中:

cglib is definitely in the classpath:

$ unzip -l flexipol-jar-with-dependencies.jar | grep cglib | wc -l
383

我试过了hibernate 3.4和3.5,完全相同的错误。这是javassist的问题吗?

I've tried with both hibernate 3.4 and 3.5 and get the exact same error. Is this a problem with javassist?

更新:我可以在Eclipse中成功运行应用程序(右键单击 - >运行方式 - > Java应用程序),但使用Maven生成的jar -with-dependencies失败。我认为与Eclipse不同的是,javassist不检查包含的jar,而是检查所有的类文件(也可能是一些依赖的第三方jar)。

UPDATE: I can run the application successfully within Eclipse (Right click->Run As->Java Application), but using the maven-generated jar-with-dependencies fails. I presume the difference is that with Eclipse javassist isn't inspecting the containing jar, rather, it's inspecting all of the class files (and perhaps a few dependent 3rd-party jars).

推荐答案

这个问题最终是由 icu4j-2.6.1 中的无效类引起的,如此帖子。具体而言,此文件无效:

The problem is ultimately caused by an invalid class in icu4j-2.6.1 as can be seen in this post. Specifically, this file is invalid:

com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class

以下是识别损坏文件的简单方法:

Here's a simple way to identify a corrupt file:

for x in PATH_TO_EXTRACTED_JAR/**/*.class; do
    java -cp PATH_TO/javassist.jar javassist.tools.Dump $x >/dev/null 2>&1 || echo "$x is invalid"
done

这个文件被maven间接包含通过它的传递依赖性,这就是为什么我没有认识到该页面引用错误和jar中包含的文件作为问题的罪魁祸首和原因。下面是它如何被包含在我的jar-with-dependencies包中:

This file is being included by indirectly by maven through its transitive dependencies which is why I didn't recognize that page as referencing the error and a file contained within the jar as being the culprit and cause of the problem. Here's how it ended up included in my jar-with-dependencies bundle:

jaxen-1.1.1 -> xom-1.0 -> icu4j-2.6.1

将以下排除添加到 jaxen code>依赖关系,一切正常工作对我来说(但要小心,如果你需要它的本地化部分):

After adding the following exclusion to the jaxen dependency, everything worked correctly for me (but be careful if you need its localization pieces):

<exclusions>
    <exclusion>
        <groupId>com.ibm.icu</groupId>
        <artifactId>icu4j</artifactId>
    </exclusion>
</exclusions>

另一个选项是从jar文件中删除有问题的文件:

Another option would be to remove the offending file(s) from the jar file:

#!/bin/sh                                                                                                                                                                                                                                    
shopt -s extglob
shopt -s globstar
for x in **/*.jar ; do
    zip -d $x 'com/ibm/icu/impl/data/*_zh*' >/dev/null 2>&1 && echo "Removed corrupted files from $x"
done

这篇关于Javassist在hibernate中失败:无效的常量类型:60的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆