Skip to content

Commit 1f41794

Browse files
committed
tidy
1 parent 36509a0 commit 1f41794

File tree

1 file changed

+3
-82
lines changed
  • json-java21-schema/src/main/java/io/github/simbo1905/json/schema

1 file changed

+3
-82
lines changed

json-java21-schema/src/main/java/io/github/simbo1905/json/schema/JsonSchema.java

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -299,25 +299,6 @@ static JsonSchema compile(URI doc, JsonValue schemaJson, JsonSchemaOptions jsonS
299299
", compileOptions.remoteFetcher=" + compileOptions.remoteFetcher().getClass().getSimpleName() +
300300
", fetch policy allowedSchemes=" + compileOptions.fetchPolicy().allowedSchemes());
301301

302-
// Early policy enforcement for root-level remote $ref to avoid unnecessary work
303-
// FIXME this is an unnecessary optimization at compile time we should just be optimistic and inline this to the main loop
304-
if (schemaJson instanceof JsonObject rootObj) {
305-
JsonValue refVal = rootObj.members().get("$ref");
306-
if (refVal instanceof JsonString refStr) {
307-
try {
308-
java.net.URI refUri = java.net.URI.create(refStr.value());
309-
String scheme = refUri.getScheme();
310-
if (scheme != null && !compileOptions.fetchPolicy().allowedSchemes().contains(scheme)) {
311-
throw new RemoteResolutionException(refUri, RemoteResolutionException.Reason.POLICY_DENIED,
312-
"Scheme not allowed by policy: " + refUri);
313-
}
314-
} catch (IllegalArgumentException ignore) {
315-
// FIXME this feels unsafe lets fail fast here
316-
// Not a URI, ignore - normal compilation will handle it
317-
}
318-
}
319-
}
320-
321302
// Placeholder context (not used post-compile; schemas embed resolver contexts during build)
322303
Map<URI, CompiledRoot> emptyRoots = new LinkedHashMap<>();
323304
Map<String, JsonSchema> emptyPointerIndex = new LinkedHashMap<>();
@@ -358,25 +339,6 @@ static JsonSchema compile(URI doc, JsonValue schemaJson, JsonSchemaOptions jsonS
358339
return result;
359340
}
360341

361-
/// Normalize URI for dedup correctness
362-
static java.net.URI normalizeUri(java.net.URI baseUri, String refString) {
363-
LOG.fine(() -> "normalizeUri: entry with base=" + baseUri + ", refString=" + refString);
364-
LOG.finest(() -> "normalizeUri: baseUri object=" + baseUri + ", scheme=" + baseUri.getScheme() + ", host=" + baseUri.getHost() + ", path=" + baseUri.getPath());
365-
try {
366-
java.net.URI refUri = java.net.URI.create(refString);
367-
LOG.finest(() -> "normalizeUri: created refUri=" + refUri + ", scheme=" + refUri.getScheme() + ", host=" + refUri.getHost() + ", path=" + refUri.getPath());
368-
java.net.URI resolved = baseUri.resolve(refUri);
369-
LOG.finest(() -> "normalizeUri: resolved URI=" + resolved + ", scheme=" + resolved.getScheme() + ", host=" + resolved.getHost() + ", path=" + resolved.getPath());
370-
java.net.URI normalized = resolved.normalize();
371-
LOG.finer(() -> "normalizeUri: normalized result=" + normalized);
372-
LOG.finest(() -> "normalizeUri: final normalized URI=" + normalized + ", scheme=" + normalized.getScheme() + ", host=" + normalized.getHost() + ", path=" + normalized.getPath());
373-
return normalized;
374-
} catch (IllegalArgumentException e) {
375-
LOG.severe(() -> "ERROR: SCHEMA: normalizeUri failed ref=" + refString + " base=" + baseUri);
376-
throw new IllegalArgumentException("Invalid URI reference: " + refString);
377-
}
378-
}
379-
380342
/// Core work-stack compilation loop
381343
static CompiledRegistry compileWorkStack(JsonValue initialJson,
382344
java.net.URI initialUri,
@@ -391,7 +353,6 @@ static CompiledRegistry compileWorkStack(JsonValue initialJson,
391353
Deque<java.net.URI> workStack = new ArrayDeque<>();
392354
Map<java.net.URI, CompiledRoot> built = new NormalizedUriMap(new LinkedHashMap<>());
393355
Set<java.net.URI> active = new HashSet<>();
394-
Map<java.net.URI, java.net.URI> parentMap = new HashMap<>();
395356

396357
// Push initial document
397358
workStack.push(initialUri);
@@ -433,8 +394,8 @@ static CompiledRegistry compileWorkStack(JsonValue initialJson,
433394
);
434395

435396
// Get the compiled schema from the bundle
436-
JsonSchema schema = bundle.entry().schema();
437-
LOG.finest(() -> "buildRoot: compiled schema object=" + schema + ", class=" + schema.getClass().getSimpleName());
397+
JsonSchema rootSchema = bundle.entry().schema();
398+
LOG.finest(() -> "buildRoot: compiled schema object=" + rootSchema + ", class=" + rootSchema.getClass().getSimpleName());
438399

439400
// Register all compiled roots from the bundle into the global built map
440401
LOG.finest(() -> "buildRoot: registering " + bundle.all().size() + " compiled roots from bundle into global registry");
@@ -450,8 +411,7 @@ static CompiledRegistry compileWorkStack(JsonValue initialJson,
450411
// Process any discovered refs from the compilation
451412
// The compileBundle method should have already processed remote refs through the work stack
452413
LOG.finer(() -> "buildRoot: MVF compilation completed, work stack processed remote refs");
453-
LOG.finer(() -> "buildRoot: completed for docUri=" + currentUri + ", schema type=" + schema.getClass().getSimpleName());
454-
JsonSchema rootSchema = schema;
414+
LOG.finer(() -> "buildRoot: completed for docUri=" + currentUri + ", schema type=" + rootSchema.getClass().getSimpleName());
455415
LOG.finest(() -> "compileWorkStack: built rootSchema object=" + rootSchema + ", class=" + rootSchema.getClass().getSimpleName());
456416
} finally {
457417
active.remove(currentUri);
@@ -536,45 +496,6 @@ public String pointer() {
536496
}
537497
}
538498

539-
/// Schedule remote document for compilation if not seen before
540-
static boolean scheduleRemoteIfUnseen(Deque<java.net.URI> workStack,
541-
Map<java.net.URI, CompiledRoot> built,
542-
Map<java.net.URI, java.net.URI> parentMap,
543-
java.net.URI currentDocUri,
544-
java.net.URI targetDocUri) {
545-
LOG.finer(() -> "scheduleRemoteIfUnseen: target=" + targetDocUri + ", workStack.size=" + workStack.size() + ", built.size=" + built.size());
546-
LOG.finest(() -> "scheduleRemoteIfUnseen: targetDocUri object=" + targetDocUri + ", scheme=" + targetDocUri.getScheme() + ", host=" + targetDocUri.getHost() + ", path=" + targetDocUri.getPath());
547-
LOG.finest(() -> "scheduleRemoteIfUnseen: workStack object=" + workStack + ", contents=" + workStack.stream().map(Object::toString).collect(java.util.stream.Collectors.joining(", ", "[", "]")));
548-
LOG.finest(() -> "scheduleRemoteIfUnseen: built map object=" + built + ", keys=" + built.keySet() + ", size=" + built.size());
549-
550-
// Detect remote cycles by walking parent chain
551-
if (SchemaCompiler.formsRemoteCycle(parentMap, currentDocUri, targetDocUri)) {
552-
String cycleMessage = "ERROR: CYCLE: remote $ref cycle detected current=" + currentDocUri + ", target=" + targetDocUri;
553-
LOG.severe(() -> cycleMessage);
554-
throw new IllegalStateException(cycleMessage);
555-
}
556-
557-
// Check if already built or already in work stack
558-
boolean alreadyBuilt = built.containsKey(targetDocUri);
559-
boolean inWorkStack = workStack.contains(targetDocUri);
560-
LOG.finest(() -> "scheduleRemoteIfUnseen: alreadyBuilt=" + alreadyBuilt + ", inWorkStack=" + inWorkStack);
561-
562-
if (alreadyBuilt || inWorkStack) {
563-
LOG.finer(() -> "scheduleRemoteIfUnseen: already seen, skipping");
564-
LOG.finest(() -> "scheduleRemoteIfUnseen: skipping targetDocUri=" + targetDocUri);
565-
return false;
566-
}
567-
568-
// Track parent chain for cycle detection before scheduling child
569-
parentMap.putIfAbsent(targetDocUri, currentDocUri);
570-
571-
// Add to work stack
572-
workStack.push(targetDocUri);
573-
LOG.finer(() -> "scheduleRemoteIfUnseen: scheduled remote document: " + targetDocUri);
574-
LOG.finest(() -> "scheduleRemoteIfUnseen: workStack after push=" + workStack + ", contents=" + workStack.stream().map(Object::toString).collect(java.util.stream.Collectors.joining(", ", "[", "]")));
575-
return true;
576-
}
577-
578499
/// Detect and throw on compile-time cycles
579500
static void detectAndThrowCycle(Set<java.net.URI> active, java.net.URI docUri, String pathTrail) {
580501
LOG.finest(() -> "detectAndThrowCycle: active set=" + active + ", docUri object=" + docUri + ", scheme=" + docUri.getScheme() + ", host=" + docUri.getHost() + ", path=" + docUri.getPath() + ", pathTrail='" + pathTrail + "'");

0 commit comments

Comments
 (0)