koral--/android-gif-drawable · error · IllegalArgumentException

InputStream does not support marking

Error message

InputStream does not support marking

What it means

The GifInfoHandle(InputStream) constructor requires the stream to support mark/reset because the native decoder needs to read the stream multiple times. If stream.markSupported() returns false, an IllegalArgumentException('InputStream does not support marking') is thrown.

Solutions

  1. Wrap the stream in a BufferedInputStream (markSupported() is true) before passing it in.
  2. Buffer the stream contents into a byte array (or ByteArrayInputStream) first and pass that instead.
  3. Prefer a file/asset/Uri source where possible so no marking requirement applies.

Example fix

// before
gifDrawable = new GifDrawableBuilder().from(socket.getInputStream()).build();
// after
gifDrawable = new GifDrawableBuilder().from(new BufferedInputStream(socket.getInputStream())).build();
Defensive patterns

Strategy: validation

Validate before calling

if (stream.markSupported()) { gifDrawable = new GifDrawableBuilder().from(stream).build(); } else { gifDrawable = new GifDrawableBuilder().from(new BufferedInputStream(stream)).build(); }

Try / catch

try { d = new GifDrawableBuilder().from(stream).build(); } catch (IllegalArgumentException e) { d = new GifDrawableBuilder().from(new BufferedInputStream(stream)).build(); }

Prevention

When it happens

Trigger: Passing a non-marking InputStream such as a raw Socket InputStream, System.in, or a stream wrapped in something that disables marking into new GifInfoHandle(stream) or GifDrawableBuilder.from(stream).

Common situations: Streaming a GIF directly from a network socket or decoded HTTP body without buffering; wrapping streams in classes that drop mark support.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


AI-assisted analysis of koral--/android-gif-drawable@26ff795f78 (2026-09-10). Data as JSON: /api/errors/a8fbed532430cf43. Report an issue: GitHub.

Appendix: source

Thrown at android-gif-drawable/src/main/java/pl/droidsonroids/gif/GifInfoHandle.java:55

	GifInfoHandle(FileDescriptor fileDescriptor) throws GifIOException {
		gifInfoPtr = openFileDescriptor(fileDescriptor, 0, true);
	}

	GifInfoHandle(byte[] bytes) throws GifIOException {
		gifInfoPtr = openByteArray(bytes);
	}

	GifInfoHandle(ByteBuffer buffer) throws GifIOException {
		gifInfoPtr = openDirectByteBuffer(buffer);
	}

	GifInfoHandle(String filePath) throws GifIOException {
		gifInfoPtr = openFile(filePath);
	}

	GifInfoHandle(InputStream stream) throws GifIOException {
		if (!stream.markSupported()) {
			throw new IllegalArgumentException("InputStream does not support marking");
		}
		gifInfoPtr = openStream(stream);
	}

	GifInfoHandle(AssetFileDescriptor afd) throws IOException {
		try {
			gifInfoPtr = openFileDescriptor(afd.getFileDescriptor(), afd.getStartOffset(), false);
		} finally {
			try {
				afd.close();
			} catch (IOException ignored) {
				//no-op
			}
		}
	}

	private static long openFileDescriptor(FileDescriptor fileDescriptor, long offset, boolean closeOriginalDescriptor) throws GifIOException {
		final int nativeFileDescriptor;

View on GitHub (pinned to 26ff795f78)