Can create a BitSet with negative number of bits. You should not be able to do that.
Steps to reproduce:
Compile and run the following code
/* %W% %G%
* @author Kevin A. Smith
* BitSet constructor tests. These test creation of a bit set.
*/
import java.io.PrintStream;
import java.util.BitSet;
public class CtorTests implements Test {
final int SET_SIZE = 64;
final int MEM_LIMIT = 0x06FFFFFF;
/* Test interface */
public void run( String[] argv, PrintStream out ) {
/* put all tests into a try ... catch block */
try {
// create a BitSet with -1 number of bits
try {
BitSet b6 = new BitSet(-1);
out.println( "b6: failed, no exception" );
}
catch( NegativeArraySizeException e ) {
out.prinln( "b6 caused exception: " +
e + "( " + e.getMessage() +" )" );
}
// create a BitSet with -64 number of bits
try {
BitSet b7 = new BitSet(-64);
}
catch( NegativeArraySizeException e ) {
out.println( "b7 caused exception: " +
e + "( " + e.getMessage() +" )" );
}
} // end try
catch( Exception e ) { }
catch( Error e ) { }
// End of test
}
/* Standalone interface */
public static void main( String[] argv ) {
CtorTests test = new CtorTests();
test.run( argv, System.out );
}
}
MORE TEST CODE:
import java.util.BitSet;
class BitSetTest {
public static void main(String[] args) {
System.out.println("starting tests");
try {
BitSet b = new BitSet(Integer.MAX_VALUE);
throw new RuntimeException();
} catch (OutOfMemoryError e) {}
try {
BitSet b = new BitSet(-100);
throw new RuntimeException();
} catch (IllegalArgumentException e) {}
BitSet b = new BitSet(10);
try {
b.get(-1);
throw new RuntimeException();
} catch (IndexOutOfBoundsException e) {}
b.set(100);
if (b.get(100) != true) throw new RuntimeException();
try {
if (b.get(Integer.MAX_VALUE-100000) != false) {
throw new RuntimeException();
}
} catch (OutOfMemoryError e) {}
try {
b.set(-1);
throw new RuntimeException();
} catch (IndexOutOfBoundsException e) {}
try {
b.set(Integer.MAX_VALUE-100000);
throw new RuntimeException();
} catch (OutOfMemoryError e) {}
try {
b.clear(-1);
throw new RuntimeException();
} catch (IndexOutOfBoundsException e) {}
try {
b.clear(Integer.MAX_VALUE-100000);
throw new RuntimeException();
} catch (OutOfMemoryError e) {}
b.set(100000);
if (b.get(100000) != true) throw new RuntimeException();
System.out.println("completed successfully");
}
}
Steps to reproduce:
Compile and run the following code
/* %W% %G%
* @author Kevin A. Smith
* BitSet constructor tests. These test creation of a bit set.
*/
import java.io.PrintStream;
import java.util.BitSet;
public class CtorTests implements Test {
final int SET_SIZE = 64;
final int MEM_LIMIT = 0x06FFFFFF;
/* Test interface */
public void run( String[] argv, PrintStream out ) {
/* put all tests into a try ... catch block */
try {
// create a BitSet with -1 number of bits
try {
BitSet b6 = new BitSet(-1);
out.println( "b6: failed, no exception" );
}
catch( NegativeArraySizeException e ) {
out.prinln( "b6 caused exception: " +
e + "( " + e.getMessage() +" )" );
}
// create a BitSet with -64 number of bits
try {
BitSet b7 = new BitSet(-64);
}
catch( NegativeArraySizeException e ) {
out.println( "b7 caused exception: " +
e + "( " + e.getMessage() +" )" );
}
} // end try
catch( Exception e ) { }
catch( Error e ) { }
// End of test
}
/* Standalone interface */
public static void main( String[] argv ) {
CtorTests test = new CtorTests();
test.run( argv, System.out );
}
}
MORE TEST CODE:
import java.util.BitSet;
class BitSetTest {
public static void main(String[] args) {
System.out.println("starting tests");
try {
BitSet b = new BitSet(Integer.MAX_VALUE);
throw new RuntimeException();
} catch (OutOfMemoryError e) {}
try {
BitSet b = new BitSet(-100);
throw new RuntimeException();
} catch (IllegalArgumentException e) {}
BitSet b = new BitSet(10);
try {
b.get(-1);
throw new RuntimeException();
} catch (IndexOutOfBoundsException e) {}
b.set(100);
if (b.get(100) != true) throw new RuntimeException();
try {
if (b.get(Integer.MAX_VALUE-100000) != false) {
throw new RuntimeException();
}
} catch (OutOfMemoryError e) {}
try {
b.set(-1);
throw new RuntimeException();
} catch (IndexOutOfBoundsException e) {}
try {
b.set(Integer.MAX_VALUE-100000);
throw new RuntimeException();
} catch (OutOfMemoryError e) {}
try {
b.clear(-1);
throw new RuntimeException();
} catch (IndexOutOfBoundsException e) {}
try {
b.clear(Integer.MAX_VALUE-100000);
throw new RuntimeException();
} catch (OutOfMemoryError e) {}
b.set(100000);
if (b.get(100000) != true) throw new RuntimeException();
System.out.println("completed successfully");
}
}