Yalantis/uCrop · error · CImgArgumentException
load_tiff(): Specified filename is (null).
Error message
load_tiff(): Specified filename is (null).
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:57978
\param step_frame Step value of frame reading.
\param[out] bits_per_value Number of bits used to store a scalar value in the image file.
\param[out] voxel_size Voxel size, as stored in the filename.
\param[out] description Description, as stored in the filename.
\note
- libtiff support is enabled by defining the precompilation
directive \c cimg_use_tiff.
- When libtiff is enabled, 2D and 3D (multipage) several
channel per pixel are supported for
<tt>char,uchar,short,ushort,float</tt> and \c double pixel types.
- If \c cimg_use_tiff is not defined at compile time the
function uses CImg<T>& load_other(const char*).
**/
CImg<T>& load_tiff(const char *const filename,
const unsigned int first_frame=0, const unsigned int last_frame=~0U,
const unsigned int step_frame=1, unsigned int *const bits_per_value=0,
float *const voxel_size=0, CImg<charT> *const description=0) {
if (!filename)
throw CImgArgumentException(_cimg_instance
"load_tiff(): Specified filename is (null).",
cimg_instance);
const unsigned int
nfirst_frame = first_frame<last_frame?first_frame:last_frame,
nstep_frame = step_frame?step_frame:1;
unsigned int nlast_frame = first_frame<last_frame?last_frame:first_frame;
#ifndef cimg_use_tiff
cimg::unused(bits_per_value,voxel_size,description);
if (nfirst_frame || nlast_frame!=~0U || nstep_frame>1)
throw CImgArgumentException(_cimg_instance
"load_tiff(): Unable to read sub-images from file '%s' unless libtiff is enabled.",
cimg_instance,
filename);
return load_other(filename);
#else
#if cimg_verbosity<3View on GitHub (pinned to f788b534b4)
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.
Example fix
// before
img.load_tiff(getenv("TIFF_PATH"));
// after
const char *path = getenv("TIFF_PATH");
if (path) img.load_tiff(path); else cimg::exception("TIFF_PATH not set"); Defensive patterns
Strategy: validation
Validate before calling
if (!filename || !*filename) throw std::invalid_argument("load_tiff requires a non-null filename");
img.load_tiff(filename); Type guard
bool isUsablePath(const char *p) { return p != nullptr && *p != '\0'; } Try / catch
try { img.load_tiff(filename); }
catch (CImgArgumentException &e) { /* null/invalid argument: fix caller */ log(e.what()); } Prevention
- Never pass getenv results unchecked
- Default-construct paths from config with a fallback
- Assert non-null paths in JNI wrappers before native calls
When it happens
Trigger: 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.
Common situations: 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*.
Related errors
- load(): Specified filename is (null).
- load_ascii(): Specified filename is (null).
- load_dlm(): Specified filename is (null).
- load_bmp(): Specified filename is (null).
- load_jpeg(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/8106c03117a38831.
Report an issue: GitHub.