{"record":{"id":"2d9cb2d6258e9724","repo":"koral--/android-gif-drawable","slug":"loop-count-of-range-0-65535","errorCode":null,"errorMessage":"Loop count of range <0, 65535>","messagePattern":"Loop count of range <0, 65535>","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifInfoHandle.java","lineNumber":230,"sourceCode":"\tsynchronized boolean reset() {\n\t\treturn reset(gifInfoPtr);\n\t}\n\n\tsynchronized void saveRemainder() {\n\t\tsaveRemainder(gifInfoPtr);\n\t}\n\n\tsynchronized String getComment() {\n\t\treturn getComment(gifInfoPtr);\n\t}\n\n\tsynchronized int getLoopCount() {\n\t\treturn getLoopCount(gifInfoPtr);\n\t}\n\n\tvoid setLoopCount(@IntRange(from = 0, to = Character.MAX_VALUE) final int loopCount) {\n\t\tif (loopCount < 0 || loopCount > Character.MAX_VALUE) {\n\t\t\tthrow new IllegalArgumentException(\"Loop count of range <0, 65535>\");\n\t\t}\n\t\tsynchronized (this) {\n\t\t\tsetLoopCount(gifInfoPtr, (char) loopCount);\n\t\t}\n\t}\n\n\tsynchronized long getSourceLength() {\n\t\treturn getSourceLength(gifInfoPtr);\n\t}\n\n\tsynchronized int getNativeErrorCode() {\n\t\treturn getNativeErrorCode(gifInfoPtr);\n\t}\n\n\tvoid setSpeedFactor(@FloatRange(from = 0, fromInclusive = false) float factor) {\n\t\tif (factor <= 0f || Float.isNaN(factor)) {\n\t\t\tthrow new IllegalArgumentException(\"Speed factor is not positive\");\n\t\t}","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/koral--/android-gif-drawable/blob/26ff795f78b7fe8bbaf375a947b2bda95fc58e3d/android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifInfoHandle.java#L212-L248","documentation":"GifInfoHandle.setLoopCount restricts the loop count to the GIF integer range <0, 65535> (Character.MAX_VALUE). Values outside this range raise IllegalArgumentException('Loop count of range <0, 65535>'). 0 typically means infinite looping, matching the GIF format's 16-bit loop count field.","triggerScenarios":"Calling setLoopCount(-1), setLoopCount(100000), or any int > 65535 / < 0 (e.g. using -1 to mean 'infinite', a convention from other libraries).","commonSituations":"Porting code from other GIF libraries where -1 means infinite; computing loop counts from user input or server data without clamping.","solutions":["Clamp the value: Math.max(0, Math.min(loopCount, Character.MAX_VALUE)) before calling setLoopCount.","Use 0 for infinite looping instead of -1.","Validate user/server supplied values against the 0..65535 range first."],"exampleFix":"// before\ngifInfoHandle.setLoopCount(-1);\n// after\ngifInfoHandle.setLoopCount(0); // 0 = infinite\n// or: gifInfoHandle.setLoopCount(Math.max(0, Math.min(requested, Character.MAX_VALUE)));","handlingStrategy":"validation","validationCode":"if (loopCount >= 0 && loopCount <= Character.MAX_VALUE) { gifInfoHandle.setLoopCount(loopCount); }","typeGuard":"boolean isValidLoopCount(int n) { return n >= 0 && n <= Character.MAX_VALUE; }","tryCatchPattern":"try { gifInfoHandle.setLoopCount(loopCount); } catch (IllegalArgumentException e) { gifInfoHandle.setLoopCount(0); }","preventionTips":["Use 0 for infinite looping, not -1","Clamp user/server-provided loop counts to 0..65535","Remember GIF's loop field is 16-bit"],"tags":["android","argument-out-of-range","animation"],"backgroundTag":"argument-out-of-range","analyzedSha":"26ff795f78b7fe8bbaf375a947b2bda95fc58e3d","analyzedAt":"2026-09-10T14:37:11.595Z","contentChangedAt":"2026-09-10T14:37:11.595Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}