Skip to content

Commit

Permalink
guarantee that bits is non-null once resize has been called
Browse files Browse the repository at this point in the history
  • Loading branch information
lfbayer committed Apr 16, 2018
1 parent 0622dfd commit 5bc3913
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/zaxxer/sparsebits/SparseBitSet.java
Expand Up @@ -1714,7 +1714,7 @@ protected final void resize(int index)
newSize = MAX_LENGTH1;
final int aLength1 = (bits != null ? bits.length : 0);

if (newSize != aLength1)
if (newSize != aLength1 || bits == null)
{ // only if the size needs to be changed
final long[][][] temp = new long[newSize][][]; // Get the new array
if (aLength1 != 0)
Expand Down
44 changes: 44 additions & 0 deletions src/test/java/com/zaxxer/sparsebits/InitWithZeroTest.java
@@ -0,0 +1,44 @@
package com.zaxxer.sparsebits;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class InitWithZeroTest {
private SparseBitSet bitset;

@Before
public void setup() {
bitset = new SparseBitSet(0);
}

@Test
public void testPreviousSetBit() {
Assert.assertEquals(-1, bitset.previousSetBit(0));
}

@Test
public void testPreviousClearBit() {
Assert.assertEquals(0, bitset.previousClearBit(0));
}

@Test
public void testNextSetBit() {
Assert.assertEquals(-1, bitset.nextSetBit(0));
}

@Test
public void testNextClearBit() {
Assert.assertEquals(0, bitset.nextClearBit(0));
}

@Test
public void testClone() {
Assert.assertEquals(-1, bitset.clone().nextSetBit(0));
}

@Test
public void testAnd() {
bitset.and(new SparseBitSet());
}
}

0 comments on commit 5bc3913

Please sign in to comment.