This is an automated email from the ASF dual-hosted git repository.

alexstocks pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git


The following commit(s) were added to refs/heads/3.0 by this push:
     new 16d8297  Fix: URL serialization bug (#1238)
16d8297 is described below

commit 16d8297b5d06c1a289fcd8a78d817087d3c248d4
Author: XavierNiu <[email protected]>
AuthorDate: Mon Jun 7 10:42:29 2021 +0800

    Fix: URL serialization bug (#1238)
    
    * unittests for DubboCodec
    
    * fix serializing url bug and add error handling
    
    * gofmt
---
 common/url.go                               |  5 ++++
 protocol/dubbo/hessian2/hessian_response.go | 37 ++++++++++++++++++++++-------
 2 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/common/url.go b/common/url.go
index 07bda8e..65d1748 100644
--- a/common/url.go
+++ b/common/url.go
@@ -125,6 +125,11 @@ type URL struct {
        SubURL *URL
 }
 
+// JavaClassName POJO for URL
+func (c *URL) JavaClassName() string {
+       return "org.apache.dubbo.common.URL"
+}
+
 // Option accepts URL
 // Option will define a function of handling URL
 type Option func(*URL)
diff --git a/protocol/dubbo/hessian2/hessian_response.go 
b/protocol/dubbo/hessian2/hessian_response.go
index b0070a6..47dc866 100644
--- a/protocol/dubbo/hessian2/hessian_response.go
+++ b/protocol/dubbo/hessian2/hessian_response.go
@@ -111,30 +111,49 @@ func packResponse(header DubboHeader, ret interface{}) 
([]byte, error) {
                        }
 
                        if response.Exception != nil { // throw error
-                               _ = encoder.Encode(resWithException)
+                               err := encoder.Encode(resWithException)
+                               if err != nil {
+                                       return nil, perrors.Errorf("encoding 
response failed: %v", err)
+                               }
                                if t, ok := 
response.Exception.(java_exception.Throwabler); ok {
-                                       _ = encoder.Encode(t)
+                                       err = encoder.Encode(t)
                                } else {
-                                       _ = 
encoder.Encode(java_exception.NewThrowable(response.Exception.Error()))
+                                       err = 
encoder.Encode(java_exception.NewThrowable(response.Exception.Error()))
+                               }
+                               if err != nil {
+                                       return nil, perrors.Errorf("encoding 
exception failed: %v", err)
                                }
                        } else {
                                if response.RspObj == nil {
-                                       _ = encoder.Encode(resNullValue)
+                                       if err := encoder.Encode(resNullValue); 
err != nil {
+                                               return nil, 
perrors.Errorf("encoding null value failed: %v", err)
+                                       }
                                } else {
-                                       _ = encoder.Encode(resValue)
-                                       _ = encoder.Encode(response.RspObj) // 
result
+                                       if err := encoder.Encode(resValue); err 
!= nil {
+                                               return nil, 
perrors.Errorf("encoding response value failed: %v", err)
+                                       }
+                                       if err := 
encoder.Encode(response.RspObj); err != nil {
+                                               return nil, 
perrors.Errorf("encoding response failed: %v", err)
+                                       }
                                }
                        }
 
+                       // attachments
                        if atta {
-                               _ = encoder.Encode(response.Attachments) // 
attachments
+                               if err := encoder.Encode(response.Attachments); 
err != nil {
+                                       return nil, perrors.Errorf("encoding 
response attachements failed: %v", err)
+                               }
                        }
                }
        } else {
+               var err error
                if response.Exception != nil { // throw error
-                       _ = encoder.Encode(response.Exception.Error())
+                       err = encoder.Encode(response.Exception.Error())
                } else {
-                       _ = encoder.Encode(response.RspObj)
+                       err = encoder.Encode(response.RspObj)
+               }
+               if err != nil {
+                       return nil, perrors.Errorf("encoding error failed: %v", 
err)
                }
        }
 

Reply via email to