more IllegalArgumentException checks

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1687 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-08-29 13:13:24 +00:00
parent 2528a636a2
commit 5f7d87caff
14 changed files with 70 additions and 16 deletions

View File

@ -295,13 +295,19 @@ public class Util {
* @throws IllegalArgumentException
* if (classNames != null) and (0 < classNames.length) and
* (classNames[0] == null)
* @throws IllegalArgumentException
* if classNames.length == 0
*/
public static Iterable<Entrypoint> makeMainEntrypoints(final ClassLoaderReference loaderRef, final IClassHierarchy cha,
final String[] classNames) throws IllegalArgumentException, IllegalArgumentException {
final String[] classNames) throws IllegalArgumentException, IllegalArgumentException, IllegalArgumentException {
if (classNames == null) {
throw new IllegalArgumentException("classNames == null");
}
if (classNames[0] == null && 0 < classNames.length ) {
if (classNames.length == 0) {
throw new IllegalArgumentException("classNames.length == 0");
}
if (classNames[0] == null && 0 < classNames.length) {
throw new IllegalArgumentException("(0 < classNames.length) and (classNames[0] == null)");
}

View File

@ -30,9 +30,12 @@ public class SSAArrayLoadInstruction extends SSAArrayReferenceInstruction {
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) throws IllegalArgumentException {
if (defs.length == 0) {
if (defs != null && defs.length == 0) {
throw new IllegalArgumentException("defs.length == 0");
}
if (uses != null && uses.length < 2) {
throw new IllegalArgumentException("uses.length < 2");
}
return new SSAArrayLoadInstruction(defs == null ? result : defs[0], uses == null ? getArrayRef() : uses[0],
uses == null ? getIndex() : uses[1], getDeclaredType());
}

View File

@ -17,7 +17,7 @@ import com.ibm.wala.util.Exceptions;
/**
* @author sfink
*
*
*/
public class SSAArrayStoreInstruction extends SSAArrayReferenceInstruction {
@ -30,21 +30,23 @@ public class SSAArrayStoreInstruction extends SSAArrayReferenceInstruction {
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
return new SSAArrayStoreInstruction(
uses == null ? getArrayRef() : uses[0],
uses == null ? getIndex() : uses[1],
uses == null ? value : uses[2],
getDeclaredType());
if (uses != null && uses.length == 0) {
throw new IllegalArgumentException("uses.length == 0");
}
return new SSAArrayStoreInstruction(uses == null ? getArrayRef() : uses[0], uses == null ? getIndex() : uses[1],
uses == null ? value : uses[2], getDeclaredType());
}
@Override
public String toString(SymbolTable symbolTable, ValueDecorator d) {
return "arraystore " + getValueString(symbolTable, d, getArrayRef()) + "[" + getValueString(symbolTable, d, getIndex()) + "] = " + getValueString(symbolTable, d, value);
return "arraystore " + getValueString(symbolTable, d, getArrayRef()) + "[" + getValueString(symbolTable, d, getIndex())
+ "] = " + getValueString(symbolTable, d, value);
}
/**
* @see com.ibm.wala.ssa.SSAInstruction#visit(IVisitor)
* @throws IllegalArgumentException if v is null
* @throws IllegalArgumentException
* if v is null
*/
@Override
public void visit(IVisitor v) {

View File

@ -42,6 +42,9 @@ public class SSABinaryOpInstruction extends SSAInstruction {
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
if (uses != null && uses.length == 0) {
throw new IllegalArgumentException("uses.length == 0");
}
return new SSABinaryOpInstruction(operator, defs == null || defs.length == 0 ? result : defs[0], uses == null ? val1 : uses[0],
uses == null ? val2 : uses[1]);
}

View File

@ -37,6 +37,9 @@ public class SSACheckCastInstruction extends SSAInstruction {
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
if (defs != null && defs.length == 0) {
throw new IllegalArgumentException("(defs != null) and (defs.length == 0)");
}
return new SSACheckCastInstruction(defs == null ? result : defs[0], uses == null ? val : uses[0], declaredResultType);
}

View File

@ -44,7 +44,10 @@ public class SSAConditionalBranchInstruction extends SSAInstruction {
}
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
public SSAInstruction copyForSSA(int[] defs, int[] uses) throws IllegalArgumentException {
if (uses != null && uses.length == 0) {
throw new IllegalArgumentException("(uses != null) and (uses.length == 0)");
}
return new SSAConditionalBranchInstruction(operator, type, uses == null ? val1 : uses[0], uses == null ? val2 : uses[1]);
}

View File

@ -37,7 +37,10 @@ public class SSAConversionInstruction extends SSAInstruction {
}
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
public SSAInstruction copyForSSA(int[] defs, int[] uses) throws IllegalArgumentException {
if (uses != null && uses.length == 0) {
throw new IllegalArgumentException("(uses != null) and (uses.length == 0)");
}
return new SSAConversionInstruction(defs == null || defs.length == 0 ? result : defs[0], uses == null ? val : uses[0],
fromType, toType);
}

View File

@ -35,6 +35,12 @@ public class SSAInstanceofInstruction extends SSAInstruction {
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
if (defs != null && defs.length == 0) {
throw new IllegalArgumentException("defs.length == 0");
}
if (uses != null && uses.length == 0) {
throw new IllegalArgumentException("uses.length == 0");
}
return new SSAInstanceofInstruction(defs == null || defs.length == 0 ? result : defs[0], uses == null ? ref : uses[0],
checkedType);
}

View File

@ -31,6 +31,9 @@ public class SSALoadClassInstruction extends SSAInstruction {
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
if (defs != null && defs.length == 0) {
throw new IllegalArgumentException("(defs != null) and (defs.length == 0)");
}
return new SSALoadClassInstruction(defs == null ? lval : defs[0], typeRef);
}

View File

@ -58,6 +58,9 @@ public class SSAPiInstruction extends SSAUnaryOpInstruction {
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
if (defs != null && defs.length == 0) {
throw new IllegalArgumentException("defs.length == 0");
}
return new SSAPiInstruction(defs == null ? result : defs[0], uses == null ? val : uses[0], successorBlock, cause);
}

View File

@ -29,7 +29,10 @@ public class SSAUnaryOpInstruction extends SSAAbstractUnaryInstruction {
}
@Override
public SSAInstruction copyForSSA(int[] defs, int[] uses) {
public SSAInstruction copyForSSA(int[] defs, int[] uses) throws IllegalArgumentException {
if (uses != null && uses.length == 0) {
throw new IllegalArgumentException("(uses != null) and (uses.length == 0)");
}
return new SSAUnaryOpInstruction(operator, defs == null || defs.length == 0 ? result : defs[0], uses == null ? val : uses[0]);
}

View File

@ -95,13 +95,24 @@ public final class Atom {
return findOrCreate(utf8);
}
public static Atom findOrCreate(byte utf8[], int off, int len) throws IllegalArgumentException, IllegalArgumentException {
/**
* create an Atom from utf8[off] of length len
* @throws IllegalArgumentException if utf8.length <= off
*/
public static Atom findOrCreate(byte utf8[], int off, int len) throws IllegalArgumentException, IllegalArgumentException, IllegalArgumentException {
if (utf8 == null) {
throw new IllegalArgumentException("utf8 == null");
}
if (len < 0) {
throw new IllegalArgumentException("len must be >= 0, " + len);
}
if (off < 0) {
throw new IllegalArgumentException("off must be >= 0, " + off);
}
if (utf8.length < off + len) {
throw new IllegalArgumentException("utf8.length < off + len");
}
byte val[] = new byte[len];
for (int i = 0; i < len; ++i) {
val[i] = utf8[off++];

View File

@ -180,6 +180,9 @@ public class IntSetUtil {
if (data.length == 0) {
return -1;
}
if (low <= high && (low < 0 || high < 0)) {
throw new IllegalArgumentException("can't search negative indices " + low + " " + high);
}
if (low <= high) {
int mid = (low + high) / 2;
int midValue = data[mid];

View File

@ -18,7 +18,6 @@ package com.ibm.wala.util.intset;
*/
public class LongSetUtil {
/**
* @return index \in [low,high] s.t. data[index] = key, or -1 if not found
*/
@ -29,6 +28,9 @@ public class LongSetUtil {
if (data.length == 0) {
return -1;
}
if (low <= high && (low < 0 || high < 0)) {
throw new IllegalArgumentException("can't search negative indices");
}
if (low <= high) {
int mid = (low + high) / 2;
long midValue = data[mid];