1414import java .net .URI ;
1515import java .util .*;
1616import java .util .logging .Level ;
17- import java .util .logging .Logger ;
1817import java .util .regex .Pattern ;
18+ import static io .github .simbo1905 .json .schema .SchemaLogging .LOG ;
1919
2020/// JSON Schema public API entry point
2121///
@@ -55,9 +55,9 @@ public sealed interface JsonSchema
5555 JsonSchema .RootRef ,
5656 JsonSchema .EnumSchema {
5757
58- Logger LOG = Logger . getLogger ( JsonSchema . class . getName ());
58+ /// Shared logger is provided by SchemaLogging.LOG
5959
60- /** Adapter that normalizes URI keys (strip fragment + normalize) for map access. */
60+ /// Adapter that normalizes URI keys (strip fragment + normalize) for map access.
6161 final class NormalizedUriMap implements java .util .Map <java .net .URI , CompiledRoot > {
6262 private final java .util .Map <java .net .URI , CompiledRoot > delegate ;
6363 NormalizedUriMap (java .util .Map <java .net .URI , CompiledRoot > delegate ) { this .delegate = delegate ; }
@@ -101,11 +101,10 @@ public ValidationResult validateAt(String path, JsonValue json, Deque<Validation
101101 }
102102
103103 /// Options for schema compilation
104- ///
105- /// @param assertFormats whether to enable format assertion validation
106104 record Options (boolean assertFormats ) {
107105 /// Default options with format assertion disabled
108106 static final Options DEFAULT = new Options (false );
107+ String summary () { return "assertFormats=" + assertFormats ; }
109108 }
110109
111110 /// Compile-time options controlling remote resolution and caching
@@ -317,7 +316,7 @@ static JsonSchema compile(JsonValue schemaJson, Options options, CompileOptions
317316 Objects .requireNonNull (schemaJson , "schemaJson" );
318317 Objects .requireNonNull (options , "options" );
319318 Objects .requireNonNull (compileOptions , "compileOptions" );
320- LOG .fine (() -> "compile: Starting schema compilation with initial URI: " + java .net .URI .create ("urn:inmemory:root" ));
319+ LOG .info (() -> "json-schema. compile start doc= " + java .net .URI .create ("urn:inmemory:root" ) + " options=" + options . summary ( ));
321320 LOG .fine (() -> "compile: Starting schema compilation with full options, schema type: " + schemaJson .getClass ().getSimpleName () +
322321 ", options.assertFormats=" + options .assertFormats () + ", compileOptions.remoteFetcher=" + compileOptions .remoteFetcher ().getClass ().getSimpleName ());
323322 LOG .fine (() -> "compile: fetch policy allowedSchemes=" + compileOptions .fetchPolicy ().allowedSchemes ());
@@ -374,8 +373,7 @@ static JsonSchema compile(JsonValue schemaJson, Options options, CompileOptions
374373 }
375374 }
376375
377- LOG .fine (() -> "compile: Completed schema compilation, total roots compiled: " + rootCount );
378- LOG .fine (() -> "compile: Completed schema compilation with full options, result type: " + result .getClass ().getSimpleName ());
376+ LOG .info (() -> "json-schema.compile done roots=" + rootCount );
379377 return result ;
380378 }
381379
@@ -393,7 +391,7 @@ static java.net.URI normalizeUri(java.net.URI baseUri, String refString) {
393391 LOG .finest (() -> "normalizeUri: final normalized URI=" + normalized + ", scheme=" + normalized .getScheme () + ", host=" + normalized .getHost () + ", path=" + normalized .getPath ());
394392 return normalized ;
395393 } catch (IllegalArgumentException e ) {
396- LOG .severe (() -> "ERROR: normalizeUri failed for refString =" + refString + ", baseUri =" + baseUri );
394+ LOG .severe (() -> "ERROR: SCHEMA: normalizeUri failed ref =" + refString + " base =" + baseUri );
397395 throw new IllegalArgumentException ("Invalid URI reference: " + refString );
398396 }
399397 }
@@ -571,7 +569,7 @@ static JsonValue fetchIfNeeded(java.net.URI docUri,
571569 return fetchedDocument ;
572570
573571 } catch (Exception e ) {
574- LOG . severe (() -> "ERROR: fetchIfNeeded failed to fetch remote document: " + docUri + ", error: " + e . getMessage ());
572+ // Network failures are logged by the fetcher; suppress here to avoid duplication
575573 throw new RemoteResolutionException (docUri , RemoteResolutionException .Reason .NETWORK_ERROR ,
576574 "Failed to fetch remote document: " + docUri , e );
577575 }
@@ -681,7 +679,7 @@ static void detectAndThrowCycle(Set<java.net.URI> active, java.net.URI docUri, S
681679 LOG .finest (() -> "detectAndThrowCycle: active set=" + active + ", docUri=" + docUri + ", pathTrail='" + pathTrail + "'" );
682680 LOG .finest (() -> "detectAndThrowCycle: docUri object=" + docUri + ", scheme=" + docUri .getScheme () + ", host=" + docUri .getHost () + ", path=" + docUri .getPath ());
683681 if (active .contains (docUri )) {
684- String cycleMessage = "ERROR: CYCLE: " + pathTrail + " -> " + docUri + " (compile-time remote ref cycle)" ;
682+ String cycleMessage = "ERROR: CYCLE: " + pathTrail + "; doc= " + docUri ;
685683 LOG .severe (() -> cycleMessage );
686684 throw new IllegalArgumentException (cycleMessage );
687685 }
@@ -730,20 +728,24 @@ static CompiledRegistry freezeRoots(Map<java.net.URI, CompiledRoot> built, java.
730728 /// @return ValidationResult with success/failure information
731729 default ValidationResult validate (JsonValue json ) {
732730 Objects .requireNonNull (json , "json" );
731+ LOG .info (() -> "json-schema.validate start frames=0 doc=unknown" );
733732 List <ValidationError > errors = new ArrayList <>();
734733 Deque <ValidationFrame > stack = new ArrayDeque <>();
735734 Set <ValidationKey > visited = new HashSet <>();
736735 stack .push (new ValidationFrame ("" , this , json ));
737736
738737 int iterationCount = 0 ;
739- final int WARNING_THRESHOLD = 1000 ; // Warn after 1000 iterations
738+ int maxDepthObserved = 0 ;
739+ final int WARNING_THRESHOLD = 10_000 ;
740740
741741 while (!stack .isEmpty ()) {
742742 iterationCount ++;
743+ if (stack .size () > maxDepthObserved ) maxDepthObserved = stack .size ();
743744 if (iterationCount % WARNING_THRESHOLD == 0 ) {
744- final int count = iterationCount ;
745- LOG .warning (() -> "PERFORMANCE WARNING: Validation stack processing " + count +
746- " iterations - possible infinite recursion or deeply nested schema" );
745+ final int processed = iterationCount ;
746+ final int pending = stack .size ();
747+ final int maxDepth = maxDepthObserved ;
748+ LOG .fine (() -> "PERFORMANCE WARNING: Validation stack processed=" + processed + " pending=" + pending + " maxDepth=" + maxDepth );
747749 }
748750
749751 ValidationFrame frame = stack .pop ();
@@ -1457,7 +1459,7 @@ private static String escapeJsonString(String s) {
14571459
14581460 /// Internal schema compiler
14591461 final class SchemaCompiler {
1460- /** Per-compilation session state (no static mutable fields). */
1462+ /// Per-compilation session state (no static mutable fields).
14611463 private static final class Session {
14621464 final Map <String , JsonSchema > definitions = new LinkedHashMap <>();
14631465 final Map <String , JsonSchema > compiledByPointer = new LinkedHashMap <>();
@@ -1467,7 +1469,7 @@ private static final class Session {
14671469 long totalFetchedBytes ;
14681470 int fetchedDocs ;
14691471 }
1470- /** Strip any fragment from a URI, returning the base document URI. */
1472+ /// Strip any fragment from a URI, returning the base document URI.
14711473 private static java .net .URI stripFragment (java .net .URI uri ) {
14721474 String s = uri .toString ();
14731475 int i = s .indexOf ('#' );
@@ -1482,7 +1484,7 @@ private static void trace(String stage, JsonValue fragment) {
14821484 }
14831485 }
14841486
1485- /** Per-compile carrier for resolver-related state. */
1487+ /// Per-compile carrier for resolver-related state.
14861488 private static final class CompileContext {
14871489 final Session session ;
14881490 final Map <java .net .URI , CompiledRoot > sharedRoots ;
@@ -1504,7 +1506,7 @@ private static final class CompileContext {
15041506 }
15051507 }
15061508
1507- /** Immutable context frame capturing current document/base/pointer/anchors. */
1509+ /// Immutable context frame capturing current document/base/pointer/anchors.
15081510 private static final class ContextFrame {
15091511 final java .net .URI docUri ;
15101512 final java .net .URI baseUri ;
@@ -1783,7 +1785,7 @@ static CompilationBundle compileBundle(JsonValue schemaJson, Options options, Co
17831785 final java .net .URI normUri = first ;
17841786 LOG .fine (() -> "compileBundle: Successfully fetched document (normalized): " + normUri + ", document type: " + normType );
17851787 } catch (RemoteResolutionException e ) {
1786- LOG . severe (() -> "ERROR: compileBundle failed to fetch remote document: " + docUri + ", reason: " + e . reason ());
1788+ // Network outcomes are logged by the fetcher; rethrow to surface to caller
17871789 throw e ;
17881790 }
17891791 }
0 commit comments