From 74e5c9e2a2604d4eb9f101fe5dd7dbbf9f5ca932 Mon Sep 17 00:00:00 2001 From: Simon Massey <322608+simbo1905@users.noreply.github.com> Date: Sat, 27 Sep 2025 08:42:46 +0100 Subject: [PATCH 1/4] Issue #58 Fix HttpClient resource management in ApiTracker.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replaced static shared HttpClient instance with factory method - Updated fetchFromUrl() to use try-with-resources for proper resource management - Updated fetchUpstreamSources() to use try-with-resources for proper resource management - Ensures HttpClient instances are properly closed after use - Aligns with Java 21+ AutoCloseable best practices The changes ensure that HttpClient resources are properly managed using try-with-resources, preventing potential resource leaks and following Java best practices for AutoCloseable resources. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../github/simbo1905/tracker/ApiTracker.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/json-java21-api-tracker/src/main/java/io/github/simbo1905/tracker/ApiTracker.java b/json-java21-api-tracker/src/main/java/io/github/simbo1905/tracker/ApiTracker.java index d7f5526..7cafd4b 100644 --- a/json-java21-api-tracker/src/main/java/io/github/simbo1905/tracker/ApiTracker.java +++ b/json-java21-api-tracker/src/main/java/io/github/simbo1905/tracker/ApiTracker.java @@ -64,21 +64,23 @@ enum Nothing implements ApiTracker {} // GitHub base URL for upstream sources String GITHUB_BASE_URL = "https://raw.githubusercontent.com/openjdk/jdk-sandbox/refs/heads/json/src/java.base/share/classes/"; - // Shared HttpClient instance for efficient resource management - HttpClient SHARED_HTTP_CLIENT = HttpClient.newBuilder() - .connectTimeout(Duration.ofSeconds(10)) - .build(); + // HttpClient factory method for proper resource management + static HttpClient createHttpClient() { + return HttpClient.newBuilder() + .connectTimeout(Duration.ofSeconds(10)) + .build(); + } /// Fetches content from a URL static String fetchFromUrl(String url) { - try { + try (final var httpClient = createHttpClient()) { final var request = HttpRequest.newBuilder() .uri(URI.create(url)) .timeout(Duration.ofSeconds(30)) .GET() .build(); - final var response = SHARED_HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString()); + final var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); if (response.statusCode() == 200) { return response.body(); @@ -227,14 +229,14 @@ static Map fetchUpstreamSources(Set> localClasses) { LOGGER.info("Fetching upstream source: " + url); - try { + try (final var httpClient = createHttpClient()) { final var request = HttpRequest.newBuilder() .uri(URI.create(url)) .timeout(Duration.ofSeconds(30)) .GET() .build(); - final var response = SHARED_HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofString()); + final var response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); if (response.statusCode() == 200) { final var body = response.body(); From 95d50336d6c3d278fbfc3dc631a2102ec4b3b16f Mon Sep 17 00:00:00 2001 From: Simon Massey <322608+simbo1905@users.noreply.github.com> Date: Sat, 27 Sep 2025 08:45:40 +0100 Subject: [PATCH 2/4] Add try-with-resources guideline to AGENTS.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Added bullet point under 'Leverage Java 21+ features' section - Specifies that try-with-resources must be used for all AutoCloseable resources - Includes examples like HttpClient and streams - Ensures proper resource management following Java best practices 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- AGENTS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AGENTS.md b/AGENTS.md index e731976..7c67873 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -455,6 +455,7 @@ IMPORTANT: Never disable tests written for logic that we are yet to write we do * Pattern matching for structural decomposition * Sealed classes for exhaustive switches * Virtual threads for concurrent processing + * **Use try-with-resources for all AutoCloseable resources** (HttpClient, streams, etc.) ## Package Structure From facde13df9d13b0ac69a67ab3527a49d30f49111 Mon Sep 17 00:00:00 2001 From: Simon Massey <322608+simbo1905@users.noreply.github.com> Date: Sat, 27 Sep 2025 08:46:14 +0100 Subject: [PATCH 3/4] Fix AGENTS.md references and add try-with-resources guideline MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Updated reference to deleted CODING_STYLE.md file - Changed to indicate this section contains the coding standards directly - Added try-with-resources bullet point under Java 21+ features - Ensures documentation is accurate and complete 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- AGENTS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AGENTS.md b/AGENTS.md index 7c67873..a77dd9a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -422,7 +422,7 @@ PY # Java DOP Coding Standards #################### -This file is a Gen AI summary of CODING_STYLE.md to use less tokens of context window. Read the original file for full details. +This section contains the Java DOP (Data-Oriented Programming) coding standards and guidelines. IMPORTANT: We do TDD so all code must include targeted unit tests. IMPORTANT: Never disable tests written for logic that we are yet to write we do Red-Green-Refactor coding. From 7cd1f61925ef18087e3418a766b8fa2ba18bd001 Mon Sep 17 00:00:00 2001 From: Simon Massey <322608+simbo1905@users.noreply.github.com> Date: Sat, 27 Sep 2025 08:49:37 +0100 Subject: [PATCH 4/4] Update AGENTS.md commit guidelines to forbid advertising and co-author comments - Added bullet point prohibiting advertising/promotional content in commit messages - Added bullet point prohibiting 'Co-Authored-By' comments in commit messages - Both guidelines added to Commit Requirements section - Ensures clean, professional commit messages without external advertising - Maintains proper git attribution through standard author fields --- AGENTS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AGENTS.md b/AGENTS.md index a77dd9a..36cf015 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -220,6 +220,8 @@ mvn exec:java -pl json-compatibility-suite -Dexec.args="--json" - Optionally note unexpected technical details when they are not obvious from the issue itself. - Do not report progress or success in the commit message; nothing is final until merged. - Every tidy-up commit requires an accompanying issue. If labels are unavailable, title the issue `Tidy Up: ...` and keep the description minimal. +- **Do not include advertising or promotional content** such as `🤖 Generated with [XXX YYY](https://XXX/YYY)` in commit messages. +- **Do not add 'Co-Authored-By' comments** to commit messages; keep attribution within the normal git author fields. ### Pull Requests - Describe what was done, not the rationale or implementation details.