{"record":{"id":"8106c03117a38831","repo":"Yalantis/uCrop","slug":"load-tiff-specified-filename-is-null","errorCode":null,"errorMessage":"load_tiff(): Specified filename is (null).","messagePattern":"load_tiff\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57978,"sourceCode":"       \\param step_frame Step value of frame reading.\n       \\param[out] bits_per_value Number of bits used to store a scalar value in the image file.\n       \\param[out] voxel_size Voxel size, as stored in the filename.\n       \\param[out] description Description, as stored in the filename.\n       \\note\n       - libtiff support is enabled by defining the precompilation\n        directive \\c cimg_use_tiff.\n       - When libtiff is enabled, 2D and 3D (multipage) several\n        channel per pixel are supported for\n        <tt>char,uchar,short,ushort,float</tt> and \\c double pixel types.\n       - If \\c cimg_use_tiff is not defined at compile time the\n        function uses CImg<T>& load_other(const char*).\n     **/\n    CImg<T>& load_tiff(const char *const filename,\n                       const unsigned int first_frame=0, const unsigned int last_frame=~0U,\n                       const unsigned int step_frame=1, unsigned int *const bits_per_value=0,\n                       float *const voxel_size=0, CImg<charT> *const description=0) {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_tiff(): Specified filename is (null).\",\n                                    cimg_instance);\n\n      const unsigned int\n        nfirst_frame = first_frame<last_frame?first_frame:last_frame,\n        nstep_frame = step_frame?step_frame:1;\n      unsigned int nlast_frame = first_frame<last_frame?last_frame:first_frame;\n\n#ifndef cimg_use_tiff\n      cimg::unused(bits_per_value,voxel_size,description);\n      if (nfirst_frame || nlast_frame!=~0U || nstep_frame>1)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_tiff(): Unable to read sub-images from file '%s' unless libtiff is enabled.\",\n                                    cimg_instance,\n                                    filename);\n      return load_other(filename);\n#else\n#if cimg_verbosity<3","sourceCodeStart":57960,"sourceCodeEnd":57996,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57960-L57996","documentation":"CImg<T>::load_tiff() throws a CImgArgumentException immediately when the filename pointer is null. The library checks its arguments before doing any file I/O, so a null C-string is rejected up front. This is a caller-side programming mistake, not a runtime file problem.","triggerScenarios":"Calling img.load_tiff(NULL) directly, or passing the result of a function that returned NULL for a path (e.g. getenv(\"UNSET_VAR\") or a failed lookup) into load_tiff.","commonSituations":"Paths read from unset environment variables, optional config fields that default to null, or JNI/native code marshalling a null Java string into a const char*.","solutions":["Ensure a non-null filename string is passed to load_tiff.","If the path comes from getenv or config, check for NULL/empty before calling and supply a default.","In Java/JNI callers, verify the String path is non-null before crossing into native code."],"exampleFix":"// before\nimg.load_tiff(getenv(\"TIFF_PATH\"));\n// after\nconst char *path = getenv(\"TIFF_PATH\");\nif (path) img.load_tiff(path); else cimg::exception(\"TIFF_PATH not set\");","handlingStrategy":"validation","validationCode":"if (!filename || !*filename) throw std::invalid_argument(\"load_tiff requires a non-null filename\");\nimg.load_tiff(filename);","typeGuard":"bool isUsablePath(const char *p) { return p != nullptr && *p != '\\0'; }","tryCatchPattern":"try { img.load_tiff(filename); }\ncatch (CImgArgumentException &e) { /* null/invalid argument: fix caller */ log(e.what()); }","preventionTips":["Never pass getenv results unchecked","Default-construct paths from config with a fallback","Assert non-null paths in JNI wrappers before native calls"],"tags":["cimg","null-argument","tiff"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}