{"record":{"id":"15b7a3537647b7d6","repo":"karatelabs/karate","slug":"boot-classpath-dir-is-null-pass-a-project-relative-directory","errorCode":null,"errorMessage":"boot.classpath: dir is null — pass a project-relative directory such as 'src/test/resources', or '' for the project root","messagePattern":"boot\\.classpath: dir is null — pass a project-relative directory such as 'src/test/resources', or '' for the project root","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/core/BootBinding.java","lineNumber":150,"sourceCode":"    }\n\n    /**\n     * {@code boot.classpath('src/test/resources')} — <b>declare the resource root</b>: the directory\n     * a {@code classpath:} reference retries against when the classloader misses, and (in a Java\n     * Runner-lane run that did not set an explicit working dir) the directory the working dir\n     * re-anchors to. One committed line makes a Maven/Gradle project resolve its references\n     * identically under a JVM run — where the classloader hits and this mapping stays inert — and\n     * under a bare-folder serve run, where the fallback carries {@code classpath:} refs to the\n     * declared dir.\n     *\n     * <p>The argument is a <b>root-relative reference</b>, so {@code file:} / {@code classpath:} /\n     * {@code this:} and Windows drive-letter absolutes are rejected. {@code ''} is valid and means\n     * the root itself (the \"unify only, map nothing\" spelling) — which is also what an undeclared\n     * project gets, so a bare-folder project never needs this call. Last call wins.</p>\n     */\n    public void classpath(String dir) {\n        if (dir == null) {\n            throw new IllegalArgumentException(\"boot.classpath: dir is null — pass a project-relative \"\n                    + \"directory such as 'src/test/resources', or '' for the project root\");\n        }\n        if (dir.startsWith(Resource.FILE_COLON) || dir.startsWith(Resource.CLASSPATH_COLON)\n                || dir.startsWith(Resource.THIS_COLON)\n                || (!dir.startsWith(\"/\") && java.nio.file.Path.of(dir).isAbsolute())) {\n            throw new IllegalArgumentException(\"boot.classpath('\" + dir + \"'): expected a directory \"\n                    + \"RELATIVE to the project root (e.g. 'src/test/resources'), not an absolute or \"\n                    + \"prefixed reference\");\n        }\n        this.classpathDir = Resource.stripLeadingSlashes(dir);\n    }\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;","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/core/BootBinding.java#L132-L168","documentation":"BootBinding.classpath(dir) configures the project-relative directory that boot.read() uses to resolve classpath: references. Passing null gives no information about where to root the classpath mapping, so an IllegalArgumentException is thrown immediately with guidance on acceptable values ('' meaning project root is valid).","triggerScenarios":"Calling boot.classpath(null) — or calling it with an expression that evaluates to null at boot time (e.g. an unset config variable).","commonSituations":"A boot configuration script interpolates a directory from an environment variable or property that is unset, producing null; copy-pasted boot config where the argument was accidentally deleted.","solutions":["Pass an explicit project-relative directory string, e.g. boot.classpath('src/test/resources').","Use boot.classpath('') if you want the project root itself.","Check any interpolated variable feeding the call for null/undefined values at boot time."],"exampleFix":"// before\nboot.classpath(myDir); // myDir may be null\n// after\nboot.classpath(myDir == null ? 'src/test/resources' : myDir);","handlingStrategy":"validation","validationCode":"// before calling boot.classpath(dir)\nif (dir == null) dir = \"\"; // default to project root, or throw your own clear error","typeGuard":null,"tryCatchPattern":"try {\n    boot.classpath(dir);\n} catch (IllegalArgumentException e) {\n    // log misconfigured boot script and fail fast with your own message\n}","preventionTips":["Never pass interpolated values that can be null; default to '' for project root.","Keep boot config free of env-dependent directory arguments, or provide explicit defaults.","Prefer literal directory strings in boot configuration."],"tags":["boot","configuration","null-argument"],"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"}