Skip to content

fixes #25 #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2023
Merged

fixes #25 #26

merged 2 commits into from
May 29, 2023

Conversation

GavinChenYan
Copy link
Contributor

As long as user properly handle and close any associated resources, such as the input stream, there should not be a memory leak issue.

However, , if user app repeatedly execute this code without properly closing the input stream or if there are other components in your application that are not releasing resources correctly, it could lead to memory leaks over time.

We need to ensure proper handling of resources and avoid memory leaks,

@GavinChenYan GavinChenYan requested a review from stevehu May 29, 2023 05:09
@@ -63,6 +63,7 @@ public OpenApiValidator() {
spec = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
openApiHelper = new OpenApiHelper(spec);
schemaValidator = new SchemaValidator(openApiHelper.openApi3);
in.close();
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should put this line into the finally block. Or just use the try with the resource.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to use try block like this:
try (InputStream in = this.getClass().getClassLoader().getResourceAsStream(OPENAPI_YAML_CONFIG)) {
if (in == null) {
in = this.getClass().getClassLoader().getResourceAsStream(OPENAPI_YML_CONFIG);
if (in == null) {
throw new IOException("Cannot load OpenAPI spec file");
}
}
spec = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
.lines()
.collect(Collectors.joining("\n"));
openApiHelper = new OpenApiHelper(spec);
schemaValidator = new SchemaValidator(openApiHelper.openApi3);
} catch (Exception e) {
logger.error("Initialization failed: " + e);
}

But it is error since try block will set the in (inputstream) as final and cannot load it again.

So I am going to change it to finally block

@stevehu stevehu merged commit b53406e into main May 29, 2023
@stevehu stevehu deleted the issue25 branch May 29, 2023 16:55
@GavinChenYan GavinChenYan mentioned this pull request May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants