diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java index 0364eb316305..66c3bd1520c3 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java @@ -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); } } } diff --git a/openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java b/openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java index b5e606fe8d41..3ac793aa5022 100644 --- a/openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java +++ b/openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java @@ -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); + } + } SchemaProcessingException.ErrorType.OTHER); } } @@ -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); } }