Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPE will occur when consumer lazy init and the consumer thread contextClassLoader is null #14478

Merged
merged 3 commits into from
Aug 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.util.Objects;

import com.alibaba.com.caucho.hessian.io.Hessian2Input;

Expand Down Expand Up @@ -96,9 +97,9 @@ public String readUTF() throws IOException {

@Override
public Object readObject() throws IOException {
if (!mH2i.getSerializerFactory()
.getClassLoader()
.equals(Thread.currentThread().getContextClassLoader())) {
if (!Objects.equals(
mH2i.getSerializerFactory().getClassLoader(),
Thread.currentThread().getContextClassLoader())) {
mH2i.setSerializerFactory(hessian2FactoryManager.getSerializerFactory(
Thread.currentThread().getContextClassLoader()));
}
Expand All @@ -108,9 +109,9 @@ public Object readObject() throws IOException {
@Override
@SuppressWarnings("unchecked")
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
if (!mH2i.getSerializerFactory()
.getClassLoader()
.equals(Thread.currentThread().getContextClassLoader())) {
if (!Objects.equals(
mH2i.getSerializerFactory().getClassLoader(),
Thread.currentThread().getContextClassLoader())) {
mH2i.setSerializerFactory(hessian2FactoryManager.getSerializerFactory(
Thread.currentThread().getContextClassLoader()));
}
Expand All @@ -119,9 +120,9 @@ public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException

@Override
public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
if (!mH2i.getSerializerFactory()
.getClassLoader()
.equals(Thread.currentThread().getContextClassLoader())) {
if (!Objects.equals(
mH2i.getSerializerFactory().getClassLoader(),
Thread.currentThread().getContextClassLoader())) {
mH2i.setSerializerFactory(hessian2FactoryManager.getSerializerFactory(
Thread.currentThread().getContextClassLoader()));
}
Expand Down
Loading