Skip to content

Commit

Permalink
NPE will occur when consumer lazy init and the consumer thread contex…
Browse files Browse the repository at this point in the history
…tClassLoader is null (#14478)

* hessian2 readObject NPE bugfix

* format the code

---------

Co-authored-by: wiam <[email protected]>
  • Loading branch information
Xwiam and wiam authored Aug 2, 2024
1 parent cec1643 commit feceeca
Showing 1 changed file with 10 additions and 9 deletions.
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

0 comments on commit feceeca

Please sign in to comment.