{"record":{"id":"821efeb5d5bd402a","repo":"Yalantis/uCrop","slug":"load-minc2-specified-filename-is-null","errorCode":null,"errorMessage":"load_minc2(): Specified filename is (null).","messagePattern":"load_minc2\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":58334,"sourceCode":"              if (sampleformat==SAMPLEFORMAT_UINT) _load_tiff_separate<uint64T>(tif,samplesperpixel,nx,ny);\n              else if (sampleformat==SAMPLEFORMAT_INT) _load_tiff_separate<int64T>(tif,samplesperpixel,nx,ny);\n              else _load_tiff_separate<double>(tif,samplesperpixel,nx,ny);\n              break;\n            }\n        }\n      }\n      return *this;\n    }\n#endif\n\n    //! Load image from a MINC2 file.\n    /**\n        \\param filename Filename, as a C-string.\n    **/\n    // (Original code by Haz-Edine Assemlal).\n    CImg<T>& load_minc2(const char *const filename) {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_minc2(): Specified filename is (null).\",\n                                    cimg_instance);\n#ifndef cimg_use_minc2\n      return load_other(filename);\n#else\n      minc::minc_1_reader rdr;\n      rdr.open(filename);\n      assign(rdr.ndim(1)?rdr.ndim(1):1,\n             rdr.ndim(2)?rdr.ndim(2):1,\n             rdr.ndim(3)?rdr.ndim(3):1,\n             rdr.ndim(4)?rdr.ndim(4):1);\n      if (pixel_type()==cimg::type<unsigned char>::string())\n        rdr.setup_read_byte();\n      else if (pixel_type()==cimg::type<int>::string())\n        rdr.setup_read_int();\n      else if (pixel_type()==cimg::type<double>::string())\n        rdr.setup_read_double();\n      else","sourceCodeStart":58316,"sourceCodeEnd":58352,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L58316-L58352","documentation":"CImg<T>::load_minc2() throws a CImgArgumentException when the filename pointer is null, mirroring the other loaders. Note that without cimg_use_minc2 defined, the function simply delegates to load_other(); the null check happens first regardless of build configuration.","triggerScenarios":"img.load_minc2(NULL), or passing a null path obtained from an unset environment variable or failed lookup.","commonSituations":"Optional MINC file paths from config/env defaults that resolve to null, or native code receiving a null string from a managed caller.","solutions":["Pass a valid non-null filename string.","Check env/config lookups for NULL before calling and default appropriately.","If MINC2 support is needed, build with cimg_use_minc2; otherwise ensure the file is a format load_other() handles."],"exampleFix":"// before\nimg.load_minc2(cfg.mincPath); // may be NULL\n// after\nif (cfg.mincPath) img.load_minc2(cfg.mincPath);\nelse throw std::runtime_error(\"mincPath missing\");","handlingStrategy":"validation","validationCode":"if (!mincPath || !*mincPath) throw std::invalid_argument(\"load_minc2 requires a non-null filename\");\nimg.load_minc2(mincPath);","typeGuard":"bool hasMincPath(const char *p) { return p != nullptr && *p != '\\0'; }","tryCatchPattern":"try { img.load_minc2(path); }\ncatch (CImgArgumentException &e) { log(\"null path passed to load_minc2\"); }","preventionTips":["Null-check paths resolved from env/config","Reject empty strings alongside null","Fail early at API boundaries with clear messages"],"tags":["cimg","null-argument","minc"],"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"}