{"record":{"id":"607372bb3b1758ed","repo":"Yalantis/uCrop","slug":"load-analyze-specified-filename-is-null","errorCode":null,"errorMessage":"load_analyze(): Specified filename is (null).","messagePattern":"load_analyze\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58390,"sourceCode":"\n    //! Load image from an ANALYZE7.5/NIFTI file \\newinstance.\n    static CImg<T> get_load_analyze(const char *const filename, float *const voxel_size=0) {\n      return CImg<T>().load_analyze(filename,voxel_size);\n    }\n\n    //! Load image from an ANALYZE7.5/NIFTI file \\overloading.\n    CImg<T>& load_analyze(std::FILE *const file, float *const voxel_size=0) {\n      return _load_analyze(file,0,voxel_size);\n    }\n\n    //! Load image from an ANALYZE7.5/NIFTI file \\newinstance.\n    static CImg<T> get_load_analyze(std::FILE *const file, float *const voxel_size=0) {\n      return CImg<T>().load_analyze(file,voxel_size);\n    }\n\n    CImg<T>& _load_analyze(std::FILE *const file, const char *const filename, float *const voxel_size=0) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_analyze(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      std::FILE *nfile_header = 0, *nfile = 0;\n      if (!file) {\n        CImg<charT> body(1024);\n        const char *const ext = cimg::split_filename(filename,body);\n        const unsigned int len = (unsigned int)std::strlen(body);\n        if (!cimg::strcasecmp(ext,\"hdr\")) { // File is an Analyze header file\n          nfile_header = cimg::fopen(filename,\"rb\");\n          cimg_snprintf(body._data + len,body._width - len,\".img\");\n          nfile = cimg::fopen(body,\"rb\");\n        } else if (!cimg::strcasecmp(ext,\"img\")) { // File is an Analyze data file\n          nfile = cimg::fopen(filename,\"rb\");\n          cimg_snprintf(body._data + len,body._width - len,\".hdr\");\n          nfile_header = cimg::fopen(body,\"rb\");\n        } else nfile_header = nfile = cimg::fopen(filename,\"rb\"); // File is a Niftii file\n      } else nfile_header = nfile = file; // File is a Niftii file","sourceCodeStart":58372,"sourceCodeEnd":58408,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58372-L58408","documentation":"load_analyze() delegates to _load_analyze(), which accepts either an open FILE* or a filename. If both are null there is nothing to read from, so it throws a CImgArgumentException. Passing only a null filename while file is also null is the rejected condition.","triggerScenarios":"img.load_analyze((std::FILE*)0, NULL), or calling load_analyze(filename) with filename == NULL (no FILE* supplied).","commonSituations":"Path variables that failed to initialize (null from getenv/config), or generic loader wrappers that forward an empty optional filename.","solutions":["Supply a non-null filename (e.g. pointing at the .hdr/.img Analyze file).","Alternatively pass an already-open std::FILE* instead of a filename.","Guard the call: check the path is non-null and non-empty before invoking."],"exampleFix":"// before\nimg.load_analyze(NULL);\n// after\nconst char *hdr = getenv(\"ANALYZE_HDR\");\nif (hdr) img.load_analyze(hdr);\nelse throw std::runtime_error(\"ANALYZE_HDR not set\");","handlingStrategy":"validation","validationCode":"if (!filename || !*filename) throw std::invalid_argument(\"load_analyze requires a filename or open FILE*\");\nimg.load_analyze(filename, voxelSize);","typeGuard":"bool validAnalyzeTarget(std::FILE *f, const char *name) { return f != nullptr || (name != nullptr && *name != '\\0'); }","tryCatchPattern":"try { img.load_analyze(hdrPath); }\ncatch (CImgArgumentException &e) { log(\"no file or filename given to load_analyze\"); }","preventionTips":["Always pass either an open FILE* or a non-null filename","Resolve .hdr paths before calling","Centralize path resolution with null checks"],"tags":["cimg","null-argument","analyze-format"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}