{"record":{"id":"84664b6c997ef54b","repo":"Yalantis/uCrop","slug":"save-jxl-specified-filename-is-null","errorCode":null,"errorMessage":"save_jxl(): Specified filename is (null).","messagePattern":"save_jxl\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":61766,"sourceCode":"#endif\n    }\n\n    //! Save image as a JPEG XL file.\n    /**\n      \\param filename Filename, as a C-string.\n      \\param distance Sets the level for lossy compression: lower = higher quality.\n        Range: 0 .. 25. 0.0 = mathematically lossless\n      \\param bytes_per_pixel Force the number of bytes per pixels for the saving, when possible.\n    **/\n    const CImg<T>& save_jxl(const char *const filename, const float distance=1.0f,\n                            const unsigned int bytes_per_pixel=0) const {\n      return _save_jxl(filename,distance,bytes_per_pixel);\n    }\n\n    const CImg<T>& _save_jxl(const char *const filename, const float distance=1.0f,\n                             const unsigned int bytes_per_pixel=0) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_jxl(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (_spectrum > 4)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_jxl(): JPEG XL only supports at most 4 channels.\",\n                                    cimg_instance);\n      double stmin, stmax = (double)max_min(stmin);\n      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)\n        cimg::warn(_cimg_instance\n                   \"save_jxl(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.\",\n                   cimg_instance,\n                   stmin,stmax,filename);\n      if (bytes_per_pixel>2 || sizeof(T)<bytes_per_pixel)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_jxl(): bytes_per_pixel must be in [0, 2] and less than or equal to sizeof(T)\",\n                                    cimg_instance);\n      if (_depth>1)\n        cimg::warn(_cimg_instance","sourceCodeStart":61748,"sourceCodeEnd":61784,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L61748-L61784","documentation":"CImg's save_jxl() requires a destination filename; _save_jxl throws CImgArgumentException immediately when the filename pointer is null. JPEG XL saving in this code path is filename-based only — there is no FILE* overload to fall back on.","triggerScenarios":"Calling img.save_jxl(nullptr) or passing a null/empty-derived filename variable to _save_jxl.","commonSituations":"Filenames computed at runtime (from user input, config, or string operations) that end up null; also calling internal overloads directly with an uninitialized char*.","solutions":["Pass a concrete path with a .jxl extension: img.save_jxl(\"out.jxl\").","Validate the filename (non-null, non-empty) before calling save_jxl and fail early.","Ensure the variable holding the path is actually initialized before the save call."],"exampleFix":"// before\nconst char *out = config.outputPath; // may be null\nimg.save_jxl(out);\n// after\nif (!config.outputPath || !*config.outputPath) throw std::invalid_argument(\"outputPath required\");\nimg.save_jxl(config.outputPath);","handlingStrategy":"validation","validationCode":"if (!outPath || !*outPath) {\n  throw std::invalid_argument(\"jxl output path is required\");\n}\nimg.save_jxl(outPath);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate output paths at configuration load time.","Never store filenames as raw pointers that can be null.","Check strlen/emptiness before format-specific save calls."],"tags":["cimg","jxl","null-argument"],"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"}