{"record":{"id":"535e63a175df51b9","repo":"json-path/JsonPath","slug":"cannot-determine-length-of","errorCode":null,"errorMessage":"Cannot determine length of ","messagePattern":"Cannot determine length of ","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"json-path/src/main/java/com/jayway/jsonpath/spi/json/TapestryJsonProvider.java","lineNumber":88,"sourceCode":"  }\n\n  @Override\n  public Object getMapValue(final Object obj, final String key) {\n    JSONObject json = (JSONObject) obj;\n    if (!json.has(key)) {\n      return UNDEFINED;\n    }\n    return json.get(key);\n  }\n\n  @Override\n  public int length(final Object obj) {\n    if (obj instanceof JSONArray) {\n      return ((JSONArray) obj).length();\n    } else if (obj instanceof JSONObject) {\n      return ((JSONObject) obj).length();\n    } else {\n      throw new IllegalArgumentException(\"Cannot determine length of \" + obj + \", unsupported type.\");\n    }\n  }\n\n  @Override\n  public boolean isArray(final Object obj) {\n    return (obj instanceof JSONArray);\n  }\n\n  @Override\n  public void setArrayIndex(final Object array, final int index, final Object newValue) {\n    Object v = newValue == null ? JSONObject.NULL : newValue;\n    JSONArray list = (JSONArray) array;\n    list.put(index, v);\n  }\n\n}\n","sourceCodeStart":70,"sourceCodeEnd":105,"githubUrl":"https://github.com/json-path/JsonPath/blob/62a4c9f0f65ba3f625aa0867d64c528ba72d09ec/json-path/src/main/java/com/jayway/jsonpath/spi/json/TapestryJsonProvider.java#L70-L105","documentation":"TapestryJsonProvider.length() supports only org.apache.tapestry5.json.JSONArray and JSONObject; anything else triggers IllegalArgumentException \"Cannot determine length of <obj>, unsupported type.\" Like the other providers, it implements the JsonPath length function contract but only for Tapestry's JSON container types.","triggerScenarios":"Evaluating a JsonPath with a length() function where the selected node is a Tapestry5 JSON scalar (String, Number, Boolean, JSONObject.NULL) or an object of a foreign JSON library rather than JSONArray/JSONObject.","commonSituations":"Applying length() to scalar values (numbers/booleans/null) in the document; using a document parsed by a different library with the Tapestry provider; paths resolving to JSONObject.NULL.","solutions":["Check that the path targets an array or object before using length()","Adjust the path or add array indices so the target is a JSONArray","Handle scalars separately: read the node and compute length only when it is an array/object","Use SUPPRESS_EXCEPTIONS or a default value in Configuration for nullable paths"],"exampleFix":"// before\nint n = JsonPath.parse(doc).read(\"$.count.length()\"); // count is a number\n// after\nInteger count = JsonPath.parse(doc).read(\"$.count\"); // plain scalar read, no length()\n","handlingStrategy":"type-guard","validationCode":"Object node = doc.read(path);\nif (!(node instanceof JSONArray) && !(node instanceof JSONObject)) {\n    throw new IllegalArgumentException(\"length() requires array/object, got: \" + node);\n}","typeGuard":"static boolean lengthSupported(Object o) {\n    return o instanceof JSONArray || o instanceof JSONObject;\n}","tryCatchPattern":"try {\n    int n = doc.read(\"$.items.length()\");\n} catch (IllegalArgumentException e) {\n    // node is scalar or null — handle accordingly\n    n = -1;\n}","preventionTips":["Apply length() only to JSONArray/JSONObject nodes","Read scalars directly without length functions","Use default values / SUPPRESS_EXCEPTIONS for nullable paths","Parse documents with the same Tapestry provider you query with"],"tags":["json","jsonpath","tapestry","unsupported-type"],"backgroundTag":"unsupported-operation","analyzedSha":"62a4c9f0f65ba3f625aa0867d64c528ba72d09ec","analyzedAt":"2026-09-11T11:36:00.448Z","contentChangedAt":"2026-09-11T11:36:00.448Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}