Fix ClassCastException in JSONML.toJSONArray and toJSONObject#1037
Fix ClassCastException in JSONML.toJSONArray and toJSONObject#1037stleary merged 2 commits intostleary:masterfrom
Conversation
Add type checking before casting parse() results to JSONArray/JSONObject. When parse() returns an unexpected type (e.g., String for malformed input), the code now throws a descriptive JSONException instead of ClassCastException. This prevents unchecked exceptions from propagating to callers who only expect JSONException from these methods. Fixes stleary#1034
|
Changes look OK, but where are the unit tests to confirm the new behavior? [stleary 1/28/2026] Issue fixed |
|
What problem does this code solve? Does the code still compile with Java6? Risks Changes to the API? Will this require a new release? Should the documentation be updated? Does it break the unit tests? Was any code refactored in this commit? Review status Starting 3-day comment window |
Added comprehensive test coverage for safe type casting: Exception cases (should throw JSONException, not ClassCastException): - Malformed XML causing type mismatch in toJSONArray() - Type mismatch in toJSONObject() Valid cases (should continue to work): - Valid XML to JSONArray conversion - Valid XML to JSONObject conversion These tests verify the fix for issue stleary#1034 where ClassCastException was thrown when parse() returned unexpected types.
|
|
Hey @stleary, all requested changes are complete. Could you please take a look? After the fix:
|



Add type checking before casting parse() results to JSONArray/JSONObject. When parse() returns an unexpected type (e.g., String for malformed input), the code now throws a descriptive JSONException instead of ClassCastException.
This prevents unchecked exceptions from propagating to callers who only expect JSONException from these methods.
Fixes #1034