在重构后的泛型反序列化期间抛出java ClassNotFoundException(java ClassNotFoundException thrown during deserialization

编程入门 行业动态 更新时间:2024-10-25 02:21:30
在重构后的泛型反序列化期间抛出java ClassNotFoundException(java ClassNotFoundException thrown during deserialization of Generics following refactoring)

我重构(移动)了一堆类,现在我在尝试反序列化Session时遇到ClassNotFoundException 。 经典。

我创建了一个客户反序列化器SessionDeserializer extends ObjectInputStream ,它适用于大多数类,除了Generic类Result<T> 。

泛型类本身没有移动,所以我猜测问题在于已被移动的T对象类。

现在的问题是stacktrace没有指定T类:

java.lang.ClassNotFoundException: com.mysite.shared.beans.Result at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) ...

您是否知道解决此问题的方法:通过查找Result<T>对象中包含哪个T类并调整SessionDeserializer ,或者跳过Result<T>对象的反序列化?

编辑

添加了以下结果类:

public class Result<T> implements Serializable{ private static final long serialVersionUID=1L; protected T t=null; protected boolean success=false; protected Map<String,String> errors=new HashMap<String,String>(); protected String message=null; public void setData(T t){ this.t=t; } public T getData(){ return t; } public boolean isSuccess(){ return success; } public Map<String,String> getErrors(){ return errors; } public void setSuccess(boolean success){ this.success=success; } public void setErrors(Map<String,String> errors){ this.errors=errors; } protected void addError(String field, String msg){ errors.put(field,msg); } public String getMessage(){ return message; } public void setMessage(String message){ this.message=message; } }

I refactored (moved) a bunch of classes and now I am getting a ClassNotFoundException while trying to deserialize the Session. Classic.

I created a custome deserializer SessionDeserializer extends ObjectInputStream which works fine for most classes except for a Generic class Result<T>.

The generic class in itself hasn't moved, so I am guessing that the issue lies with the T object class which has been moved.

Now the issue is that the stacktrace doesn't specify the T class:

java.lang.ClassNotFoundException: com.mysite.shared.beans.Result at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714) ...

Do you know a way to work around this problem: either by finding which T class is contained inside the Result<T> object and adjusting the SessionDeserializer, or by skipping the deserialization of the Result<T> object alltogether?

EDIT

Added the result class below:

public class Result<T> implements Serializable{ private static final long serialVersionUID=1L; protected T t=null; protected boolean success=false; protected Map<String,String> errors=new HashMap<String,String>(); protected String message=null; public void setData(T t){ this.t=t; } public T getData(){ return t; } public boolean isSuccess(){ return success; } public Map<String,String> getErrors(){ return errors; } public void setSuccess(boolean success){ this.success=success; } public void setErrors(Map<String,String> errors){ this.errors=errors; } protected void addError(String field, String msg){ errors.put(field,msg); } public String getMessage(){ return message; } public void setMessage(String message){ this.message=message; } }

最满意答案

现在的问题是stacktrace没有指定T类。

那是因为这里不是T类问题。 问题是Result类。 信任异常消息。

我不能告诉你为什么类加载器找不到你的Result类,但可能的解释是:

Result类不在您的webapps类加载器的类路径中,或者 这个类取决于其他一些缺少的类,或者 此类对其初始化失败的其他类具有初始化依赖性。

Now the issue is that the stacktrace doesn't specify the T class.

That's because it is not the T class that is the problem here. The problem is the Result class. Trust the exception message.

I can't tell you why the classloader cannot find your Result class, but possible explanations are:

the Result class is not on your webapps classloader's classpath, or this class depends on some other class that is missing, or this class has an initialization dependency on some other class whose initialization has failed.

更多推荐

本文发布于:2023-07-31 20:07:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1347228.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:抛出   重构   序列化   泛型反   java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!