ClassLoader.defineClass抛出的ClassCircularityError [英] ClassCircularityError thrown by ClassLoader.defineClass

查看:258
本文介绍了ClassLoader.defineClass抛出的ClassCircularityError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义类加载器加载类。在大多数情况下,一切正常,但有时当我加载特别复杂的项目/库时,我得到一个奇怪的错误:

I'm loading classes using a custom class loader. For the most part, everything works, but sometimes when I load particularly complex projects/libraries, I get a strange bug:

Exception in thread "main" java.lang.ClassCircularityError: 
  org/apache/commons/codec/binary/Hex
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:466)
    at my.custom.class.Loader.loadClass(...)

看着Javadocs,我不希望 defineClass 抛出这个特殊的错误。 org / apache / commons / codec / binary / Hex 是我正在尝试加载的类。这几乎就像 defineClass 在定义类之前想要一个类的副本 - 这对我来说毫无意义。

Looking at the Javadocs, I wouldn't expect defineClass to throw this particular error. org/apache/commons/codec/binary/Hex is the class I'm trying to load. It's almost as if defineClass wants a copy of the class before it'll define the class - which makes no sense to me.

想法?

推荐答案

当某些人抛出 ClassCircularityError class是一个(间接)超类本身,一些接口(间接)扩展自身或类似。

A ClassCircularityError is thrown when some class is a (indirect) superclass of itself, some interface (indirectly) extends itself or similar.

这通常不会发生,因为一个表现良好的编译器不会产生这样的类,但使用不同版本的库(或使用包含不同版本的类的几个库)可能会带来这个问题。

This should normally not occur as a well-behaved compiler will not produce such classes, but using different versions of a library (or using several libraries containing different versions of a class) could bring this problem.

扫描库中的双类名称,特别要看看上面提到的 org.apache.commons.codec.binary.Hex 类的多个版本。

Scan your libraries for double class names, in particular have a look if there are multiple versions of the mentioned org.apache.commons.codec.binary.Hex class.

这篇关于ClassLoader.defineClass抛出的ClassCircularityError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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