Skip to content

Roaring64Bitmap.remove loses the replacement container at the bitmap-to-array threshold #852

Closed

Description

@PHJ2000

Removing an element at the bitmap-to-array threshold leaves the old container installed. A subsequent portable round-trip changes the bitmap's contents.

This input is built entirely through public mutation APIs; the bytes are produced by serializePortable itself, not supplied as malformed external data.

import org.roaringbitmap.longlong.Roaring64Bitmap;
import java.io.*;
public class Reproduce {
 public static void main(String[] args) throws Exception {
  Roaring64Bitmap b=new Roaring64Bitmap();
  for(int i=0;i<4097;i++) b.addLong(i*2L);
  b.remove(0L);
  ByteArrayOutputStream out=new ByteArrayOutputStream();
  b.serializePortable(new DataOutputStream(out));
  Roaring64Bitmap restored=new Roaring64Bitmap();
  restored.deserializePortable(new DataInputStream(new ByteArrayInputStream(out.toByteArray())));
  System.out.println("equal="+b.equals(restored)+", expected contains(2)="+b.contains(2)+", actual="+restored.contains(2));
 }
}

Expected: restored equals the original and contains 2. Actual: equal=false and contains(2)=false. Reproduced with 1.6.22 and current master on Java 21.

remove(long) ignores the replacement returned by Container.remove, while removeLong(long) already installs it. Delegating to removeLong fixes the round-trip.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions