@@ -163,27 +163,28 @@ private static boolean isEntityType(JSONObject jsonSchema) {
163163 private static Schema loadMainSchema (
164164 String schemaPath , String entityType , String schemaUri , SchemaClient schemaClient )
165165 throws SchemaProcessingException {
166- InputStream schemaInputStream =
167- SchemaFieldExtractor .class .getClassLoader ().getResourceAsStream (schemaPath );
168- if (schemaInputStream == null ) {
169- LOG .error ("Schema file not found at path: {}" , schemaPath );
170- throw new SchemaProcessingException (
171- "Schema file not found for entity type: " + entityType ,
172- SchemaProcessingException .ErrorType .RESOURCE_NOT_FOUND );
173- }
166+ try ( InputStream schemaInputStream =
167+ SchemaFieldExtractor .class .getClassLoader ().getResourceAsStream (schemaPath )) {
168+ if (schemaInputStream == null ) {
169+ LOG .error ("Schema file not found at path: {}" , schemaPath );
170+ throw new SchemaProcessingException (
171+ "Schema file not found for entity type: " + entityType ,
172+ SchemaProcessingException .ErrorType .RESOURCE_NOT_FOUND );
173+ }
174174
175- JSONObject rawSchema = new JSONObject (new JSONTokener (schemaInputStream ));
176- SchemaLoader schemaLoader =
177- SchemaLoader .builder ()
178- .schemaJson (rawSchema )
179- .resolutionScope (schemaUri )
180- .schemaClient (schemaClient )
181- .build ();
175+ JSONObject rawSchema = new JSONObject (new JSONTokener (schemaInputStream ));
176+ SchemaLoader schemaLoader =
177+ SchemaLoader .builder ()
178+ .schemaJson (rawSchema )
179+ .resolutionScope (schemaUri )
180+ .schemaClient (schemaClient )
181+ .build ();
182182
183- try {
184183 Schema schema = schemaLoader .load ().build ();
185184 LOG .debug ("Schema '{}' loaded successfully." , schemaPath );
186185 return schema ;
186+ } catch (SchemaProcessingException e ) {
187+ throw e ;
187188 } catch (Exception e ) {
188189 LOG .error ("Error loading schema '{}': {}" , schemaPath , e .getMessage ());
189190 throw new SchemaProcessingException (
@@ -414,26 +415,28 @@ private Schema resolveSchemaByType(String typeName, String schemaUri, SchemaClie
414415
415416 private Schema loadSchema (String schemaPath , String schemaUri , SchemaClient schemaClient )
416417 throws SchemaProcessingException {
417- InputStream schemaInputStream = getClass ().getClassLoader ().getResourceAsStream (schemaPath );
418- if (schemaInputStream == null ) {
419- LOG .error ("Schema file not found at path: {}" , schemaPath );
420- throw new SchemaProcessingException (
421- "Schema file not found for path: " + schemaPath ,
422- SchemaProcessingException .ErrorType .RESOURCE_NOT_FOUND );
423- }
418+ try (InputStream schemaInputStream =
419+ getClass ().getClassLoader ().getResourceAsStream (schemaPath )) {
420+ if (schemaInputStream == null ) {
421+ LOG .error ("Schema file not found at path: {}" , schemaPath );
422+ throw new SchemaProcessingException (
423+ "Schema file not found for path: " + schemaPath ,
424+ SchemaProcessingException .ErrorType .RESOURCE_NOT_FOUND );
425+ }
424426
425- JSONObject rawSchema = new JSONObject (new JSONTokener (schemaInputStream ));
426- SchemaLoader schemaLoader =
427- SchemaLoader .builder ()
428- .schemaJson (rawSchema )
429- .resolutionScope (schemaUri ) // Base URI for resolving $ref
430- .schemaClient (schemaClient )
431- .build ();
427+ JSONObject rawSchema = new JSONObject (new JSONTokener (schemaInputStream ));
428+ SchemaLoader schemaLoader =
429+ SchemaLoader .builder ()
430+ .schemaJson (rawSchema )
431+ .resolutionScope (schemaUri )
432+ .schemaClient (schemaClient )
433+ .build ();
432434
433- try {
434435 Schema schema = schemaLoader .load ().build ();
435436 LOG .debug ("Schema '{}' loaded successfully." , schemaPath );
436437 return schema ;
438+ } catch (SchemaProcessingException e ) {
439+ throw e ;
437440 } catch (Exception e ) {
438441 LOG .error ("Error loading schema '{}': {}" , schemaPath , e .getMessage ());
439442 throw new SchemaProcessingException (
0 commit comments