Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?

log.Printf("Java command exited with status %d: %s", exitErr.ExitCode(), string(out))
return out
}
log.Fatal(cmd.Args, err)
}
return out
Expand Down
6 changes: 6 additions & 0 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ func (e *Encoder) Encode(v interface{}) error {
return nil
}

vVal := reflect.ValueOf(v)
if vVal.Kind() == reflect.Ptr && vVal.IsNil() {
e.buffer = EncNull(e.buffer)
return nil
}

switch val := v.(type) {
case nil:
e.buffer = EncNull(e.buffer)
Expand Down
30 changes: 30 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

err := encoder.Encode(val)
assert.Nil(t, err)

expected := []byte{'N'}
assertEqual(expected, encoder.Buffer(), t)
}

func TestEncodeUntypedNil(t *testing.T) {
encoder := NewEncoder()
err := encoder.Encode(nil)
assert.Nil(t, err)

expected := []byte{'N'}
assertEqual(expected, encoder.Buffer(), t)
}

func TestEncodeNonNilPointer(t *testing.T) {
encoder := NewEncoder()
val := int32(42)
ptr := &val
err := encoder.Encode(ptr)
assert.Nil(t, err)

expected := []byte{0xba}
assertEqual(expected, encoder.Buffer(), t)
}

type BenchData struct {
name string
}
Expand Down
2 changes: 1 addition & 1 deletion test_hessian/src/main/java/test/TestThrowable.java
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ public static Object throw_AnnotationTypeMismatchException() {
}

public static Object throw_UserDefinedException() {
return new UserDefindException("throw UserDefinedException");
return new UserDefinedException("throw UserDefinedException");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package test;

public class UserDefindException extends RuntimeException{
public UserDefindException(String dd){
public class UserDefinedException extends RuntimeException{
public UserDefinedException(String dd){
super(dd);
}
}