This is an automated email from the ASF dual-hosted git repository. chaokunyang pushed a commit to branch releases-0.12 in repository https://gitbox.apache.org/repos/asf/fory.git
commit b8b99baf8f9ecf920eb05d6049d9337255056b25 Author: Shawn Yang <[email protected]> AuthorDate: Thu Sep 4 11:43:40 2025 +0800 fix(java): skip hash compute for abstract field type (#2575) <!-- **Thanks for contributing to Fory.** **If this is your first time opening a PR on fory, you can refer to [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md).** Contribution Checklist - The **Apache Fory** community has requirements on the naming of pr titles. You can also find instructions in [CONTRIBUTING.md](https://github.com/apache/fory/blob/main/CONTRIBUTING.md). - Fory has a strong focus on performance. If the PR you submit will have an impact on performance, please benchmark it first and provide the benchmark result here. --> ## Why? <!-- Describe the purpose of this PR. --> ## What does this PR do? <!-- Describe the details of this PR. --> ## Related issues #2559 ## Does this PR introduce any user-facing change? <!-- If any user-facing interface changes, please [open an issue](https://github.com/apache/fory/issues/new/choose) describing the need to do so and update the document if necessary. Delete section if not applicable. --> - [ ] Does this PR introduce any public API change? - [ ] Does this PR introduce any binary protocol compatibility change? ## Benchmark <!-- When the PR has an impact on performance (if you don't know whether the PR will have an impact on performance, you can submit the PR first, and if it will have impact on performance, the code reviewer will explain it), be sure to attach a benchmark data here. Delete section if not applicable. --> --- .../org/apache/fory/serializer/ObjectSerializer.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/java/fory-core/src/main/java/org/apache/fory/serializer/ObjectSerializer.java b/java/fory-core/src/main/java/org/apache/fory/serializer/ObjectSerializer.java index 741491a0c..881cedce0 100644 --- a/java/fory-core/src/main/java/org/apache/fory/serializer/ObjectSerializer.java +++ b/java/fory-core/src/main/java/org/apache/fory/serializer/ObjectSerializer.java @@ -32,6 +32,7 @@ import org.apache.fory.memory.MemoryBuffer; import org.apache.fory.memory.Platform; import org.apache.fory.meta.ClassDef; import org.apache.fory.reflect.FieldAccessor; +import org.apache.fory.reflect.ReflectionUtils; import org.apache.fory.reflect.TypeRef; import org.apache.fory.resolver.ClassInfo; import org.apache.fory.resolver.ClassResolver; @@ -363,13 +364,19 @@ public final class ObjectSerializer<T> extends AbstractObjectSerializer<T> { try { TypeResolver resolver = fory.isCrossLanguage() ? fory.getXtypeResolver() : fory.getClassResolver(); - ClassInfo classInfo = resolver.getClassInfo(typeRef.getRawType()); - int xtypeId = classInfo.getXtypeId(); - if (Types.isStructType((byte) xtypeId)) { - id = - TypeUtils.computeStringHash(classInfo.decodeNamespace() + classInfo.decodeTypeName()); + Class<?> cls = typeRef.getRawType(); + if (ReflectionUtils.isAbstract(cls) || cls.isInterface()) { + id = 0; } else { - id = Math.abs(xtypeId); + ClassInfo classInfo = resolver.getClassInfo(typeRef.getRawType()); + int xtypeId = classInfo.getXtypeId(); + if (Types.isStructType((byte) xtypeId)) { + id = + TypeUtils.computeStringHash( + classInfo.decodeNamespace() + classInfo.decodeTypeName()); + } else { + id = Math.abs(xtypeId); + } } } catch (Exception e) { id = 0; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
