You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
The SyncStack.setJSON method is incorrectly handling scenarios where the "items" key in the provided JSONObject contains a single item.
Instead of processing this single item, the current logic within the else block (when itemsObj is not a JSONArray) logs a warning and initializes an empty syncItems list, effectively skipping the data.
Code Snippet:
protectedsynchronizedvoidsetJSON(@NotNullJSONObjectjsonobject) {
if (jsonobject == null) {
thrownewIllegalArgumentException("JSON object cannot be null.");
}
this.receiveJson = jsonobject;
if (receiveJson.has("items")) {
ObjectitemsObj = receiveJson.opt("items");
if (itemsObjinstanceofJSONArray) {
JSONArrayjsonArray = (JSONArray) itemsObj;
syncItems = newArrayList<>();
for (inti = 0; i < jsonArray.length(); i++) {
JSONObjectjsonItem = jsonArray.optJSONObject(i);
if (jsonItem != null) {
syncItems.add(sanitizeJson(jsonItem));
}
}
} else {
logger.warning("'items' is not a valid list. Skipping processing."); // ✅ Prevent crashessyncItems = newArrayList<>();
}
} else {
syncItems = newArrayList<>();
}
}
Observed Behavior:
When the "items" key in the receiveJson JSONObject contains a single JSON object (not a JSONArray of one element), the code enters the else block and skips processing this item. The syncItems list remains empty in this case.
Expected Behavior:
When the "items" key contains only a single JSON object, it should be treated as a single item to be processed and added to the syncItems list.
Suggested Solution:
The else block should be modified to handle the case where itemsObj is a single JSONObject. A possible solution would be to check if itemsObj is an instance of JSONObject and, if so, create a new ArrayList, add the sanitized itemsObj to it, and assign it to syncItems.
} else {
if (itemsObjinstanceofJSONObject) {
syncItems = newArrayList<>();
syncItems.add(sanitizeJson((JSONObject) itemsObj));
} else {
logger.warning("'items' is not a valid list. Skipping processing."); // ✅ Prevent crashessyncItems = newArrayList<>();
}
}
Impact:
This issue leads to data loss or incomplete synchronization when the "items" payload from Contentstack contains a single entry. As there is any exception thrown, we consider the execution as completed, and we are updating the sync token, which leads to data loss.
The text was updated successfully, but these errors were encountered:
Description:
The SyncStack.setJSON method is incorrectly handling scenarios where the "items" key in the provided JSONObject contains a single item.
Instead of processing this single item, the current logic within the else block (when itemsObj is not a JSONArray) logs a warning and initializes an empty syncItems list, effectively skipping the data.
Code Snippet:
Observed Behavior:
When the "items" key in the receiveJson JSONObject contains a single JSON object (not a JSONArray of one element), the code enters the else block and skips processing this item. The syncItems list remains empty in this case.
Expected Behavior:
When the "items" key contains only a single JSON object, it should be treated as a single item to be processed and added to the syncItems list.
Suggested Solution:
The else block should be modified to handle the case where itemsObj is a single JSONObject. A possible solution would be to check if itemsObj is an instance of JSONObject and, if so, create a new ArrayList, add the sanitized itemsObj to it, and assign it to syncItems.
Impact:
This issue leads to data loss or incomplete synchronization when the "items" payload from Contentstack contains a single entry. As there is any exception thrown, we consider the execution as completed, and we are updating the sync token, which leads to data loss.
The text was updated successfully, but these errors were encountered: