more documentation and IllegalArgumentExceptions

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3315 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2009-03-16 14:58:32 +00:00
parent f9aa9e6d96
commit c095615761
9 changed files with 47 additions and 16 deletions

View File

@ -55,6 +55,9 @@ public class ArraySet<T> extends AbstractSet<T> {
private static final ArraySet EMPTY = new ArraySet<Object>(0, true) { private static final ArraySet EMPTY = new ArraySet<Object>(0, true) {
@Override @Override
/**
* @throws UnsupportedOperationException unconditionally
*/
public boolean add(Object obj_) { public boolean add(Object obj_) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -179,6 +179,7 @@ public class JavaLauncher extends Launcher {
/** /**
* Wait for the spawned process to terminate. * Wait for the spawned process to terminate.
* @throws IllegalStateException if the process has not been started
*/ */
public void join() { public void join() {
if (stdOutDrain == null || stdErrDrain == null) { if (stdOutDrain == null || stdErrDrain == null) {

View File

@ -133,6 +133,9 @@ public class PointsToMap {
* record that a particular points-to-set has been unioned with another * record that a particular points-to-set has been unioned with another
*/ */
public void recordUnified(PointerKey key) { public void recordUnified(PointerKey key) {
if (key == null) {
throw new IllegalArgumentException("null key");
}
int i = findOrCreateIndex(key); int i = findOrCreateIndex(key);
pointsToSets.set(i, UNIFIED); pointsToSets.set(i, UNIFIED);
} }

View File

@ -19,8 +19,8 @@ import com.ibm.wala.util.debug.Assertions;
* By convention, symbol numbers start at 1 ... the "this" parameter will be symbol number 1 in a virtual method. * By convention, symbol numbers start at 1 ... the "this" parameter will be symbol number 1 in a virtual method.
*/ */
public class SymbolTable { public class SymbolTable {
private final static int MAX_VALUE_NUMBER = Integer.MAX_VALUE/4; private final static int MAX_VALUE_NUMBER = Integer.MAX_VALUE / 4;
/** /**
* value numbers for parameters to this method * value numbers for parameters to this method
@ -88,9 +88,16 @@ public class SymbolTable {
} }
} }
/**
* set the default value for a value number.
*
* @throws IllegalStateException if that value number value is already assigned
*/
public void setDefaultValue(int vn, final Object defaultValue) { public void setDefaultValue(int vn, final Object defaultValue) {
try { try {
Assertions._assert(values[vn] == null); if (values[vn] != null) {
throw new IllegalStateException("cannot set default value of vn " + vn);
}
values[vn] = new Value() { values[vn] = new Value() {
public boolean isStringConstant() { public boolean isStringConstant() {
@ -185,7 +192,7 @@ public class SymbolTable {
} }
} catch (ArrayIndexOutOfBoundsException e) { } catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid i: " + i); throw new IllegalArgumentException("invalid i: " + i);
} }
} }

View File

@ -51,8 +51,12 @@ public class IntSetUtil {
* *
* @param set * @param set
* @return a new MutableIntSet object with the same value as set * @return a new MutableIntSet object with the same value as set
* @throws UnimplementedError if (not ( set instanceof com.ibm.wala.util.intset.SparseIntSet ) ) and (not ( set instanceof com.ibm.wala.util.intset.BitVectorIntSet ) ) and (not ( set instanceof com.ibm.wala.util.intset.BimodalMutableIntSet ) ) and (not ( set instanceof com.ibm.wala.util.intset.DebuggingMutableIntSet ) ) and (not ( set instanceof com.ibm.wala.util.intset.SemiSparseMutableIntSet ) ) and (not ( set instanceof com.ibm.wala.util.intset.MutableSharedBitVectorIntSet ) ) * @throws UnimplementedError if (not ( set instanceof com.ibm.wala.util.intset.SparseIntSet ) ) and (not ( set instanceof
* @throws IllegalArgumentException if set == null * com.ibm.wala.util.intset.BitVectorIntSet ) ) and (not ( set instanceof com.ibm.wala.util.intset.BimodalMutableIntSet
* ) ) and (not ( set instanceof com.ibm.wala.util.intset.DebuggingMutableIntSet ) ) and (not ( set instanceof
* com.ibm.wala.util.intset.SemiSparseMutableIntSet ) ) and (not ( set instanceof
* com.ibm.wala.util.intset.MutableSharedBitVectorIntSet ) )
* @throws IllegalArgumentException if set == null
*/ */
public static MutableIntSet makeMutableCopy(IntSet set) throws IllegalArgumentException, UnimplementedError { public static MutableIntSet makeMutableCopy(IntSet set) throws IllegalArgumentException, UnimplementedError {
if (set == null) { if (set == null) {
@ -136,7 +140,7 @@ public class IntSetUtil {
/** /**
* Subtract two sets, i.e. a = a \ b. * Subtract two sets, i.e. a = a \ b.
* *
* @throws IllegalArgumentException if B == null * @throws IllegalArgumentException if B == null
*/ */
public static MutableIntSet removeAll(MutableIntSet A, IntSet B) throws IllegalArgumentException { public static MutableIntSet removeAll(MutableIntSet A, IntSet B) throws IllegalArgumentException {
if (B == null) { if (B == null) {
@ -175,8 +179,8 @@ public class IntSetUtil {
if (low <= high && (low < 0 || high < 0)) { if (low <= high && (low < 0 || high < 0)) {
throw new IllegalArgumentException("can't search negative indices " + low + " " + high); throw new IllegalArgumentException("can't search negative indices " + low + " " + high);
} }
if (high > data.length -1 ) { if (high > data.length - 1) {
high = data.length -1; high = data.length - 1;
} }
if (low <= high) { if (low <= high) {
int mid = (low + high) / 2; int mid = (low + high) / 2;
@ -201,16 +205,18 @@ public class IntSetUtil {
} }
/** /**
* @param defaultIntSetFactory * @param defaultIntSetFactory The defaultIntSetFactory to set.
* The defaultIntSetFactory to set.
*/ */
public static void setDefaultIntSetFactory(MutableIntSetFactory defaultIntSetFactory) { public static void setDefaultIntSetFactory(MutableIntSetFactory defaultIntSetFactory) {
if (defaultIntSetFactory == null) {
throw new IllegalArgumentException("null defaultIntSetFactory");
}
IntSetUtil.defaultIntSetFactory = defaultIntSetFactory; IntSetUtil.defaultIntSetFactory = defaultIntSetFactory;
} }
/** /**
* @return a new sparse int set which adds j to s * @return a new sparse int set which adds j to s
* @throws IllegalArgumentException if s == null * @throws IllegalArgumentException if s == null
*/ */
public static IntSet add(IntSet s, int j) throws IllegalArgumentException { public static IntSet add(IntSet s, int j) throws IllegalArgumentException {
if (s == null) { if (s == null) {
@ -220,7 +226,7 @@ public class IntSetUtil {
SparseIntSet sis = (SparseIntSet) s; SparseIntSet sis = (SparseIntSet) s;
return SparseIntSet.add(sis, j); return SparseIntSet.add(sis, j);
} else { } else {
// really slow. optimize as needed. // really slow. optimize as needed.
MutableSparseIntSet result = MutableSparseIntSet.make(s); MutableSparseIntSet result = MutableSparseIntSet.make(s);
result.add(j); result.add(j);
return result; return result;

View File

@ -22,7 +22,6 @@ import java.util.TreeSet;
public class MutableSparseIntSetFactory implements MutableIntSetFactory { public class MutableSparseIntSetFactory implements MutableIntSetFactory {
/** /**
* @param set
* @throws IllegalArgumentException if set is null * @throws IllegalArgumentException if set is null
*/ */
public MutableIntSet make(int[] set) { public MutableIntSet make(int[] set) {

View File

@ -182,6 +182,9 @@ public class OrdinalSet<T> implements Iterable<T> {
if (c == null) { if (c == null) {
throw new IllegalArgumentException("c is null"); throw new IllegalArgumentException("c is null");
} }
if (m == null) {
throw new IllegalArgumentException("m is null");
}
MutableSparseIntSet s = MutableSparseIntSet.makeEmpty(); MutableSparseIntSet s = MutableSparseIntSet.makeEmpty();
for (Iterator<T> it = c.iterator(); it.hasNext();) { for (Iterator<T> it = c.iterator(); it.hasNext();) {
int index = m.getMappedIndex(it.next()); int index = m.getMappedIndex(it.next());

View File

@ -161,10 +161,16 @@ public class FileUtil {
return new FileOutputStream(f); return new FileOutputStream(f);
} }
/**
* read fully the contents of s and return a byte array holding the result
* @throws IOException
*/
public static byte[] readBytes(InputStream s) throws IOException { public static byte[] readBytes(InputStream s) throws IOException {
byte[] b; if (s == null) {
throw new IllegalArgumentException("null s");
}
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
b = new byte[1024]; byte[] b = new byte[1024];
int n = s.read(b); int n = s.read(b);
while (n != -1) { while (n != -1) {
out.write(b, 0, n); out.write(b, 0, n);

View File

@ -236,6 +236,7 @@ public final class Atom implements Serializable {
* "[Ljava/lang/String;" or "[[I" * "[Ljava/lang/String;" or "[[I"
* *
* @return dimensionality - something like "1" or "2" * @return dimensionality - something like "1" or "2"
* @throws IllegalStateException if this Atom does not represent an array
*/ */
public final int parseForArrayDimensionality() throws IllegalArgumentException { public final int parseForArrayDimensionality() throws IllegalArgumentException {
if (val.length == 0) { if (val.length == 0) {
@ -255,6 +256,8 @@ public final class Atom implements Serializable {
/** /**
* Return the innermost element type reference for an array * Return the innermost element type reference for an array
*
* @throws IllegalStateException if this Atom does not represent an array descriptor
*/ */
public final Atom parseForInnermostArrayElementDescriptor() throws IllegalArgumentException { public final Atom parseForInnermostArrayElementDescriptor() throws IllegalArgumentException {
if (val.length == 0) { if (val.length == 0) {