Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,7 @@ public void deleteByAbout(UUID entityId) {
try {
deleteThreadInternal(UUID.fromString(threadId));
} catch (Exception ex) {
// Continue deletion
LOG.warn("Failed to delete thread {} for entity {}", threadId, entityId, ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,31 +163,42 @@ private static boolean isEntityType(JSONObject jsonSchema) {
private static Schema loadMainSchema(
String schemaPath, String entityType, String schemaUri, SchemaClient schemaClient)
throws SchemaProcessingException {
InputStream schemaInputStream =
SchemaFieldExtractor.class.getClassLoader().getResourceAsStream(schemaPath);
if (schemaInputStream == null) {
LOG.error("Schema file not found at path: {}", schemaPath);
throw new SchemaProcessingException(
"Schema file not found for entity type: " + entityType,
SchemaProcessingException.ErrorType.RESOURCE_NOT_FOUND);
}

JSONObject rawSchema = new JSONObject(new JSONTokener(schemaInputStream));
SchemaLoader schemaLoader =
SchemaLoader.builder()
.schemaJson(rawSchema)
.resolutionScope(schemaUri)
.schemaClient(schemaClient)
.build();
try (InputStream schemaInputStream =
SchemaFieldExtractor.class.getClassLoader().getResourceAsStream(schemaPath)) {
if (schemaInputStream == null) {
LOG.error("Schema file not found at path: {}", schemaPath);
throw new SchemaProcessingException(
"Schema file not found for entity type: " + entityType,
SchemaProcessingException.ErrorType.RESOURCE_NOT_FOUND);
}

try {
Schema schema = schemaLoader.load().build();
LOG.debug("Schema '{}' loaded successfully.", schemaPath);
return schema;
} catch (Exception e) {
LOG.error("Error loading schema '{}': {}", schemaPath, e.getMessage());
JSONObject rawSchema = new JSONObject(new JSONTokener(schemaInputStream));
SchemaLoader schemaLoader =
SchemaLoader.builder()
.schemaJson(rawSchema)
.resolutionScope(schemaUri)
.schemaClient(schemaClient)
.build();

try {
Schema schema = schemaLoader.load().build();
LOG.debug("Schema '{}' loaded successfully.", schemaPath);
return schema;
} catch (Exception e) {
LOG.error("Error loading schema '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
SchemaProcessingException.ErrorType.INVALID_SCHEMA,
e);
}
} catch (IOException e) {
LOG.error("Error closing schema input stream '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
"Error closing schema input stream: " + e.getMessage(),
SchemaProcessingException.ErrorType.INVALID_SCHEMA,
e);
Comment on lines +194 to +199
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: IOException catch misleadingly says 'closing' but covers all IO

In both loadMainSchema (line 194) and loadSchema (line 454), the outer catch (IOException e) block logs "Error closing schema input stream" but this catch will also fire if an IOException is thrown during getResourceAsStream() or while reading the stream (e.g., inside JSONTokener). The log message and exception text are misleading — they suggest only a close failure, when the real cause could be a read error.

Consider using a more general message like "Error reading schema input stream" to accurately reflect all possible IOException origins within the try-with-resources block.

Suggested fix:

Change the log and exception messages from:
  "Error closing schema input stream ..."
to:
  "Error reading schema input stream ..."

Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion

Comment on lines +187 to +199
}
}
SchemaProcessingException.ErrorType.OTHER);
}
}
Comment on lines 202 to 204
Expand Down Expand Up @@ -414,30 +425,36 @@ private Schema resolveSchemaByType(String typeName, String schemaUri, SchemaClie

private Schema loadSchema(String schemaPath, String schemaUri, SchemaClient schemaClient)
throws SchemaProcessingException {
InputStream schemaInputStream = getClass().getClassLoader().getResourceAsStream(schemaPath);
if (schemaInputStream == null) {
LOG.error("Schema file not found at path: {}", schemaPath);
throw new SchemaProcessingException(
"Schema file not found for path: " + schemaPath,
SchemaProcessingException.ErrorType.RESOURCE_NOT_FOUND);
}

JSONObject rawSchema = new JSONObject(new JSONTokener(schemaInputStream));
SchemaLoader schemaLoader =
SchemaLoader.builder()
.schemaJson(rawSchema)
.resolutionScope(schemaUri) // Base URI for resolving $ref
.schemaClient(schemaClient)
.build();
try (InputStream schemaInputStream = getClass().getClassLoader().getResourceAsStream(schemaPath)) {
if (schemaInputStream == null) {
LOG.error("Schema file not found at path: {}", schemaPath);
throw new SchemaProcessingException(
"Schema file not found for path: " + schemaPath,
SchemaProcessingException.ErrorType.RESOURCE_NOT_FOUND);
}

try {
Schema schema = schemaLoader.load().build();
LOG.debug("Schema '{}' loaded successfully.", schemaPath);
return schema;
} catch (Exception e) {
LOG.error("Error loading schema '{}': {}", schemaPath, e.getMessage());
JSONObject rawSchema = new JSONObject(new JSONTokener(schemaInputStream));
SchemaLoader schemaLoader =
SchemaLoader.builder()
.schemaJson(rawSchema)
.resolutionScope(schemaUri) // Base URI for resolving $ref
.schemaClient(schemaClient)
.build();

try {
Schema schema = schemaLoader.load().build();
LOG.debug("Schema '{}' loaded successfully.", schemaPath);
return schema;
} catch (Exception e) {
LOG.error("Error loading schema '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
SchemaProcessingException.ErrorType.OTHER);
}
} catch (IOException e) {
LOG.error("Error closing schema input stream '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
"Error closing schema input stream: " + e.getMessage(),
SchemaProcessingException.ErrorType.OTHER);
Comment on lines +448 to 458
}
}
Expand Down
Loading