You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If there is a BigInteger type in the defined interface return class or parameter type, an exception will be thrown when native-image is compiled, prompting java.lang.StackOverflowError
After investigation, it was caused by the imprecise implementation of the registerSerializationType method in AotUtils. The specific code:
Therefore, AotUtils will throw an exception when encountering BigInteger;
In the same way, if there are two classes that are each other's Field, a java.lang.StackOverflowError exception will also be thrown, for example:
class A implements Serializable{
private B b;
}
class B implements Serializable{
private A a;
}
Solution
In order to solve the infinite loop caused by similar circular dependencies, a variable of type Set<Class<?>> is added for deduplication judgment. The modified AotUtils code is as follows
Environment
Steps to reproduce this issue
If there is a BigInteger type in the defined interface return class or parameter type, an exception will be thrown when native-image is compiled, prompting
java.lang.StackOverflowError
After investigation, it was caused by the imprecise implementation of the
registerSerializationType
method inAotUtils
. The specific code:If there is a Field of its own type in the
registerType
type, it will fall into an infinite loop, for example:Based on the above analysis, we look at the BigInteger source code, which has similar code as follows:
Therefore,
AotUtils
will throw an exception when encounteringBigInteger
;In the same way, if there are two classes that are each other's Field, a
java.lang.StackOverflowError
exception will also be thrown, for example:Solution
In order to solve the infinite loop caused by similar circular dependencies, a variable of type Set<Class<?>> is added for deduplication judgment. The modified
AotUtils
code is as followsEnvironment
Steps to reproduce this issue
如果定义的接口返回类或参数类型中存在BigInteger类型,在native-image编译时,会抛出异常,提示
java.lang.StackOverflowError
经排查是
AotUtils
中registerSerializationType
方法的实现不严谨造成的,具体代码:如果
registerType
类型中存在以自己为类型的Field,就会陷入死循环,比如:根据上面分析,我们查看BigInteger源码,其存在类似的如下代码:
因此
AotUtils
遇到BigInteger
时会抛出异常;同理,如果存在两个类,互为对方的Field,也会抛出
java.lang.StackOverflowError
异常,例如:解决办法
为解决类似循环依赖造成的死循环,增加一个Set<Class<?>>类型的变量,用于去重判断,修改后的
AotUtils
代码如下The text was updated successfully, but these errors were encountered: