apache / apache/dubbo

怎么配置才能让 hessian2 序列类型忽略 Serializable?

Open
#12,045 3 comments 0 reactions 0 assignees View on GitHub
type/bug
Dominant language
Java
Stars
41.6k
Forks
26.4k
Avg merge
15h 13m
Merged PRs (30d)
4

Description

dubbo 3.1.9 版本

我用的 spring-boot, 在配置文件里加入了
```
dubbo:
application:
# 关闭序列化严格检查
check-serializable: false
protocol:
serialization: hessian2
hessian:
allow-non-serializable: true
```
但仍然报 `must implement java.io.Serializable`.
我做了点研究,发现 allow-non-serializable 似乎无法生效,源码里用的

`serializerFactory.setAllowNonSerializable(Boolean.parseBoolean(System.getProperty("dubbo.hessian.allowNonSerializable", "false")));`

这样似乎只有 jvm 的 -D 配置才行?我不得已改了 jvm,但发现仍然报错,这回 isAllowNonSerializable 返回 true 了,但还是报错,追踪源码又发现了这个:

```
@Override
protected Deserializer getDefaultDeserializer(Class cl) {
try {
// pre-check if class is allow
defaultSerializeClassChecker.loadClass(getClassLoader(), cl.getName());
} catch (ClassNotFoundException e) {
// ignore
}

if (!Serializable.class.isAssignableFrom(cl)
&& (!isAllowNonSerializable() || !defaultSerializeClassChecker.isCheckSerializable())) {
throw new IllegalStateException("Serialized class " + cl.getName() + " must implement java.io.Serializable");
}

return new JavaDeserializer(cl);
}
```

这个 !isAllowNonSerializable() || !defaultSerializeClassChecker.isCheckSerializable() 的判断让我搞不懂了,两个都必须是 true 才行?也就是 check-serializable 需要打开,而我打开了 check-serializable

轮到 loadClass 里面报错了,这到底应该怎么整啊??

Contributor guide

Open the contributing guide

Research direction

Start by tracing the Spring Boot configuration for check-serializable and hessian.allow-non-serializable into the serializerFactory settings. Then inspect getDefaultDeserializer and defaultSerializeClassChecker.loadClass to determine which condition still rejects the class. Done means identifying the effective configuration path and confirming that a non-Serializable Hessian2 class can be deserialized without the exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.