Skip to content

Commit feceeca

Browse files
Xwiamwiam
andauthored
NPE will occur when consumer lazy init and the consumer thread contextClassLoader is null (#14478)
* hessian2 readObject NPE bugfix * format the code --------- Co-authored-by: wiam <[email protected]>
1 parent cec1643 commit feceeca

File tree

1 file changed

+10
-9
lines changed
  • dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2

1 file changed

+10
-9
lines changed

dubbo-serialization/dubbo-serialization-hessian2/src/main/java/org/apache/dubbo/common/serialize/hessian2/Hessian2ObjectInput.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.io.IOException;
2424
import java.io.InputStream;
2525
import java.lang.reflect.Type;
26+
import java.util.Objects;
2627

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

@@ -96,9 +97,9 @@ public String readUTF() throws IOException {
9697

9798
@Override
9899
public Object readObject() throws IOException {
99-
if (!mH2i.getSerializerFactory()
100-
.getClassLoader()
101-
.equals(Thread.currentThread().getContextClassLoader())) {
100+
if (!Objects.equals(
101+
mH2i.getSerializerFactory().getClassLoader(),
102+
Thread.currentThread().getContextClassLoader())) {
102103
mH2i.setSerializerFactory(hessian2FactoryManager.getSerializerFactory(
103104
Thread.currentThread().getContextClassLoader()));
104105
}
@@ -108,9 +109,9 @@ public Object readObject() throws IOException {
108109
@Override
109110
@SuppressWarnings("unchecked")
110111
public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException {
111-
if (!mH2i.getSerializerFactory()
112-
.getClassLoader()
113-
.equals(Thread.currentThread().getContextClassLoader())) {
112+
if (!Objects.equals(
113+
mH2i.getSerializerFactory().getClassLoader(),
114+
Thread.currentThread().getContextClassLoader())) {
114115
mH2i.setSerializerFactory(hessian2FactoryManager.getSerializerFactory(
115116
Thread.currentThread().getContextClassLoader()));
116117
}
@@ -119,9 +120,9 @@ public <T> T readObject(Class<T> cls) throws IOException, ClassNotFoundException
119120

120121
@Override
121122
public <T> T readObject(Class<T> cls, Type type) throws IOException, ClassNotFoundException {
122-
if (!mH2i.getSerializerFactory()
123-
.getClassLoader()
124-
.equals(Thread.currentThread().getContextClassLoader())) {
123+
if (!Objects.equals(
124+
mH2i.getSerializerFactory().getClassLoader(),
125+
Thread.currentThread().getContextClassLoader())) {
125126
mH2i.setSerializerFactory(hessian2FactoryManager.getSerializerFactory(
126127
Thread.currentThread().getContextClassLoader()));
127128
}

0 commit comments

Comments
 (0)