apache/hadoop · error · IllegalArgumentException

attempting to read from negative offset

Error message

attempting to read from negative offset

What it means

Error "attempting to read from negative offset" thrown in apache/hadoop.

Source

Thrown at hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/AbfsInputStream.java:652

   * Uses the Content-Range header to determine the total file size, which is necessary
   * for handling partial reads correctly.
   *
   * @param op the ABFS HTTP operation containing the response headers
   * @return the content length of the file
   */
  private long extractContentLength(AbfsHttpOperation op) {
    // We need to use content range header instead of content length to take care of partial reads
    String contentRange = op.getResponseHeader(HttpHeaderConfigurations.CONTENT_RANGE);
    contentLength = 0;
    if (!StringUtils.isEmpty(contentRange)) {
      contentLength = Long.parseLong(contentRange.split(AbfsHttpConstants.FORWARD_SLASH)[1]);
    }
    return contentLength;
  }

  int readRemote(long position, byte[] b, int offset, int length, TracingContext tracingContext) throws IOException {
    if (position < 0) {
      throw new IllegalArgumentException("attempting to read from negative offset");
    }
    if (!(shouldRestrictGpsOnOpenFile() && isFirstRead()) && position >= contentLength) {
      return -1;  // Hadoop prefers -1 to EOFException
    }
    if (b == null) {
      throw new IllegalArgumentException("null byte array passed in to read() method");
    }
    if (offset >= b.length) {
      throw new IllegalArgumentException("offset greater than length of array");
    }
    if (length < 0) {
      throw new IllegalArgumentException("requested read length is less than zero");
    }
    if (length > (b.length - offset)) {
      throw new IllegalArgumentException("requested read length is more than will fit after requested offset in buffer");
    }
    final AbfsRestOperation op;
    AbfsPerfTracker tracker = client.getAbfsPerfTracker();

View on GitHub (pinned to 2add963021)

Solutions

  1. Pass a non-negative offset to read(position, buffer, offset, length).
  2. Validate offsets computed by application code before issuing positioned reads.

When it happens

Trigger: A positioned read is requested with a negative buffer offset.

Common situations: See trigger scenarios.


AI-assisted analysis of apache/hadoop@2add963021 (2026-08-22). Data as JSON: /api/errors/fb5d348e85b54e56. Report an issue: GitHub.