Skip to content

Commit d429cdd

Browse files
Fix silent exception swallowing in FeedRepository and resource leaks in SchemaFieldExtractor
- FeedRepository.deleteByAbout(): Replace empty catch block with LOG.warn to log failed thread deletions during entity cleanup with thread ID, entity ID, and exception details - SchemaFieldExtractor.loadMainSchema(): Wrap InputStream in try-with-resources to prevent file descriptor leak - SchemaFieldExtractor.loadSchema(): Same try-with-resources fix, consistent with getAllEntityTypes() which already does this correctly
1 parent 9da7bea commit d429cdd

2 files changed

Lines changed: 35 additions & 32 deletions

File tree

openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -767,7 +767,7 @@ public void deleteByAbout(UUID entityId) {
767767
try {
768768
deleteThreadInternal(UUID.fromString(threadId));
769769
} catch (Exception ex) {
770-
// Continue deletion
770+
LOG.warn("Failed to delete thread {} during entity {} cleanup", threadId, entityId, ex);
771771
}
772772
}
773773
}

openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)