Skip to content

handle typed nil pointers in Encode method (apache/dubbo-go#2517) #376

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Nexusrex18
Copy link

This PR fixes the issue where the Encode method in encode.go did not properly handle typed nil pointers (e.g., (*int32)(nil)). The changes ensure that such pointers are encoded as Hessian NULL ('N').

Changes:

  • Modified encode.go to add a reflect-based check for typed nil pointers.
  • Added tests in encode_test.go to verify the behavior for typed nil pointers, untyped nil, and non-nil pointers.
  • Fixed TestUserDefinedException in decode_test.go by:
  • Updating getJavaReply to handle non-zero exit statuses from the Java program.
  • Correcting the Java class name to com.test.UserDefinedException and updating TestThrowable.java accordingly.

Fixes apache/dubbo-go#2517 (Ref: apache/dubbo-go#2517)

This PR is a prerequisite for the corresponding changes in apache/dubbo-go.

@@ -81,6 +81,10 @@ func getJavaReply(method, className string) []byte {
cmd := exec.Command("java", cmdArgs...)
out, err := cmd.Output()
if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why ignore the the exec.ExitError?

@@ -92,6 +92,36 @@ func testSimpleEncode(t *testing.T, v interface{}) {
assert.Nil(t, err)
}

func TestEncodeTypedNilPointer(t *testing.T) {
encoder := NewEncoder()
var val *int32 = nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we define *int32 as java.lang.Integer,

got, err := decodeJavaResponse(`customReplyJavaIntegerArray`, ``, false)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dubbo protocol and dubbo-go-hessian2 can not process (*int32)(nil) corner case
2 participants