This is an automated email from the ASF dual-hosted git repository.
crazyhzm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-dubbo.git
The following commit(s) were added to refs/heads/master by this push:
new a6c8835 [Dubbo-3727] Fix NullPointerException when protocoluff
protocol serializes an empty object (#3734)
a6c8835 is described below
commit a6c88357cfdc9816bc34bf3c18e263894996779e
Author: zhangfei <[email protected]>
AuthorDate: Tue Mar 26 17:21:53 2019 +0800
[Dubbo-3727] Fix NullPointerException when protocoluff protocol serializes
an empty object (#3734)
* fix: #3727
* style: code tidy up
* style: add apache license
---
.../protostuff/ProtostuffObjectOutput.java | 2 +-
.../protostuff/ProtostuffObjectOutputTest.java | 54 ++++++++++++++++++++++
2 files changed, 55 insertions(+), 1 deletion(-)
diff --git
a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java
b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java
index f52c755..ab94d3b 100644
---
a/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java
+++
b/dubbo-serialization/dubbo-serialization-protostuff/src/main/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutput.java
@@ -47,7 +47,7 @@ public class ProtostuffObjectOutput implements ObjectOutput {
byte[] classNameBytes;
try {
- if (WrapperUtils.needWrapper(obj)) {
+ if (obj == null || WrapperUtils.needWrapper(obj)) {
Schema<Wrapper> schema =
RuntimeSchema.getSchema(Wrapper.class);
Wrapper wrapper = new Wrapper(obj);
bytes = GraphIOUtil.toByteArray(wrapper, schema, buffer);
diff --git
a/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java
b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java
new file mode 100644
index 0000000..bb28386
--- /dev/null
+++
b/dubbo-serialization/dubbo-serialization-test/src/test/java/org/apache/dubbo/common/serialize/protostuff/ProtostuffObjectOutputTest.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.dubbo.common.serialize.protostuff;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.nullValue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+public class ProtostuffObjectOutputTest {
+
+ private ByteArrayOutputStream byteArrayOutputStream;
+ private ProtostuffObjectOutput protostuffObjectOutput;
+ private ProtostuffObjectInput protostuffObjectInput;
+ private ByteArrayInputStream byteArrayInputStream;
+
+ @BeforeEach
+ public void setUp() throws Exception {
+ this.byteArrayOutputStream = new ByteArrayOutputStream();
+ this.protostuffObjectOutput = new
ProtostuffObjectOutput(byteArrayOutputStream);
+ }
+
+ @Test
+ public void testWriteObjectNull() throws IOException,
ClassNotFoundException {
+ this.protostuffObjectOutput.writeObject(null);
+ this.flushToInput();
+
+ assertThat(protostuffObjectInput.readObject(), nullValue());
+ }
+
+ private void flushToInput() throws IOException {
+ this.protostuffObjectOutput.flushBuffer();
+ this.byteArrayInputStream = new
ByteArrayInputStream(byteArrayOutputStream.toByteArray());
+ this.protostuffObjectInput = new
ProtostuffObjectInput(byteArrayInputStream);
+ }
+}