This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/fory.git
The following commit(s) were added to refs/heads/main by this push:
new a45aba8f5 fix(kotlin): accept supported metadata versions (#4001)
a45aba8f5 is described below
commit a45aba8f598f4155eba50736ad1669d6b27e26b2
Author: Shawn Yang <[email protected]>
AuthorDate: Mon Aug 31 00:26:43 2026 +0800
fix(kotlin): accept supported metadata versions (#4001)
## Why?
## What does this PR do?
## Related issues
Closes #3998
## AI Contribution Checklist
- [ ] Substantial AI assistance was used in this PR: `yes` / `no`
- [ ] If `yes`, I included a completed [AI Contribution
Checklist](https://github.com/apache/fory/blob/main/AI_POLICY.md#9-contributor-checklist-for-ai-assisted-prs)
in this PR description and the required `AI Usage Disclosure`.
- [ ] If `yes`, my PR description includes the required `ai_review`
summary and screenshot evidence or equivalent persisted links of the
final clean AI review results from both fresh reviewers described in
`AI_POLICY.md`, the Fory-guided reviewer and the independent general
reviewer, on the current PR diff or current HEAD after the latest code
changes.
## Does this PR introduce any user-facing change?
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
---
AGENTS.md | 4 ++++
docs/json/kotlin.md | 4 ++--
docs/json/troubleshooting.md | 2 +-
.../kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt | 8 ++------
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/AGENTS.md b/AGENTS.md
index 6cd4756c9..b6d9202a1 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -161,6 +161,10 @@ This is the entry point for AI guidance in Apache Fory.
Read this file first, th
`Object` quoted values remain strings. Quoted scalar common paths must parse
directly from reader
storage with no intermediate object allocation, reuse the unquoted token
parser, and keep larger
quoted handling in a separate cold method so native token parsing does not
regress.
+- Fory JSON Kotlin metadata-version compatibility belongs to
+ `KotlinClassMetadata.readStrict`. Do not add compiler or metadata
minor-version allowlists after a
+ successful strict parse. Validate unsupported declaration shapes and
mismatched JVM members at
+ the concrete consumer instead.
- Decoder depth and the generic-type stack paired with that depth use
root-operation failure cleanup. Nested decoders decrement depth and pop generic
types only after successful child reads; do not add nested `try/finally` to
restore them after exceptions. The root operation's `finally`/reset must clear
both decoder depth and the generic-type stack.
- Keep public APIs minimal. Public APIs must match user ownership and mental
model, not internal implementation details; generated flows stay type-owned,
while custom serializer registration stays explicit.
- A Fory instance may register types or serializers only before its first root
diff --git a/docs/json/kotlin.md b/docs/json/kotlin.md
index feb7a320f..0a6825f3c 100644
--- a/docs/json/kotlin.md
+++ b/docs/json/kotlin.md
@@ -25,8 +25,8 @@ Fory JSON; it does not change Fory's binary protocols.
## Installation
-The runtime supports Kotlin/JVM metadata ABI 2.3 and is built with Kotlin
2.3.20. Use the same Fory
-version for every module:
+The runtime accepts model metadata supported by Kotlin's strict metadata
reader and is built with
+Kotlin 2.3.20. Use the same Fory version for every module:
```kotlin title="build.gradle.kts"
plugins {
diff --git a/docs/json/troubleshooting.md b/docs/json/troubleshooting.md
index 94839267c..5d301fddf 100644
--- a/docs/json/troubleshooting.md
+++ b/docs/json/troubleshooting.md
@@ -37,7 +37,7 @@ license: |
| OutputStream write fails | The underlying `IOException` is
wrapped as the cause of `ForyJsonException`
|
| Kotlin null or missing member fails | Check the exact `jsonTypeRef`,
constructor default, and nullable occurrence; null does not request a compiler
default |
| Raw/star/projected Kotlin generic fails | Supply a complete
`jsonTypeRef<T>()`; `in` and star projections cannot reconstruct one exact
schema |
-| Unsupported Kotlin metadata | Compile the model with a
supported Kotlin 2.3 compiler and ensure its validated JVM members match the
metadata |
+| Unsupported Kotlin metadata | Ensure the resolved
`kotlin-metadata-jvm` supports the model compiler's metadata and that validated
JVM members match it |
| Kotlin model fails after Android shrinking | Apply KSP; for an exact Mixin,
use it when either its source or target is Kotlin, and verify that the
generated rules are packaged |
| Kotlin model is absent in Native Image | Install `ForyJsonKotlin` from a
reachable `ForyJsonProvider`, enable code generation, and make the exact
binding reachable from that configuration |
diff --git
a/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt
b/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt
index b5a408ed7..be68e4738 100644
---
a/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt
+++
b/kotlin/fory-json-kotlin/src/main/kotlin/org/apache/fory/json/kotlin/KotlinMetadataModels.kt
@@ -634,6 +634,8 @@ internal object KotlinMetadataTypes {
?: throw ForyJsonException("Unsupported Kotlin metadata on
${type.name}: missing @Metadata")
val metadata =
try {
+ // readStrict owns metadata-version compatibility. Callers validate
the concrete Kotlin
+ // declaration and its matching JVM members instead of gating compiler
minor versions.
KotlinClassMetadata.readStrict(annotation)
} catch (cause: IllegalArgumentException) {
throw ForyJsonException("Unsupported Kotlin metadata on ${type.name}",
cause)
@@ -643,12 +645,6 @@ internal object KotlinMetadataTypes {
"Unsupported Kotlin metadata on ${type.name}: not a class declaration",
)
}
- val version = metadata.version
- if (version.major != 2 || version.minor != 3) {
- throw ForyJsonException(
- "Unsupported Kotlin metadata on ${type.name}: ABI $version; expected
2.3",
- )
- }
return metadata
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]