diff --git a/AGENTS.md b/AGENTS.md index e731976..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. @@ -422,7 +424,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. @@ -455,6 +457,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 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();