Repository navigation
refactor(schema): move the validateSchema worker out of JsonValidator into MetaSchemaCheck - #102
Merged
Merged
Conversation
… into MetaSchemaCheck validateSchema() brought about 100 lines of thread machinery into JsonValidator.kt: the iterative nesting check, the 64 MB-stack worker that inherits no thread-locals (#56), joinUninterruptibly, metaSchemaDepth (#73), the lazily created meta-schema validator and metaSchemaOf/metaSchemas, and the two constants only they use. Thread lifecycle is not keyword evaluation (SRP), so it now lives in MetaSchemaCheck.kt, beside MetaSchemas.kt whose data it uses. MetaSchemaCheck is an internal class taking only maxValidationDepth. Each JsonValidator creates its own lazily, on the first validateSchema() call with meta-schema validation enabled, so the meta-schema validator keeps its lifetime and is freed with the validator; no state is held in a top-level or companion object. The public validateSchema() keeps its signature and KDoc, keeps the enableMetaSchemaValidation check and delegates. The moved bodies, KDoc and comments are unchanged, as are the thread name, stack size, interrupt handling and exception propagation. Behaviour is unchanged. Closes #97 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Owner
Author
Review of #102: move the validateSchema worker into MetaSchemaCheckVerdict: this is a pure move with no behaviour change, and I found nothing blocking. There is one should-fix (a missing GC test for an acceptance criterion of #97) and two nits. How I verified
BlockingNone. What I checked:
Should-fix
Nits
Other checks (no findings)
🤖 Generated with Claude Code |
… check is created CLAUDE.md's JsonValidator entry now names MetaSchemaCheck beside the other extracted holders, and the KDoc of MetaSchemaCheck and of the metaSchemaCheck field says it is created on the first validateSchema call with meta-schema validation enabled, not on any first call. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
MetaSchemaCheck holds no reference back to its JsonValidator, so a leak of the check or of its meta-schema validator into a global would not keep the validator alive, and the existing lifecycle test never called validateSchema(). The new case runs validateSchema(), drops the validator and checks that the validator, its MetaSchemaCheck and the meta-schema validator are each collected. A planted global list holding the meta-schema validator makes it fail ([true, true, false]). Test counts: custom 1,379 -> 1,380, full run 5,849 -> 5,850. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves the
validateSchema()machinery out ofJsonValidator.ktinto a newMetaSchemaCheck.kt, a pure move with no behaviour change:nestingDepthcheck againstmaxValidationDepthktson-validateSchemaworker that inherits no thread-locals ([P2] Interrupted validateSchema calls leave large-stack worker threads running #56) andjoinUninterruptiblymetaSchemaDepth([P2] Meta-schema depth-budget scaling overflows large positive limits and mishandles zero #73) and the constantsMETA_SCHEMA_STACK_SIZEandMETA_SCHEMA_DEPTH_PER_LEVELmetaSchemaOf/metaSchemasThe public
JsonValidator.validateSchema(schema)keeps its signature and KDoc. It keeps theenableMetaSchemaValidationcheck and delegates. The Java API is unchanged.Ownership and lifetime
internal class MetaSchemaCheck(maxValidationDepth: Int)receives only the depth limit. EachJsonValidatorholds one in aprivate val metaSchemaCheck by lazy { ... }instance field, so it is created on the first enabledvalidateSchema()call and dropped with the validator. Its own meta-schema validator is stillby lazyinside it. No callback into the owning validator is needed: the worker only constructs and uses a separateJsonValidator, exactly as before. Nothing is stored in a top-level or companion object; the companion holds only constants and the puremetaSchemaDepth.Verification
./gradlew ktlintFormat, thenCI=true ./gradlew test ktlintCheck --rerun-tasks: 5,849 tests, 0 failures, 0 errors, 0 skipped (frombuild/test-results/test/*.xml), including ValidateSchemaWorkerTest (3), MetaSchemaValidationTest (36), ValidatorLifecycleTest (3) and JavaApiUsageTest (11)test_counts.py: exit 0 (full run 5,849, custom 1,379)origin/masterafter normalising indentation andprivate: identicalCloses #97
🤖 Generated with Claude Code