{"record":{"id":"7370cd4ac8defa0c","repo":"koral--/android-gif-drawable","slug":"position-is-not-positive","errorCode":null,"errorMessage":"Position is not positive","messagePattern":"Position is not positive","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifDrawable.java","lineNumber":537,"sourceCode":"\t\treturn mNativeInfoHandle.getCurrentPosition();\n\t}\n\n\t/**\n\t * Seeks animation to given absolute position (within given loop) and refreshes the canvas.<br>\n\t * If <code>position</code> is greater than duration of the loop of animation (or whole animation if there is no loop)\n\t * then animation will be sought to the end, no exception will be thrown.<br>\n\t * NOTE: all frames from current (or first one if seeking backward) to desired one must be rendered sequentially to perform seeking.\n\t * It may take a lot of time if number of such frames is large.\n\t * Method is thread-safe. Decoding is performed in background thread and drawable is invalidated automatically\n\t * afterwards.\n\t *\n\t * @param position position to seek to in milliseconds\n\t * @throws IllegalArgumentException if <code>position</code>&lt;0\n\t */\n\t@Override\n\tpublic void seekTo(@IntRange(from = 0, to = Integer.MAX_VALUE) final int position) {\n\t\tif (position < 0) {\n\t\t\tthrow new IllegalArgumentException(\"Position is not positive\");\n\t\t}\n\t\tmExecutor.execute(new SafeRunnable(this) {\n\t\t\t@Override\n\t\t\tpublic void doWork() {\n\t\t\t\tmNativeInfoHandle.seekToTime(position, mBuffer);\n\t\t\t\tmGifDrawable.mInvalidationHandler.sendEmptyMessageAtTime(MSG_TYPE_INVALIDATION, 0);\n\t\t\t}\n\t\t});\n\t}\n\n\t/**\n\t * Like {@link #seekTo(int)} but performs operation synchronously on current thread\n\t *\n\t * @param position position to seek to in milliseconds\n\t * @throws IllegalArgumentException if <code>position</code>&lt;0\n\t */\n\tpublic void seekToBlocking(@IntRange(from = 0, to = Integer.MAX_VALUE) final int position) {\n\t\tif (position < 0) {","sourceCodeStart":519,"sourceCodeEnd":555,"githubUrl":"https://github.com/koral--/android-gif-drawable/blob/26ff795f78b7fe8bbaf375a947b2bda95fc58e3d/android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifDrawable.java#L519-L555","documentation":"GifDrawable.seekTo validates the position in milliseconds is non-negative before scheduling an async seek on its executor. Negative positions are meaningless in a GIF timeline, so it throws IllegalArgumentException immediately on the calling thread.","triggerScenarios":"Calling seekTo() with a negative value, e.g. computing position from currentTime - offset, or from an external player state that went negative.","commonSituations":"Custom media controls computing seek targets by subtraction; binding progress values that can be negative; restoring saved state with a sentinel -1 meaning 'unknown position'.","solutions":["Clamp before calling: Math.max(0, position)","Guard the source: treat sentinel/negative values as 'restart from 0' by calling seekTo(0) or resetAnimation()","Catch IllegalArgumentException around seekTo and fall back to seekTo(0)"],"exampleFix":"// before\ngifDrawable.seekTo(positionMs);\n// after\ngifDrawable.seekTo(Math.max(0, positionMs));","handlingStrategy":"validation","validationCode":"if (positionMs < 0) { positionMs = 0; }","typeGuard":"int clampPosition(int pos) { return Math.max(0, pos); }","tryCatchPattern":"try { gifDrawable.seekTo(pos); } catch (IllegalArgumentException e) { gifDrawable.seekTo(0); }","preventionTips":["Clamp all computed seek positions with Math.max(0, ...)","Treat persisted -1 position sentinels as 0 on restore","Keep seek-target arithmetic in one utility that guarantees non-negativity"],"tags":["android","gif","seek","argument-validation"],"backgroundTag":"invalid-argument-value","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"}