Skip to content

[Java] Allocator buffer method no setting the capacity correctly. #141

Closed

Description

@FiV0

Describe the bug, including details regarding any error messages, version, and platform.

The following snippet

package org.apache.arrow.vector;

import org.apache.arrow.memory.ArrowBuf;
import org.apache.arrow.memory.RootAllocator;
import org.junit.jupiter.api.Test;


public class BufferAllocatorOverAllocation {

    @Test
    void overallocation()  {
        RootAllocator allocator = new RootAllocator();
        ArrowBuf buf = allocator.buffer(9946);

        System.out.println(buf.capacity());

        buf.capacity(9946);

        System.out.println(buf.capacity());

    }

}

prints

16384
9946

So without setting the capacity explicitly the allocator overallocates memory and also seems to set the capacity of the buffer to that. That is contrary to the docstring of the buffer method:

Note that the buffer may technically be larger than the requested size for rounding purposes. However, the buffer's capacity will be set to the configured size.

Tested against the 14.0.2 tag.

Component(s)

Java

Activity

  1. vibhatha commented on Jan 16, 2024

    @vibhatha
    Contributor

    @FiV0 Did you look into the definition of capacity function here?

  2. FiV0 commented on Jan 16, 2024

    @FiV0
    ContributorAuthor

    @vibhatha The point of this ticket was for the buffer method for which (IMO) the docstring or implementation is wrong.

  3. davisusanibar commented on Jan 17, 2024

    @davisusanibar
    Contributor

    Thanks for opening this issue, @FiV0.

    The sentences are separated by dots, maybe this will be improved, but how I understand this is:

    Note that the buffer may technically be larger than the requested size for rounding purposes. However, the buffer's capacity will be adjusted based on the configured size using the method properly (buffer.capacity).

  4. FiV0 commented on Jan 17, 2024

    @FiV0
    ContributorAuthor

    @davisusanibar Then it's a misunderstanding on my part. Your docstring improvement than solves this ticket for me.

  5. transferred this issue fromapache/arrowon Nov 26, 2024
  6. added a commit that references this issue on Feb 7, 2026
  7. added this to the 19.0.0 milestone on Feb 8, 2026
  8. added a commit that references this issue on Feb 8, 2026
  9. added a commit that references this issue on Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions