{"record":{"id":"ef1ac75d412d5ce5","repo":"OpenRefine/OpenRefine","slug":"can-t-lookup-a-project-with-a-null-name","errorCode":null,"errorMessage":"Can't lookup a project with a null name","messagePattern":"Can't lookup a project with a null name","errorType":"exception","errorClass":"GetProjectIDException","httpStatus":null,"severity":"error","filePath":"modules/core/src/main/java/com/google/refine/ProjectManager.java","lineNumber":380,"sourceCode":"                return pm;\n            }\n        }\n        return null;\n    }\n\n    /**\n     * Tries to find the project id when given a project name Requires that all project metadata exists has been loaded\n     * to memory from the data store\n     * \n     * @param name\n     *            The name of the project\n     * @return The id of the project\n     * @throws GetProjectIDException\n     *             If no unique project is found with the given name\n     */\n    public long getProjectID(String name) throws GetProjectIDException {\n        if (name == null) {\n            throw new GetProjectIDException(\"Can't lookup a project with a null name\");\n        }\n        Integer count = 0;\n        Long id = -1L;\n        // TODO: Linear search assumes small number of projects\n        for (Entry<Long, ProjectMetadata> entry : _projectsMetadata.entrySet()) {\n            ProjectMetadata metadata = entry.getValue();\n            if (metadata != null && name.equals(metadata.getName())) {\n                id = entry.getKey();\n                count += 1;\n            }\n        }\n        if (count == 1) {\n            return id;\n        } else if (count == 0) {\n            throw new GetProjectIDException(\"Unable to find project with name: \" + name);\n        }\n        throw new GetProjectIDException(\"Multiple (\" + count + \") projects found with name: \" + name);\n    }","sourceCodeStart":362,"sourceCodeEnd":398,"githubUrl":"https://github.com/OpenRefine/OpenRefine/blob/a946177e049f3b0644261661db36cbb0c81ccf8a/modules/core/src/main/java/com/google/refine/ProjectManager.java#L362-L398","documentation":"GetProjectIDException thrown by ProjectManager.getProjectID when the supplied project name is null. A null name can never match any project, so the manager fails fast instead of doing a linear search.","triggerScenarios":"Calling ProjectManager.singleton.getProjectID(null) directly, or passing an expression/cell result that evaluated to null as the project name.","commonSituations":"Scripting or extension code that resolves a project name from user data where the value is empty/null; forgetting to supply the project-name argument in a custom command.","solutions":["Ensure the name argument is non-null before calling getProjectID","Validate user/derived input: check for null/empty strings before lookup","For expressions, use a default value (e.g. a named constant project) when the key is missing"],"exampleFix":"// before\nlong id = ProjectManager.singleton.getProjectID(name);\n// after\nif (name == null || name.isEmpty()) { throw new IllegalArgumentException(\"project name required\"); }\nlong id = ProjectManager.singleton.getProjectID(name);","handlingStrategy":"type-guard","validationCode":"if (name == null || name.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"Project name must be a non-empty string\");\n}","typeGuard":"boolean hasName(String s) { return s != null && !s.trim().isEmpty(); }","tryCatchPattern":"try { id = ProjectManager.singleton.getProjectID(name); }\ncatch (GetProjectIDException e) { /* handle missing/null/ambiguous name */ }","preventionTips":["Never pass expression results directly as project names without null checks","Default to a sentinel project name when data is missing"],"tags":["java","openrefine","null-argument"],"backgroundTag":"null-argument","analyzedSha":"a946177e049f3b0644261661db36cbb0c81ccf8a","analyzedAt":"2026-09-08T10:21:27.735Z","contentChangedAt":"2026-09-08T10:21:27.735Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}