-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Issue Description
The HttpClient instance in ApiTracker.java is not properly managed using try-with-resources, which violates Java's AutoCloseable resource management best practices.
Location
- File: json-java21-api-tracker/src/main/java/io/github/simbo1905/tracker/ApiTracker.java
- Lines: Around lines where HttpClient.newBuilder() is used
Problem
The code creates an HttpClient instance:
final var httpClient = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10))
.build();But does not use it within a try-with-resources statement, which means:
- The HttpClient may not be properly closed
- Potential resource leaks if exceptions occur
- Violates the AutoCloseable contract
Expected Fix
Wrap the HttpClient usage in a try-with-resources statement to ensure proper resource cleanup:
try (final var httpClient = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10))
.build()) {
// HttpClient usage here
}Impact
- Severity: Medium (resource leak potential)
- Type: Code quality / Resource management
- Module: json-java21-api-tracker
Additional Context
This issue was identified by static analysis tools that detect AutoCloseable instances used without proper resource management. The fix aligns with Java best practices for managing AutoCloseable resources.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels