{"record":{"id":"e7630389705ad4af","repo":"code4craft/webmagic","slug":"language-and-script-must-not-be-null","errorCode":null,"errorMessage":"language and script must not be null!","messagePattern":"language and script must not be null!","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"webmagic-scripts/src/main/java/us/codecraft/webmagic/scripts/ScriptProcessor.java","lineNumber":34,"sourceCode":"/**\n * @author code4crafter@gmail.com\n * @since 0.4.1\n */\npublic class ScriptProcessor implements PageProcessor {\n\n    private ScriptEnginePool enginePool;\n\n    private String defines;\n\n    private String script;\n\n    private final Language language;\n\n    private Site site = Site.me();\n\n    public ScriptProcessor(Language language, String script, int threadNum) {\n        if (language == null || script == null) {\n            throw new IllegalArgumentException(\"language and script must not be null!\");\n        }\n        this.language = language;\n        enginePool = new ScriptEnginePool(language, threadNum);\n        InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream(language.getDefineFile());\n        try {\n            defines = IOUtils.toString(resourceAsStream, Charset.defaultCharset());\n        } catch (IOException e) {\n            throw new IllegalArgumentException(e);\n        }\n        this.script = script;\n    }\n\n    @Override\n    public void process(Page page) {\n        ScriptEngine engine = enginePool.getEngine();\n        try {\n            ScriptContext context = engine.getContext();\n            context.setAttribute(\"page\", page, ScriptContext.ENGINE_SCOPE);","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/code4craft/webmagic/blob/67816a19d68a4fec4657bf1336227e046e251df2/webmagic-scripts/src/main/java/us/codecraft/webmagic/scripts/ScriptProcessor.java#L16-L52","documentation":"The ScriptProcessor constructor requires both a Language and a script string. If either is null it throws IllegalArgumentException \"language and script must not be null!\" before any engine is created. It is a fail-fast guard against unusable script processor configuration.","triggerScenarios":"Calling new ScriptProcessor(null, script, threadNum) or new ScriptProcessor(language, null, threadNum) — e.g. a Language enum value resolved to null from config, or a script string loaded from an empty/missing source and never defaulted.","commonSituations":"Language loaded from a config file with a typo that resolves to null; a file/classpath script read returning null (or the caller passing a null literal) and forwarded directly to the constructor.","solutions":["Pass a valid Language enum value (check spelling of the config value used to resolve it).","Ensure the script string is non-null before constructing — load it via ScriptProcessorBuilder.script/scriptFromFile which validate IO errors.","Add a caller-side null check with a clear message identifying which argument was null."],"exampleFix":"// before\nnew ScriptProcessor(languageConfig, scriptText, 1);\n// after\nObjects.requireNonNull(languageConfig, \"language\");\nObjects.requireNonNull(scriptText, \"script\");\nnew ScriptProcessor(languageConfig, scriptText, 1);","handlingStrategy":"validation","validationCode":"if (language == null) throw new IllegalStateException(\"Language not resolved from config\");\nif (script == null || script.trim().isEmpty()) throw new IllegalStateException(\"Script is empty\");","typeGuard":null,"tryCatchPattern":"try {\n    processor = new ScriptProcessor(language, script, threadNum);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"must not be null\")) {\n        throw new IllegalStateException(\"language and script are required to build ScriptProcessor\", e);\n    }\n    throw e;\n}","preventionTips":["Null-check config-derived Language values before constructing","Default empty script sources to an explicit error instead of passing null","Use Objects.requireNonNull with named messages at API boundaries"],"tags":["java","null-check","argument-validation","scripting"],"backgroundTag":"null-argument","analyzedSha":"67816a19d68a4fec4657bf1336227e046e251df2","analyzedAt":"2026-09-08T11:15:28.425Z","contentChangedAt":"2026-09-08T11:15:28.425Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}