From f13bb4e83a904a0cfb90aabc7c9edf46fc7365dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tiltwind=28=E6=96=9C=E9=A3=8E=29?= <116183822+tiltwind@users.noreply.github.com> Date: Tue, 14 Feb 2023 09:44:49 +0800 Subject: [PATCH 1/7] mark array types deprecated (#347) * mark array types deprected * mark array types deprecated --- array.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/array.go b/array.go index 30593d50..5a9c5709 100644 --- a/array.go +++ b/array.go @@ -33,6 +33,7 @@ func init() { } // BooleanArray Boolean[] +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type BooleanArray struct { Values []bool } @@ -60,7 +61,8 @@ func (*BooleanArray) JavaClassName() string { return "[java.lang.Boolean" } -// IntegerArray Integer[] +// IntegerArray Integer[]. +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type IntegerArray struct { Values []int32 } @@ -89,6 +91,7 @@ func (*IntegerArray) JavaClassName() string { } // ByteArray Byte[] +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type ByteArray struct { Values []uint8 } @@ -117,6 +120,7 @@ func (*ByteArray) JavaClassName() string { } // ShortArray Short[] +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type ShortArray struct { Values []int16 } @@ -145,6 +149,7 @@ func (*ShortArray) JavaClassName() string { } // LongArray Long[] +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type LongArray struct { Values []int64 } @@ -173,6 +178,7 @@ func (*LongArray) JavaClassName() string { } // FloatArray Float[] +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type FloatArray struct { Values []float32 } @@ -201,6 +207,7 @@ func (*FloatArray) JavaClassName() string { } // DoubleArray Double[] +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type DoubleArray struct { Values []float64 } @@ -229,6 +236,7 @@ func (*DoubleArray) JavaClassName() string { } // CharacterArray Character[] +// Deprecated: it will not be supported in next major version, being replaced by a slice type instead. type CharacterArray struct { Values string } From 4cd8b9da65a875f7b222fea8b76d693edfb0cc25 Mon Sep 17 00:00:00 2001 From: "Xin.Zh" Date: Tue, 14 Feb 2023 11:34:56 +0800 Subject: [PATCH 2/7] Update README.md change readme title --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b454844c..1e8a81af 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# gohessian +# dubbo-go-hessian2 [![Build Status](https://travis-ci.org/apache/dubbo-go-hessian2.png?branch=master)](https://travis-ci.org/apache/dubbo-go-hessian2) [![codecov](https://codecov.io/gh/apache/dubbo-go-hessian2/branch/master/graph/badge.svg)](https://codecov.io/gh/apache/dubbo-go-hessian2) From f0ac0a67b3e1e3e9b71131ffd1d2466b65875883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tiltwind=28=E6=96=9C=E9=A3=8E=29?= <116183822+tiltwind@users.noreply.github.com> Date: Fri, 24 Feb 2023 21:24:20 +0800 Subject: [PATCH 3/7] upgrade go to v1.17 to fix issue #348 (#352) --- .github/workflows/github-actions.yml | 2 +- date.go | 6 +++--- date_test.go | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.github/workflows/github-actions.yml b/.github/workflows/github-actions.yml index 132f03e4..0e304f57 100644 --- a/.github/workflows/github-actions.yml +++ b/.github/workflows/github-actions.yml @@ -19,7 +19,7 @@ jobs: os: - ubuntu-latest go_version: - - 1.13 + - 1.17 jdk_version: - 1.8 env: diff --git a/date.go b/date.go index 0b5329aa..4fa6b259 100644 --- a/date.go +++ b/date.go @@ -42,12 +42,12 @@ func encDateInMs(b []byte, i interface{}) []byte { return append(b, BC_NULL) } b = append(b, BC_DATE) - return append(b, PackInt64(vi.UnixNano()/1e6)...) + return append(b, PackInt64(vi.UnixMilli())...) } -func encDateInMimute(b []byte, v time.Time) []byte { +func encDateInMinute(b []byte, v time.Time) []byte { b = append(b, BC_DATE_MINUTE) - return append(b, PackInt32(int32(v.UnixNano()/60e9))...) + return append(b, PackInt32(int32(v.Unix()/60))...) } ///////////////////////////////////////// diff --git a/date_test.go b/date_test.go index f0a8b6f3..2954ffc6 100644 --- a/date_test.go +++ b/date_test.go @@ -66,6 +66,22 @@ func TestEncDate(t *testing.T) { d = NewDecoder(e.Buffer()) res, err = d.Decode() t.Logf("decode(%s, %s) = %v, %v\n", v, tz.Local(), res, err) + assert.Equal(t, tz.Local(), res) +} + +func TestEncDateIssue348(t *testing.T) { + e := NewEncoder() + v := "2914-02-09 06:15:23" + tz, _ := time.Parse("2006-01-02 15:04:05", v) + e.Encode(tz) + if len(e.Buffer()) == 0 { + t.Fail() + } + + d := NewDecoder(e.Buffer()) + res, err := d.Decode() + t.Logf("decode(%s, %s) = %v, %v\n", v, tz.Local(), res, err) + assert.Equal(t, tz.Local(), res) } func testDateFramework(t *testing.T, method string, expected time.Time) { From 8390f137edd9e37f2b086453f0db70596fc7df10 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:35:20 +0800 Subject: [PATCH 4/7] Bump dubbo from 2.7.18 to 2.7.21 in /test_dubbo (#354) Bumps [dubbo](https://github.com/apache/dubbo) from 2.7.18 to 2.7.21. - [Release notes](https://github.com/apache/dubbo/releases) - [Changelog](https://github.com/apache/dubbo/blob/3.2/CHANGES.md) - [Commits](https://github.com/apache/dubbo/compare/dubbo-2.7.18...dubbo-2.7.21) --- updated-dependencies: - dependency-name: org.apache.dubbo:dubbo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- test_dubbo/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_dubbo/pom.xml b/test_dubbo/pom.xml index ce12c8c1..5e6a2145 100644 --- a/test_dubbo/pom.xml +++ b/test_dubbo/pom.xml @@ -31,7 +31,7 @@ org.apache.dubbo dubbo - 2.7.18 + 2.7.21 compile From 76ae75b37ae4fc6bf213c664fe95cea40fe72514 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 15 Mar 2023 16:36:08 +0800 Subject: [PATCH 5/7] Bump dubbo from 2.7.18 to 2.7.21 in /test_hessian (#355) Bumps [dubbo](https://github.com/apache/dubbo) from 2.7.18 to 2.7.21. - [Release notes](https://github.com/apache/dubbo/releases) - [Changelog](https://github.com/apache/dubbo/blob/3.2/CHANGES.md) - [Commits](https://github.com/apache/dubbo/compare/dubbo-2.7.18...dubbo-2.7.21) --- updated-dependencies: - dependency-name: org.apache.dubbo:dubbo dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- test_hessian/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_hessian/pom.xml b/test_hessian/pom.xml index 93a9824f..4989f6dd 100644 --- a/test_hessian/pom.xml +++ b/test_hessian/pom.xml @@ -45,7 +45,7 @@ org.apache.dubbo dubbo - 2.7.18 + 2.7.21 com.alibaba From 33f7e9deb352bb7eccf305a806172ae52781b166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tiltwind=28=E6=96=9C=E9=A3=8E=29?= <116183822+tiltwind@users.noreply.github.com> Date: Sun, 9 Apr 2023 23:59:16 +0800 Subject: [PATCH 6/7] fix issue 356 that ref to wrong type of map for nil value (#357) * fix issue 356 * fix issue 356 * fix issue 356 --- map.go | 2 +- ref.go | 29 +++++++----- testcases/issue356/issue356_test.go | 68 +++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 testcases/issue356/issue356_test.go diff --git a/map.go b/map.go index 13367562..f005324e 100644 --- a/map.go +++ b/map.go @@ -117,7 +117,7 @@ func (e *Encoder) encMap(m interface{}) error { value = UnpackPtrValue(value) // check nil map - if value.Kind() == reflect.Ptr && !value.Elem().IsValid() { + if value.IsNil() || (value.Kind() == reflect.Ptr && !value.Elem().IsValid()) { e.buffer = EncNull(e.buffer) return nil } diff --git a/ref.go b/ref.go index f8926013..0767ca07 100644 --- a/ref.go +++ b/ref.go @@ -29,6 +29,9 @@ import ( // Empty slice is not nil, but the addresses of all empty slice are the same. var _emptySliceAddr = unsafe.Pointer(reflect.ValueOf([]interface{}{}).Pointer()) +// The addresses of all nil map are the same. +var _nilMapAddr = unsafe.Pointer(reflect.ValueOf(map[interface{}]interface{}(nil)).Pointer()) + // used to ref object,list,map type _refElem struct { // record the kind of target, objects are the same only if the address and kind are the same @@ -127,20 +130,22 @@ func (e *Encoder) checkRefMap(v reflect.Value) (int, bool) { } } - if addr != _emptySliceAddr { - if elem, ok := e.refMap[addr]; ok { - if elem.kind == kind { - // If kind is not struct, just return the index. Otherwise, - // check whether the types are same, because the different - // empty struct may share the same address and kind. - if elem.kind != reflect.Struct { - return elem.index, ok - } else if elem.tp == tp { - return elem.index, ok - } + if addr == _emptySliceAddr || addr == _nilMapAddr { + return 0, false + } + + if elem, ok := e.refMap[addr]; ok { + if elem.kind == kind { + // If kind is not struct, just return the index. Otherwise, + // check whether the types are same, because the different + // empty struct may share the same address and kind. + if elem.kind != reflect.Struct { + return elem.index, ok + } else if elem.tp == tp { + return elem.index, ok } - return 0, false } + return 0, false } n := len(e.refMap) diff --git a/testcases/issue356/issue356_test.go b/testcases/issue356/issue356_test.go new file mode 100644 index 00000000..d6175d54 --- /dev/null +++ b/testcases/issue356/issue356_test.go @@ -0,0 +1,68 @@ +/* + * 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 issue356 + +import ( + "reflect" + "testing" +) + +import ( + hessian "github.com/apache/dubbo-go-hessian2" +) + +import ( + "github.com/stretchr/testify/assert" +) + +type UserInfo struct { + Name string + Address map[string]string + Family map[string]int +} + +func (UserInfo) JavaClassName() string { + return "com.test.UserInfo" +} + +func TestIssue356Case(t *testing.T) { + info := &UserInfo{ + Name: "test", + Address: nil, + Family: nil, + } + + hessian.RegisterPOJO(info) + + encoder := hessian.NewEncoder() + err := encoder.Encode(info) + if err != nil { + t.Error(err) + return + } + + enBuf := encoder.Buffer() + + decoder := hessian.NewDecoder(enBuf) + dec, err := decoder.Decode() + assert.Nil(t, err) + + t.Log(dec) + + assert.True(t, reflect.DeepEqual(info, dec)) +} From a55bacdfe4aa684f0bef4107a758d39f68e3bc8c Mon Sep 17 00:00:00 2001 From: tiltwind Date: Mon, 10 Apr 2023 00:07:08 +0800 Subject: [PATCH 7/7] release note for v1.12.1 --- CHANGE.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGE.md b/CHANGE.md index 9e6c769a..ca475c09 100644 --- a/CHANGE.md +++ b/CHANGE.md @@ -1,5 +1,15 @@ # Release Notes +## v1.12.1 + +### Bugfixes +- fix ref to wrong type of map for nil value. [#357](https://github.com/apache/dubbo-go-hessian2/pull/357) + +## v1.12.0 + +### New Features +- support java wrapper types. [#350](https://github.com/apache/dubbo-go-hessian2/pull/350) + ## v1.11.5 ### Bugfixes