{"record":{"id":"95e6e524ab56f3b0","repo":"koral--/android-gif-drawable","slug":"y-must-be-height","errorCode":null,"errorMessage":"y must be < height","messagePattern":"y must be < height","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifDrawable.java","lineNumber":759,"sourceCode":"\t}\n\n\t/**\n\t * Returns the {@link Color} at the specified location. Throws an exception\n\t * if x or y are out of bounds (negative or &gt;= to the width or height\n\t * respectively). The returned color is a non-premultiplied ARGB value.\n\t *\n\t * @param x The x coordinate (0...width-1) of the pixel to return\n\t * @param y The y coordinate (0...height-1) of the pixel to return\n\t * @return The argb {@link Color} at the specified coordinate\n\t * @throws IllegalArgumentException if x, y exceed the drawable's bounds\n\t * @throws IllegalStateException    if drawable is recycled\n\t */\n\tpublic int getPixel(@IntRange(from = 0) int x, @IntRange(from = 0) int y) {\n\t\tif (x >= mNativeInfoHandle.getWidth()) { //need to check explicitly because reused bitmap may be larger\n\t\t\tthrow new IllegalArgumentException(\"x must be < width\");\n\t\t}\n\t\tif (y >= mNativeInfoHandle.getHeight()) {\n\t\t\tthrow new IllegalArgumentException(\"y must be < height\");\n\t\t}\n\t\treturn mBuffer.getPixel(x, y);\n\t}\n\n\t@Override\n\tprotected void onBoundsChange(@NonNull Rect bounds) {\n\t\tmDstRect.set(bounds);\n\t\tif (mTransform != null) {\n\t\t\tmTransform.onBoundsChange(bounds);\n\t\t}\n\t}\n\n\t/**\n\t * Reads and renders new frame if needed then draws last rendered frame.\n\t *\n\t * @param canvas canvas to draw into\n\t */\n\t@Override","sourceCodeStart":741,"sourceCodeEnd":777,"githubUrl":"https://github.com/koral--/android-gif-drawable/blob/26ff795f78b7fe8bbaf375a947b2bda95fc58e3d/android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifDrawable.java#L741-L777","documentation":"GifDrawable.getPixel(x, y) validates coordinates against the current frame buffer dimensions. If y is greater than or equal to the GIF's height, an IllegalArgumentException('y must be < height') is thrown. The check is explicit because the reused Bitmap may be larger than the current GIF.","triggerScenarios":"Calling getPixel(x, y) with y >= gifDrawable.getIntrinsicHeight() (the native handle's height), e.g. a hardcoded pixel coordinate applied to a differently sized GIF.","commonSituations":"Code that assumed a fixed GIF size (e.g. sampled pixel coordinates for color detection) reused across assets of varying dimensions; resizing/reusing drawables without updating pixel coordinates.","solutions":["Check y against the drawable's intrinsic height before calling getPixel: if (y >= drawable.getIntrinsicHeight()) return/throw.","Use drawable.getIntrinsicHeight() (or GifDrawable#getHeight) to compute coordinates dynamically instead of hardcoding.","Catch IllegalArgumentException around getPixel as a last resort."],"exampleFix":"// before\nint color = gifDrawable.getPixel(10, 500);\n// after\nif (10 < gifDrawable.getIntrinsicWidth() && 500 < gifDrawable.getIntrinsicHeight()) {\n    int color = gifDrawable.getPixel(10, 500);\n}","handlingStrategy":"validation","validationCode":"if (x >= 0 && y >= 0 && x < gifDrawable.getIntrinsicWidth() && y < gifDrawable.getIntrinsicHeight()) { gifDrawable.getPixel(x, y); }","typeGuard":"boolean isWithinGifBounds(GifDrawable d, int x, int y) { return x >= 0 && y >= 0 && x < d.getIntrinsicWidth() && y < d.getIntrinsicHeight(); }","tryCatchPattern":"try { int color = gifDrawable.getPixel(x, y); } catch (IllegalArgumentException e) { /* coordinate out of bounds — use fallback color */ }","preventionTips":["Always derive pixel coordinates from getIntrinsicWidth()/getIntrinsicHeight()","Never hardcode coordinates across multiple GIF assets","Remember the reused bitmap may be larger than the GIF"],"tags":["android","argument-out-of-range","bitmap"],"backgroundTag":"value-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"}