{"record":{"id":"1e9a357061f159f8","repo":"Yalantis/uCrop","slug":"load-jpeg-specified-filename-is-null","errorCode":null,"errorMessage":"load_jpeg(): Specified filename is (null).","messagePattern":"load_jpeg\\(\\): Specified filename is \\(null\\)\\.","errorType":"validation","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57014,"sourceCode":"    struct _cimg_error_mgr {\n      struct jpeg_error_mgr original;\n      jmp_buf setjmp_buffer;\n      char message[JMSG_LENGTH_MAX];\n    };\n\n    typedef struct _cimg_error_mgr *_cimg_error_ptr;\n\n    METHODDEF(void) _cimg_jpeg_error_exit(j_common_ptr cinfo) {\n      _cimg_error_ptr c_err = (_cimg_error_ptr) cinfo->err; // Return control to the setjmp point\n      (*cinfo->err->format_message)(cinfo,c_err->message);\n      jpeg_destroy(cinfo); // Clean memory and temp files\n      longjmp(c_err->setjmp_buffer,1);\n    }\n#endif\n\n    CImg<T>& _load_jpeg(std::FILE *const file, const char *const filename) {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_jpeg(): Specified filename is (null).\",\n                                    cimg_instance);\n\n#ifndef cimg_use_jpeg\n      if (file)\n        throw CImgIOException(_cimg_instance\n                              \"load_jpeg(): Unable to load data from '(FILE*)' unless libjpeg is enabled.\",\n                              cimg_instance);\n      else return load_other(filename);\n#else\n\n#if defined __GNUC__\n      const char *volatile nfilename = filename; // Use 'volatile' to avoid (wrong) g++ warning\n      std::FILE *volatile nfile = file?file:cimg::fopen(nfilename,\"rb\");\n#else\n      const char *nfilename = filename;\n      std::FILE *nfile = file?file:cimg::fopen(nfilename,\"rb\");\n#endif","sourceCodeStart":56996,"sourceCodeEnd":57032,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L56996-L57032","documentation":"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.","triggerScenarios":"Calling img.load_jpeg(NULL, NULL), or passing a null filename to an overload that expected a FILE* which was never opened.","commonSituations":"Fopen failed earlier and its null result was passed along un-checked; a JNI string conversion returned null; variable left uninitialized.","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"],"exampleFix":"// before\nstd::FILE* f = fopen(path,\"rb\");\nimg.load_jpeg(f, path); // f may be NULL and path may be NULL\n// after\nif (!path) throw std::invalid_argument(\"jpeg path is null\");\nstd::FILE* f = fopen(path,\"rb\");\nif (!f) throw std::runtime_error(\"cannot open jpeg file\");\nimg.load_jpeg(f, path);","handlingStrategy":"type-guard","validationCode":"if (!filename || !*filename) throw std::invalid_argument(\"filename required\");","typeGuard":"bool hasJpegSource(std::FILE* file, const char* filename) { return file != nullptr || (filename != nullptr && filename[0] != '\\0'); }","tryCatchPattern":"try { img.load_jpeg(file, filename); }\ncatch (CImgArgumentException& e) { log(\"null jpeg source: %s\", e.what()); }","preventionTips":["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"],"tags":["jpeg","image-loading","null-argument","cimg"],"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"}