gpt4 book ai didi

java - java.lang.ClassCastException : someClass incompatible with someClass 的含义

转载 作者:搜寻专家 更新时间:2023-10-30 19:55:58 33 4
gpt4 key购买 nike

我在 XPages 应用程序中遇到偶尔的异常:

java.lang.ClassCastException: someClass incompatible with someClass.

两个提到的类是相同的,都是用作 session bean 的类。我无法用谷歌搜索任何涵盖我的问题的内容。对此的通常解释是设计元素的变化,而不是我的情况。

从那一刻起,XPage 应用程序变得不可用(页面使用 session bean someClass),直到重新启动 http 任务或重新保存 faces-config.xml。

在某些情况下,这与其他异常有关:

com.ibm.jscript.InterpretException: Script interpreter error, line=x, col=y: 
Java method 'method(signature containg someClass)'
on java class 'someOtherClass' not found

这种行为背后的原因是什么?

最佳答案

Philippe Riand 通过电子邮件对此进行了解释:

This class cast happens because the same class had been loaded twice by 2 different class loaders. Thus, from a Java standpoint, they are different and the cast fails.

Now, each XPages application is having its own classloader. But this class loader is discarded each time a design change happens to the application, through Domino Designer for example. This is required as a change to an XPages generates a new Java class that should then be loaded instead of the previous one. When this happens, the classloader is discarded and a new is created. Then all the application related classes are reloaded, as they are needed, even though they didn't change.This is a common behavior implemented by J2EE servers. That said, if your code is caching an object in a scope that is not discarded when a design change occurs, then this is likely to happen. For example, the applicationScope & sessionScope are currently not discarded when a design change happens, which might lead to this problem. This was a design choice as discarding the scopes sometimes provides a bad developer experience, but with this drawback.

Finally, saving faces-config.xml works as a workaround. When this file is saved, then the entire module is discarded from memory, including the scopes, This explains why it works. Making a change to your custom Java class should reload the module and remove the issue.

所以似乎将 beans(甚至间接地)放入 sessionScope 或 applicationScope 中是原因。

关于java - java.lang.ClassCastException : someClass incompatible with someClass 的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5352550/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com