Anti-AIClone

Log date · Mon

How to check JVM metadata after Kotlin 2.4.20

Compare release artifacts and reflection behavior: Kotlin 2.4.20 reads and writes annotations in JVM metadata by default.

What should you check?

Compare Kotlin metadata in your release builds and test reflection and serialization that depend on it. Kotlin 2.4.20 reads and writes annotations in JVM metadata by default; measure the actual difference in your own artifacts. [1] In our Java 17 illustration, an annotated class file contained a placeholder while the unannotated class did not.

Questions and findings
QuestionFinding
What changed?JVM metadata reads and writes annotations by default. [1]
What did the comparison show?One annotated class contained the placeholder; one unannotated class did not.
Does this establish the R8 result?No; inspect the actual minified release.

What the release changed

JetBrains/kotlin published 2.4.20 at 2026-09-07T10:31Z. Its changelog lists KT-75736 for default JVM metadata annotation reading and writing, KT-84802 for a synthetic class flag, and KT-86464 for isPublicAbi on anonymous and synthetic local classes. [1] Those short entries alone do not predict exactly what will appear in a particular shipped app.

The release also enabled Kotlin/Native incremental compilation by default (KT-86657), enabled Kotlin/Wasm range checks by default (KT-73452), deprecated K1 (KT-75372), and expanded Swift export support for sealed classes and cross-language subtyping. [1] The release overview lists Gradle 9.7.0 support and Kotlin metadata as a Build Tools API target. [2] Multiplatform teams should inventory the generated Swift public interface as well.

Kotlin documents that @Metadata in JVM class files carries Kotlin-specific declaration information. The kotlin-metadata-jvm library reads structured declarations, and inconsistencies with the class file can affect reflection. [3] Metadata serves compatibility purposes, so do not remove it blindly just to reduce visible information.

A two-class illustration

The listed toolchain has no Kotlin compiler, so we compiled our own Java sample with javac 17.0.19. This illustrates a JVM class-file annotation; it is not a test of Kotlin 2.4.20, Kotlin metadata encoding, or R8. The two classes have the same method, but only Marked has an annotation with CLASS retention.

Our sample; the label is a non-sensitive placeholder.
import java.lang.annotation.*;
@Retention(RetentionPolicy.CLASS) @interface Label { String value(); }
@Label("DEMO-INTERNAL-TIER") class Marked { public int price() { return 120; } }
class Unmarked { public int price() { return 120; } }

In javap -v output, the marked class has RuntimeInvisibleAnnotations and the placeholder; the exact-match check for the unmarked class says absent. Invisible is the name of the class-file attribute here; it does not mean the file contents are hidden. Oracle documents -v as printing additional information. [4]

Contiguous excerpt from the transcript.
== Marked annotation attributes ==
  #15 = Utf8               RuntimeInvisibleAnnotations
  #18 = Utf8               DEMO-INTERNAL-TIER
RuntimeInvisibleAnnotations:
    Label(
      value="DEMO-INTERNAL-TIER"
placeholder in Marked.class: present
== Unmarked annotation attributes ==
placeholder in Unmarked.class: absent

The comparison shows that annotation values can become part of an artifact. It does not measure recovery effort or imply Kotlin annotations always appear in the same form. Inventory names, annotation arguments, generated interfaces and the tools that consume them.

Recommendations by case

These are engineering recommendations, not benefits measured in our experiment. Identify metadata consumers before changing rules or public interfaces.

Recommendations
CaseRecommendation
Reflection or serializationExercise real paths in the minified release and verify keep rules.
Published Kotlin libraryCompare public declarations and metadata with a matching parser.
KMP Swift exportReview the generated public interface against intent.
Annotations contain internal valuesRemove values that should not ship and inspect a fresh build.

Android documents that R8 can rename, move or remove code and that indirect uses may need keep rules; it recommends specific rules. [5] Rather than keep a whole package after one failure, identify the actual dynamic dependency, verify a narrower rule in the release build, and retain the mapping for that exact build.

Check your own builds

Hold source, dependencies, build variant and R8 configuration fixed and change the Kotlin version separately. Save the pre- and post-upgrade JVM class files and final release artifacts. The commands below use your own JAR and known class; javap inspects class files, not DEX inside an APK. [4]

Replace paths and class name; diff returns a nonzero status when differences exist.
jar tf before.jar > before-files.txt
jar tf after.jar > after-files.txt
diff -u before-files.txt after-files.txt
javap -v -p -classpath before.jar com.example.YourClass > before-class.txt
javap -v -p -classpath after.jar com.example.YourClass > after-class.txt
diff -u before-class.txt after-class.txt

First check whether a class was renamed or removed, then inspect @Metadata and other annotations. javap can reveal changes, but raw encoding is not a readable declaration inventory; use kotlin-metadata-jvm matching your Kotlin version for structured comparisons. [3] File-list and disassembly differences can also come from build configuration, so do not automatically attribute them to the compiler.

Finally run reflection, serialization, installation and critical-path tests on the final minified build, and review Swift exports where applicable. Record build identifiers, tool versions, rules and differences so a later release can be checked against the same baseline. Do not paste sensitive values into public logs.

Your checklist

  • Fix build conditions and retain both artifacts.
  • Compare class names, metadata and annotation arguments.
  • Parse Kotlin metadata with a matching tool version.
  • Test reflection and serialization in the minified release.
  • Review Swift exports and retain the build record.

Primary sources

All sources and reproduction status ↗