maheshrajus commented on code in PR #519:
URL: https://github.com/apache/tez/pull/519#discussion_r3702436805
##########
tez-plugins/tez-history-parser/src/main/java/org/apache/tez/history/parser/ATSFileParser.java:
##########
@@ -174,11 +175,23 @@ private void processApplication(JSONObject
tezApplicationJson) throws JSONExcept
}
}
- private JSONObject readJson(InputStream in) throws IOException,
JSONException {
- //Read entire content to memory
- final NonSyncByteArrayOutputStream bout = new
NonSyncByteArrayOutputStream();
- IOUtils.copy(in, bout);
- return new JSONObject(new String(bout.toByteArray(), "UTF-8"));
+ /**
+ * Parse the raw payload of a single zip entry as JSON.
+ * Returns null if the payload is empty or blank — callers should skip such
entries.
+ */
+ private JSONObject readJson(byte[] payload, String entryName) throws
JSONException {
+ String text = new String(payload, StandardCharsets.UTF_8);
+ if (text.trim().isEmpty()) {
+ LOG.warn("Skipping zip entry '{}' - payload is empty or whitespace
only", entryName);
+ return null;
+ }
+ try {
+ return new JSONObject(text);
+ } catch (JSONException e) {
+ String snippet = text.length() > 200 ? text.substring(0, 200) + "..." :
text;
+ throw new JSONException("Failed to parse JSON from zip entry '" +
entryName
+ + "' (length=" + text.length() + ", snippet=" + snippet + "): " +
e.getMessage());
Review Comment:
@abstractdog Yes, Jettison's JSONObject(String) constructor calls into
JSONTokener, and on an empty payload the message we saw was below
` org.codehaus.jettison.json.JSONException: A JSONObject text must begin
with '{' at character 0 of `
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]