Skip to content
This repository was archived by the owner on Apr 5, 2026. It is now read-only.
Open
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
35 changes: 17 additions & 18 deletions src/java/APIClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,37 @@ public APIClient(String baseUrl) {

// BUG: No timeout configured on connection
// BUG: No error handling for network failures
// BUG: BufferedReader never closed - RESOURCE LEAK
public String get(String endpoint) throws IOException {
URL url = new URL(baseUrl + endpoint);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");

BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream())
);
StringBuilder response = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
// BUG: Reader never closed
return response.toString();
StringBuilder response = new StringBuilder();

try (BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream())
)) {
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
}
return response.toString();
}

// BUG: OutputStream never closed - RESOURCE LEAK
// BUG: No content-type header set
public String post(String endpoint, String data) throws IOException {
URL url = new URL(baseUrl + endpoint);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setDoOutput(true);

// BUG: No content-type header set
OutputStream os = conn.getOutputStream();
os.write(data.getBytes());
// BUG: Stream never closed

return "Posted";
// BUG: No content-type header set
try (OutputStream os = conn.getOutputStream()) {
os.write(data.getBytes());
os.flush();
}
return "Posted";
}

// BUG: Always returns true - doesn't actually check status
Expand Down
Loading