{"record":{"id":"3ef712e88792fefa","repo":"karatelabs/karate","slug":"boot-read-path-is-null","errorCode":null,"errorMessage":"boot.read: path is null","messagePattern":"boot\\.read: path is null","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/BootBinding.java","lineNumber":179,"sourceCode":"    }\n\n    /**\n     * The directory declared by {@link #classpath(String)}, root-relative and de-slashed, or\n     * {@code null} when the project declared nothing (then the fallback dir IS the root).\n     */\n    public String getClasspathDir() {\n        return classpathDir;\n    }\n\n    /**\n     * {@code boot.read('path')} — read a text file, on the one unified rule: a leading {@code /}\n     * anchors THE project root, a bare ref is root-relative, {@code classpath:} is\n     * classloader-first then the {@link #classpath(String)} fallback, and {@code file:} is a host\n     * path. Declare {@code boot.classpath(...)} before reading a {@code classpath:} ref that is\n     * not on the real classpath.\n     */\n    public String read(String path) {\n        if (path == null) throw new IllegalArgumentException(\"boot.read: path is null\");\n        java.nio.file.Path classpathRoot = classpathDir == null || root == null\n                ? root : root.resolve(classpathDir).normalize();\n        try {\n            Resource r = Resource.path(path, root, classpathRoot);\n            if (r.exists()) {\n                return r.getText();\n            }\n            throw new RuntimeException(\"boot.read: file not found: \" + path\n                    + \" (resolved to \" + r + \"; root is \" + root\n                    + \" — a leading '/' anchors the project root, 'file:' is a host path)\");\n        } catch (io.karatelabs.common.ResourceNotFoundException e) {\n            throw new RuntimeException(\"boot.read: file not found: \" + path\n                    + \" (root is \" + root + \" — a leading '/' anchors the project root, \"\n                    + \"'file:' is a host path; declare boot.classpath(dir) to map 'classpath:' refs)\", e);\n        }\n    }\n\n    /** {@code boot.log('...')} — INFO log with [boot] prefix. */","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/BootBinding.java#L161-L197","documentation":"boot.read(path) resolves and reads a file relative to the project root (or the classpath-mapped dir), but a null path cannot be resolved, so an IllegalArgumentException is thrown before any resource lookup. The method expects a non-empty string such as a bare root-relative ref, a classpath: ref, or a file: host path.","triggerScenarios":"Calling boot.read(null) directly, or passing a variable/interpolation that evaluates to null (e.g. missing config value) into boot.read.","commonSituations":"Boot config driven by environment variables or suite properties where the expected key is absent; refactored scripts where a path constant was removed but the call remained.","solutions":["Pass a concrete non-empty path string, e.g. boot.read('classpath:data/seed.json').","Initialize or default the variable feeding the call before boot.read executes.","Guard the call site: only invoke boot.read when the path value is present."],"exampleFix":"// before\nvar p = karate.env == 'ci' ? ciPath : null; boot.read(p);\n// after\nvar p = karate.env == 'ci' ? ciPath : 'classpath:default/seed.json';\nboot.read(p);","handlingStrategy":"validation","validationCode":"// before calling boot.read(path)\nif (path == null || path.isBlank()) throw new IllegalArgumentException(\"boot.read path required\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default any variable feeding boot.read to a concrete path.","Avoid reading boot paths from unset env/properties without a fallback.","Use literal path strings in boot scripts where possible."],"tags":["boot","null-argument","configuration"],"backgroundTag":"null-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"}