Yalantis/uCrop · error · CImgArgumentException
load_jpeg(): Specified filename is (null).
Error message
load_jpeg(): Specified filename is (null).
What it means
Raised by _load_jpeg()'s validation guard when neither a std::FILE* nor a non-null filename is supplied, so no JPEG source is available ('(null)' is CImg's rendering of the missing filename). The error fires before any libjpeg work starts; provide a valid filename or open file stream to fix it.
Source
Thrown at ucrop/src/main/jni/CImg.h:57014
struct _cimg_error_mgr {
struct jpeg_error_mgr original;
jmp_buf setjmp_buffer;
char message[JMSG_LENGTH_MAX];
};
typedef struct _cimg_error_mgr *_cimg_error_ptr;
METHODDEF(void) _cimg_jpeg_error_exit(j_common_ptr cinfo) {
_cimg_error_ptr c_err = (_cimg_error_ptr) cinfo->err; // Return control to the setjmp point
(*cinfo->err->format_message)(cinfo,c_err->message);
jpeg_destroy(cinfo); // Clean memory and temp files
longjmp(c_err->setjmp_buffer,1);
}
#endif
CImg<T>& _load_jpeg(std::FILE *const file, const char *const filename) {
if (!file && !filename)
throw CImgArgumentException(_cimg_instance
"load_jpeg(): Specified filename is (null).",
cimg_instance);
#ifndef cimg_use_jpeg
if (file)
throw CImgIOException(_cimg_instance
"load_jpeg(): Unable to load data from '(FILE*)' unless libjpeg is enabled.",
cimg_instance);
else return load_other(filename);
#else
#if defined __GNUC__
const char *volatile nfilename = filename; // Use 'volatile' to avoid (wrong) g++ warning
std::FILE *volatile nfile = file?file:cimg::fopen(nfilename,"rb");
#else
const char *nfilename = filename;
std::FILE *nfile = file?file:cimg::fopen(nfilename,"rb");
#endifView on GitHub (pinned to f788b534b4)
Solutions
- Check the filename/FILE* is non-null before calling load_jpeg
- Check fopen succeeded (and report the errno) before passing the handle
- Verify the path string passed across JNI/native boundary is not null
- Catch CImgArgumentException to surface the bug during development
Example fix
// before
std::FILE* f = fopen(path,"rb");
img.load_jpeg(f, path); // f may be NULL and path may be NULL
// after
if (!path) throw std::invalid_argument("jpeg path is null");
std::FILE* f = fopen(path,"rb");
if (!f) throw std::runtime_error("cannot open jpeg file");
img.load_jpeg(f, path); Defensive patterns
Strategy: type-guard
Validate before calling
if (!filename || !*filename) throw std::invalid_argument("filename required"); Type guard
bool hasJpegSource(std::FILE* file, const char* filename) { return file != nullptr || (filename != nullptr && filename[0] != '\0'); } Try / catch
try { img.load_jpeg(file, filename); }
catch (CImgArgumentException& e) { log("null jpeg source: %s", e.what()); } Prevention
- Always check fopen's return value before use
- Validate path strings at API boundaries (JNI GetStringUTFChars null check)
- Initialize source variables at declaration
- Assert non-null sources in debug builds
When it happens
Trigger: Calling img.load_jpeg(NULL, NULL), or passing a null filename to an overload that expected a FILE* which was never opened.
Common situations: Fopen failed earlier and its null result was passed along un-checked; a JNI string conversion returned null; variable left uninitialized.
Related errors
- load_jpeg(): Unable to load data from '(FILE*)' unless libjp
- load_jpeg(): Error message returned by libjpeg: %s.
- load_jpeg(): Failed to load JPEG data from file '%s'.
- load_jxl(): Specified filename is (null).
- load_magick(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/1e9a357061f159f8.
Report an issue: GitHub.