This is an automated email from the ASF dual-hosted git repository. liubao pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push: new 8d77264 [SCB-669] add extra hashcode into CtTypeJavaType to avoid deserialization problem 8d77264 is described below commit 8d7726472c1d59a367fd96110453ca49c28e626a Author: yaohaishi <yaohai...@huawei.com> AuthorDate: Thu Jun 14 13:05:23 2018 +0800 [SCB-669] add extra hashcode into CtTypeJavaType to avoid deserialization problem --- .../common/javassist/CtTypeJavaType.java | 20 +++++++++-- .../common/javassist/TestCtTypeJavaType.java | 41 ++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java index 1ef4cec..74c083c 100644 --- a/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java +++ b/common/common-javassist/src/main/java/org/apache/servicecomb/common/javassist/CtTypeJavaType.java @@ -16,7 +16,10 @@ */ package org.apache.servicecomb.common.javassist; +import java.util.Objects; + import com.fasterxml.jackson.databind.type.SimpleType; +import com.fasterxml.jackson.databind.type.TypeBindings; /** * just a wrapper for CtType @@ -28,7 +31,9 @@ public class CtTypeJavaType extends SimpleType { private CtType type; public CtTypeJavaType(CtType type) { - super(CtTypeJavaType.class); + super(CtTypeJavaType.class, TypeBindings.emptyBindings(), null, null, + type == null ? 0 : type.getGenericSignature().hashCode(), + null, null, false); this.type = type; } @@ -46,9 +51,20 @@ public class CtTypeJavaType extends SimpleType { return type.getGenericSignature(); } - @Override public StringBuilder getGenericSignature(StringBuilder sb) { return sb.append(type.getGenericSignature()); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || !this.getClass().isAssignableFrom(o.getClass())) { + return false; + } + CtTypeJavaType that = (CtTypeJavaType) o; + return Objects.equals(this.getGenericSignature(), that.getGenericSignature()); + } } diff --git a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java b/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java index 46213a3..9ec4ea9 100644 --- a/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java +++ b/common/common-javassist/src/test/java/org/apache/servicecomb/common/javassist/TestCtTypeJavaType.java @@ -45,4 +45,45 @@ public class TestCtTypeJavaType { Assert.assertEquals("Ljava/util/List<Lorg/apache/servicecomb/common/javassist/TestCtTypeJavaType;>;", listJavaType.getGenericSignature()); } + + /** + * The {@link CtTypeJavaType} with different CtType should holds different hash code. + */ + @Test + public void testHashCode() { + JavaType newJavaType = TypeFactory.defaultInstance().constructType(String.class); + CtType newCtType = new CtType(newJavaType); + CtTypeJavaType newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertNotEquals(ctTypeJavaType.hashCode(), newCtTypeJavaType.hashCode()); + + newJavaType = TypeFactory.defaultInstance().constructType(cls); + newCtType = new CtType(newJavaType); + newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertEquals(ctTypeJavaType.hashCode(), newCtTypeJavaType.hashCode()); + } + + /** + * The {@link CtTypeJavaType}s holding different type information should not equal to each others. + * While those holding the same type information should be equal. + */ + @Test + public void testEquals() { + JavaType newJavaType = TypeFactory.defaultInstance().constructType(String.class); + CtType newCtType = new CtType(newJavaType); + CtTypeJavaType newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertNotEquals(ctTypeJavaType, newCtTypeJavaType); + + newJavaType = TypeFactory.defaultInstance().constructType(cls); + newCtType = new CtType(newJavaType); + newCtTypeJavaType = new CtTypeJavaType(newCtType); + Assert.assertEquals(ctTypeJavaType, newCtTypeJavaType); + + // test subClass of CtTypeJavaType + newJavaType = TypeFactory.defaultInstance().constructType(cls); + newCtType = new CtType(newJavaType); + newCtTypeJavaType = new CtTypeJavaType(newCtType) { + private static final long serialVersionUID = 1876189050753964880L; + }; + Assert.assertEquals(ctTypeJavaType, newCtTypeJavaType); + } } -- To stop receiving notification emails like this one, please contact liu...@apache.org.