more IllegalArgumentExceptions

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3279 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2009-03-11 17:44:29 +00:00
parent f63e374a4b
commit 4472b30826
39 changed files with 130 additions and 51 deletions

View File

@ -27,9 +27,13 @@ import com.ibm.wala.ipa.callgraph.propagation.InstanceKey;
public class ReflectionContextSelector {
public static ContextSelector createReflectionContextSelector(AnalysisOptions options) {
if (options == null) {
throw new IllegalArgumentException("null options");
}
// start with a dummy
ContextSelector result = new ContextSelector() {
public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey receiver) {
return null;
}

View File

@ -19,12 +19,8 @@ import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.UnimplementedError;
/**
*
* Abstraction of a set of PointTypes. These are immutable. TODO: fix for
* efficiency if needed.
*
* @author sfink
*
*/
public class SetType extends TypeAbstraction {
@ -42,6 +38,9 @@ public class SetType extends TypeAbstraction {
types = HashSetFactory.make(points.length);
int h = 0;
for (int i = 0; i < points.length; i++) {
if (points[i] == null) {
throw new IllegalArgumentException("points[" + i + "] is null");
}
TypeReference T = points[i].getType().getReference();
h ^= T.hashCode();
types.add(T);

View File

@ -12,7 +12,6 @@ package com.ibm.wala.dataflow.graph;
import com.ibm.wala.fixedpoint.impl.UnaryOperator;
import com.ibm.wala.fixpoint.BitVectorVariable;
import com.ibm.wala.util.debug.Assertions;
/**
@ -22,8 +21,8 @@ public class BitVectorUnionConstant extends UnaryOperator<BitVectorVariable> {
private final int c;
public BitVectorUnionConstant(int c) {
if (Assertions.verifyAssertions) {
Assertions._assert(c >= 0);
if (c < 0) {
throw new IllegalArgumentException("Invalid c: " + c);
}
this.c = c;
}

View File

@ -124,6 +124,9 @@ import com.ibm.wala.util.debug.Assertions;
}
public ThisFilteringHeapModel(HeapModel delegate, IClassHierarchy cha) {
if (delegate == null) {
throw new IllegalArgumentException("delegate null");
}
this.delegate = delegate;
this.cha = cha;
}

View File

@ -58,6 +58,9 @@ public class TrivialMethodEscape implements IMethodEscapeAnalysis, INodeEscapeAn
public boolean mayEscape(MethodReference allocMethod, int allocPC, MethodReference m) throws WalaException {
if (allocMethod == null) {
throw new IllegalArgumentException("null allocMethod");
}
// nodes:= set of call graph nodes representing method m
Set nodes = cg.getNodes(m);
if (nodes.size() == 0) {

View File

@ -71,6 +71,9 @@ public class GeneralStatement<T extends IVariable> extends AbstractStatement<T,
*/
public GeneralStatement(T lhs, AbstractOperator<T> operator) {
super();
if (operator == null) {
throw new IllegalArgumentException("null operator");
}
this.operator = operator;
this.lhs = lhs;
this.rhs = null;

View File

@ -66,6 +66,9 @@ public class BitVectorVariable extends AbstractVariable<BitVectorVariable> {
}
public boolean sameValue(BitVectorVariable other) {
if (other == null) {
throw new IllegalArgumentException("null other");
}
if (V == null) {
return (other.V == null);
} else {

View File

@ -52,8 +52,6 @@ import com.ibm.wala.util.graph.traverse.SlowDFSDiscoverTimeIterator;
import com.ibm.wala.util.strings.Atom;
/**
* @author sfink
*
*/
public class Util {
/**
@ -498,7 +496,13 @@ public class Util {
};
}
/**
* create a set holding the contents of an {@link Iterator}
*/
public static <T> Set<T> setify(Iterator<? extends T> x) {
if (x == null) {
throw new IllegalArgumentException("Null x");
}
Set<T> y = HashSetFactory.make();
while (x.hasNext()) {
y.add(x.next());

View File

@ -28,6 +28,9 @@ public class LocalPointerKey extends AbstractLocalPointerKey {
if (valueNumber <= 0) {
throw new IllegalArgumentException("illegal valueNumber: " + valueNumber);
}
if (node == null) {
throw new IllegalArgumentException("null node");
}
}
@Override

View File

@ -82,10 +82,9 @@ public class PointerAnalysisImpl extends AbstractPointerAnalysis {
this.pointerKeys = pointerKeys;
this.iKeyFactory = iKeyFactory;
this.pointsToMap = pointsToMap;
if (Assertions.verifyAssertions) {
Assertions._assert(iKeyFactory != null);
if (iKeyFactory == null) {
throw new IllegalArgumentException("null iKeyFactory");
}
H = makeHeapModel();
}

View File

@ -25,6 +25,9 @@ public class PointerKeyComparator implements Comparator {
private final IClassHierarchy cha;
public PointerKeyComparator(IClassHierarchy cha) {
if (cha == null) {
throw new IllegalArgumentException("null cha");
}
this.cha = cha;
}

View File

@ -84,8 +84,8 @@ public class ContainerContextSelector implements ContextSelector {
public ContainerContextSelector(IClassHierarchy cha, ZeroXInstanceKeys delegate) {
this.cha = cha;
this.delegate = delegate;
if (Assertions.verifyAssertions) {
Assertions._assert(delegate != null);
if (delegate == null) {
throw new IllegalArgumentException("null delegate");
}
}

View File

@ -61,8 +61,8 @@ public class DefaultPointerKeyFactory implements PointerKeyFactory {
}
public PointerKey getPointerKeyForStaticField(IField f) {
if (Assertions.verifyAssertions) {
Assertions._assert(f != null, "null f");
if (f == null) {
throw new IllegalArgumentException("null f");
}
return new StaticFieldKey(f);
}

View File

@ -319,8 +319,11 @@ public class ZeroXInstanceKeys implements InstanceKeyFactory {
|| C.getReference().equals(JavaLangStringBuilder) || C.getReference().equals(JavaLangAbstractStringBuilder);
}
public static boolean isThrowable(IClass C) {
return C.getClassHierarchy().isSubclassOf(C, C.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable));
public static boolean isThrowable(IClass c) {
if (c == null) {
throw new IllegalArgumentException("null c");
}
return c.getClassHierarchy().isSubclassOf(c, c.getClassHierarchy().lookupClass(TypeReference.JavaLangThrowable));
}
public boolean isStackTraceElement(IClass C) {

View File

@ -26,13 +26,15 @@ import com.ibm.wala.types.TypeReference;
/**
* An implementation of {@link ExtendedHeapModel} based on a
* normal {@link HeapModel}
*
*/
public class DelegatingExtendedHeapModel implements ExtendedHeapModel {
private final HeapModel h;
public DelegatingExtendedHeapModel(HeapModel h) {
if (h == null) {
throw new IllegalArgumentException("null h");
}
this.h = h;
}

View File

@ -104,6 +104,9 @@ public class CISlicer {
* Compute the set of pointer keys each statement refs
*/
public static Map<Statement, Set<PointerKey>> scanForRef(SDG sdg, PointerAnalysis pa) {
if (sdg == null) {
throw new IllegalArgumentException("null sdg");
}
return scanForRef(sdg, pa, ModRef.make());
}

View File

@ -31,8 +31,8 @@ public class SyntheticIR extends IR {
private final static boolean PARANOID = true;
/**
* Create an SSA form, induced over a list of instructions provided externally. This entrypoint is often used for,
* e.g., native method models
* Create an SSA form, induced over a list of instructions provided externally. This entrypoint is often used for, e.g., native
* method models
*
* @param method the method to construct SSA form for
* @param context the governing context
@ -72,7 +72,9 @@ public class SyntheticIR extends IR {
*/
private static SymbolTable makeSymbolTable(IMethod method, SSAInstruction[] instructions, Map<Integer, ConstantValue> constants,
AbstractCFG cfg) {
assert method != null;
if (method == null) {
throw new IllegalArgumentException("null method");
}
SymbolTable symbolTable = new SymbolTable(method.getNumberOfParameters());
// simulate allocation of value numbers
@ -82,13 +84,12 @@ public class SyntheticIR extends IR {
updateForInstruction(constants, symbolTable, s);
}
}
/**
* In InducedCFGs, we have nulled out phi instructions from the instruction array ... so go back and
* retrieve them now.
* In InducedCFGs, we have nulled out phi instructions from the instruction array ... so go back and retrieve them now.
*/
if (cfg instanceof InducedCFG) {
InducedCFG icfg = (InducedCFG)cfg;
InducedCFG icfg = (InducedCFG) cfg;
for (SSAPhiInstruction phi : icfg.getAllPhiInstructions()) {
updateForInstruction(constants, symbolTable, phi);
}

View File

@ -21,7 +21,6 @@ public class Array {
*/
public static Object get(Object array, int index) throws IllegalArgumentException, ArrayIndexOutOfBoundsException {
if (!array.getClass().isArray()) {
throw new IllegalArgumentException();
}

View File

@ -40,6 +40,9 @@ public class NullTestPiPolicy implements SSAPiNodePolicy {
if (symbolTable == null) {
throw new IllegalArgumentException("null symbolTable");
}
if (cond == null) {
throw new IllegalArgumentException("null cond");
}
if (symbolTable.isNullConstant(cond.getUse(1))) {
return Pair.<Integer,SSAInstruction>make(cond.getUse(0), cond);
}

View File

@ -13,14 +13,10 @@ package com.ibm.wala.ssa;
import java.util.Collection;
import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.shrike.Exceptions;
/**
* SSA instruction representing an array load.
*
* @author sfink
*
*/
public class SSAArrayLoadInstruction extends SSAArrayReferenceInstruction {
private final int result;
@ -76,8 +72,8 @@ public class SSAArrayLoadInstruction extends SSAArrayReferenceInstruction {
@Override
public int getDef(int i) {
if (Assertions.verifyAssertions) {
Assertions._assert(i == 0);
if (i != 0) {
throw new IllegalArgumentException("illegal i: " + i);
}
return result;
}

View File

@ -29,6 +29,9 @@ public abstract class SSAArrayReferenceInstruction extends SSAInstruction {
this.arrayref = arrayref;
this.index = index;
this.elementType = elementType;
if (elementType == null) {
throw new IllegalArgumentException("null elementType");
}
}
/*

View File

@ -16,8 +16,6 @@ import com.ibm.wala.types.TypeReference;
import com.ibm.wala.util.shrike.Exceptions;
/**
* @author sfink
*
*/
public class SSAArrayStoreInstruction extends SSAArrayReferenceInstruction {

View File

@ -197,6 +197,9 @@ public class SymbolTable {
}
public boolean isOne(int v) {
if (v < 0) {
throw new IllegalArgumentException("Illegal v: " + v);
}
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).isOneConstant();
}

View File

@ -44,6 +44,9 @@ public final class Descriptor {
* @return the canonical representative for this descriptor value
*/
public static Descriptor findOrCreate(TypeName[] parameters, TypeName returnType) {
if (returnType == null) {
throw new IllegalArgumentException("null returnType");
}
if (parameters != null && parameters.length == 0) {
parameters = null;
}

View File

@ -27,11 +27,15 @@ public final class Selector {
if (selectorStr == null) {
throw new IllegalArgumentException("null selectorStr");
}
String methodName = selectorStr.substring(0, selectorStr.indexOf('('));
String desc = selectorStr.substring(selectorStr.indexOf('('));
return new Selector(Atom.findOrCreateUnicodeAtom(methodName), Descriptor.findOrCreateUTF8(desc));
try {
String methodName = selectorStr.substring(0, selectorStr.indexOf('('));
String desc = selectorStr.substring(selectorStr.indexOf('('));
return new Selector(Atom.findOrCreateUnicodeAtom(methodName), Descriptor.findOrCreateUTF8(desc));
} catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid selectorStr: " + selectorStr);
}
}
public Selector(Atom name, Descriptor descriptor) {
this.name = name;
this.descriptor = descriptor;

View File

@ -13,10 +13,7 @@ package com.ibm.wala.util.collections;
import com.ibm.wala.annotations.NonNull;
/**
*
* intersection of two filters
*
* @author sfink
*/
public class Filtersection<T> implements Filter<T> {
@ -27,6 +24,12 @@ public class Filtersection<T> implements Filter<T> {
public Filtersection(Filter<T> a, Filter<T> b) {
this.a = a;
this.b = b;
if (a == null) {
throw new IllegalArgumentException("null a");
}
if (b == null) {
throw new IllegalArgumentException("null b");
}
}
public boolean accepts(T o) {

View File

@ -52,6 +52,9 @@ public class HashMapFactory {
* @return A ParanoidHashMap if DEBUG = true, a LinkedHashMap otherwise
*/
public static <K,V> HashMap<K,V> make(Map<K,V> t) {
if (t == null) {
throw new IllegalArgumentException("null t");
}
if (HashSetFactory.DEBUG) {
return new ParanoidHashMap<K,V>(t);
} else {

View File

@ -68,6 +68,9 @@ public class TwoLevelVector<T> implements IVector<T> {
* @see com.ibm.wala.util.intset.IntVector#set(int, int)
*/
public void set(int x, T value) {
if (x < 0) {
throw new IllegalArgumentException("illegal x: " + x);
}
int page = getPageNumber(x);
IVector<T> v = findOrCreatePage(page);
int localX = toLocalIndex(x, page);

View File

@ -85,6 +85,9 @@ public class AnalysisScopeReader {
}
public static void processScopeDefLine(AnalysisScope scope, ClassLoader javaLoader, String line) throws IOException {
if (line == null) {
throw new IllegalArgumentException("null line");
}
StringTokenizer toks = new StringTokenizer(line, "\n,");
if (!toks.hasMoreTokens()) {
return;

View File

@ -91,6 +91,9 @@ public final class FixedSizeBitVector implements Cloneable, java.io.Serializable
* @param bit the bit to be cleared
*/
public void clear(int bit) {
if (bit < 0) {
throw new IllegalArgumentException("illegal bit: " + bit);
}
int shiftBits = bit & LOW_MASK;
bits[subscript(bit)] &= ~(1 << shiftBits);
}

View File

@ -117,6 +117,12 @@ public class IntSetUtil {
if (factory == null) {
throw new IllegalArgumentException("null factory");
}
if (A == null) {
throw new IllegalArgumentException("null A");
}
if (B == null) {
throw new IllegalArgumentException("null B");
}
if (A instanceof SparseIntSet && B instanceof SparseIntSet) {
return SparseIntSet.diff((SparseIntSet) A, (SparseIntSet) B);
} else if (A instanceof SemiSparseMutableIntSet && B instanceof SemiSparseMutableIntSet) {

View File

@ -423,6 +423,9 @@ public class MutableSparseIntSet extends SparseIntSet implements MutableIntSet {
}
public <T extends BitVectorBase<T>> void removeAll(T v) {
if (v == null) {
throw new IllegalArgumentException("null v");
}
int ai = 0;
for (int i = 0; i < size; i++) {
if (!v.get(elements[i])) {

View File

@ -138,6 +138,9 @@ public class SparseIntSet implements IntSet {
}
public final int elementAt(int idx) throws NoSuchElementException {
if (idx < 0) {
throw new IllegalArgumentException("invalid idx: " + idx);
}
if (elements == null || idx >= size) {
throw new NoSuchElementException("Index: " + idx);
}

View File

@ -386,6 +386,9 @@ public class SparseLongSet implements LongSet {
}
public void foreach(LongSetAction action) {
if (action == null) {
throw new IllegalArgumentException("null action");
}
for (int i = 0; i < size; i++)
action.act(elements[i]);
}

View File

@ -33,6 +33,10 @@ public class CommandLine {
}
Properties result = new Properties();
for (int i = 0; i < args.length; i++) {
if (args[i] == null) {
// skip it
continue;
}
String key = parseForKey(args[i]);
if (key != null) {
if (args[i].contains("=")) {

View File

@ -95,6 +95,9 @@ public class FileProvider {
}
public static URL getResource(String fileName, ClassLoader loader) throws IOException {
if (CorePlugin.getDefault() == null && loader == null) {
throw new IllegalArgumentException("null loader");
}
return (CorePlugin.getDefault() == null) ? loader.getResource(fileName) : FileLocator.find(CorePlugin.getDefault().getBundle(),
new Path(fileName), null);
}

View File

@ -10,13 +10,8 @@
*******************************************************************************/
package com.ibm.wala.util.strings;
import com.ibm.wala.util.debug.Assertions;
/**
*
* A read-only byte array.
*
* @author sfink
*/
public final class ImmutableByteArray {
@ -34,10 +29,10 @@ public final class ImmutableByteArray {
if (b == null) {
throw new IllegalArgumentException("b is null");
}
this.b = new byte[length];
if (Assertions.verifyAssertions) {
Assertions._assert(b.length >= start + length, "illegal");
if (start < 0) {
throw new IllegalArgumentException("invalid start: " + start);
}
this.b = new byte[length];
System.arraycopy(b, start, this.b, 0, length);
}

View File

@ -27,6 +27,9 @@ public class GVUtil {
if (gvExe == null) {
throw new IllegalArgumentException("null gvExe");
}
if (psFile == null) {
throw new IllegalArgumentException("null psFile");
}
final GSViewLauncher gv = new GSViewLauncher();
gv.setGvExe(gvExe);
gv.setPsfile(psFile);

View File

@ -85,6 +85,9 @@ public class ViewIFDSLocalAction<T, P, F> extends Action {
public ViewIFDSLocalAction(SWTTreeViewer viewer, TabulationResult<T, P, F> result, String psFile, String dotFile, String dotExe,
String gvExe) {
if (result == null) {
throw new IllegalArgumentException("null result");
}
this.viewer = viewer;
this.supergraph = result.getProblem().getSupergraph();
this.psFile = psFile;