{"record":{"id":"47252cb4c7e1b4d5","repo":"karatelabs/karate","slug":"sizeof-needs-one-argument","errorCode":null,"errorMessage":"sizeOf() needs one argument","messagePattern":"sizeOf\\(\\) needs one argument","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java","lineNumber":467,"sourceCode":"    static JavaInvokable repeat() {\n        return args -> {\n            if (args.length < 2) {\n                throw new RuntimeException(\"repeat() needs two arguments: count and function\");\n            }\n            int count = ((Number) args[0]).intValue();\n            JavaCallable fn = (JavaCallable) args[1];\n            List<Object> result = new ArrayList<>();\n            for (int i = 0; i < count; i++) {\n                result.add(fn.call(null, new Object[]{i}));\n            }\n            return result;\n        };\n    }\n\n    static JavaInvokable sizeOf() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"sizeOf() needs one argument\");\n            }\n            Object obj = args[0];\n            if (obj instanceof List) {\n                return ((List<?>) obj).size();\n            } else if (obj instanceof Map) {\n                return ((Map<?, ?>) obj).size();\n            } else if (obj instanceof String) {\n                return ((String) obj).length();\n            }\n            return 0;\n        };\n    }\n\n    static JavaInvokable sort() {\n        return args -> {\n            if (args.length == 0) {\n                throw new RuntimeException(\"sort() needs at least one argument: the list to sort\");\n            }","sourceCodeStart":449,"sourceCodeEnd":485,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/KarateJsUtils.java#L449-L485","documentation":"sizeOf() is a Karate JS utility returning the number of elements in a List or Map (and similar sized values). It throws this error when called with zero arguments, since there is no collection to measure.","triggerScenarios":"karate.sizeOf() with no arguments, e.g. sizeOf() instead of sizeOf(myList).","commonSituations":"Asserting a response length and omitting the argument; the collection variable was removed in a refactor; copying a match expression without filling in the value.","solutions":["Pass the collection: sizeOf(myList) or sizeOf(myMap).","Confirm the variable is defined before the assertion.","If it may be null/undefined, default it first: sizeOf(items || [])."],"exampleFix":"// before\nmatch sizeOf() == 3\n// after\nmatch sizeOf(response.items) == 3","handlingStrategy":"validation","validationCode":"def n = collection ? sizeOf(collection) : 0","typeGuard":null,"tryCatchPattern":null,"preventionTips":["sizeOf takes exactly one argument: the List or Map to measure.","In match assertions, include the collection path explicitly: sizeOf(response.items).","Default null collections to [] before measuring."],"tags":["karate","javascript","argument-count","collections"],"backgroundTag":"missing-required-argument","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}