koral--/android-gif-drawable · error · IllegalArgumentException
Speed factor is not positive
Error message
Speed factor is not positive
What it means
GifInfoHandle.setSpeedFactor requires a strictly positive, non-NaN float. Non-positive or NaN values raise IllegalArgumentException('Speed factor is not positive'). Values below 1/Integer.MAX_VALUE are silently clamped to that minimum instead of throwing.
Solutions
- Validate factor > 0 and !Float.isNaN(factor) before calling setSpeedFactor.
- Use the drawable's pause()/stop()/start() APIs for pausing rather than a 0 speed factor.
- Guard divisions that produce the factor against zero denominators.
Example fix
// before
gifDrawable.setSpeedFactor(userSpeed); // may be 0
// after
if (userSpeed > 0f && !Float.isNaN(userSpeed)) {
gifDrawable.setSpeedFactor(userSpeed);
} else {
gifDrawable.pause();
} Defensive patterns
Strategy: validation
Validate before calling
if (factor > 0f && !Float.isNaN(factor)) { gifInfoHandle.setSpeedFactor(factor); } Type guard
boolean isValidSpeedFactor(float f) { return f > 0f && !Float.isNaN(f); } Try / catch
try { gifInfoHandle.setSpeedFactor(factor); } catch (IllegalArgumentException e) { gifDrawable.pause(); } Prevention
- Use pause()/stop() for 'zero speed' semantics
- Guard speed computations against division by zero
- Initialize speed fields with 1.0f, not 0f
When it happens
Trigger: Calling setSpeedFactor(0), a negative factor, or Float.NaN — often the result of a division whose denominator was 0, or parsing an invalid speed string.
Common situations: Computing speed from user settings where 0 means 'paused' (use pause()/stop() instead); uninitialized float fields defaulting to 0f; NaN from unvalidated arithmetic.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Loop count of range <0, 65535>
- y must be < height
- Frame index is not in range <0;
- Sample size out of range <1, 65535>
- Bitmap is recycled
AI-assisted analysis of koral--/android-gif-drawable@26ff795f78 (2026-09-10).
Data as JSON: /api/errors/3b485bd3ace0db6e.
Report an issue: GitHub.
Appendix: source
Thrown at android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifInfoHandle.java:247
if (loopCount < 0 || loopCount > Character.MAX_VALUE) {
throw new IllegalArgumentException("Loop count of range <0, 65535>");
}
synchronized (this) {
setLoopCount(gifInfoPtr, (char) loopCount);
}
}
synchronized long getSourceLength() {
return getSourceLength(gifInfoPtr);
}
synchronized int getNativeErrorCode() {
return getNativeErrorCode(gifInfoPtr);
}
void setSpeedFactor(@FloatRange(from = 0, fromInclusive = false) float factor) {
if (factor <= 0f || Float.isNaN(factor)) {
throw new IllegalArgumentException("Speed factor is not positive");
}
if (factor < 1f / Integer.MAX_VALUE) {
factor = 1f / Integer.MAX_VALUE;
}
synchronized (this) {
setSpeedFactor(gifInfoPtr, factor);
}
}
synchronized int getDuration() {
return getDuration(gifInfoPtr);
}
synchronized int getCurrentPosition() {
return getCurrentPosition(gifInfoPtr);
}
synchronized int getCurrentFrameIndex() {View on GitHub (pinned to 26ff795f78)