Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -227,14 +229,14 @@ static Map<String, String> fetchUpstreamSources(Set<Class<?>> 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();
Expand Down