check arguments to public methods

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1018 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-04-26 20:35:01 +00:00
parent b9e9306198
commit 876a5225ec
26 changed files with 241 additions and 66 deletions

View File

@ -49,7 +49,7 @@ final public class BinaryOpInstruction extends Instruction {
return r;
}
public static BinaryOpInstruction make(String type, Operator operator) {
public static BinaryOpInstruction make(String type, Operator operator) throws IllegalArgumentException {
int t = Util.getTypeIndex(type);
if (t < 0) {
throw new IllegalArgumentException("Invalid type for BinaryOp: " + type);

View File

@ -58,6 +58,9 @@ final public class CheckCastInstruction extends Instruction {
}
public void visit(Visitor v) {
if (v == null) {
throw new IllegalArgumentException();
}
v.visitCheckCast(this);
}

View File

@ -15,7 +15,9 @@ package com.ibm.wala.shrikeBT;
*/
final public class ComparisonInstruction extends Instruction {
public enum Operator {
CMP, CMPL, CMPG;
CMP,
CMPL,
CMPG;
@Override
public String toString() {
@ -28,6 +30,7 @@ final public class ComparisonInstruction extends Instruction {
}
private final static ComparisonInstruction preallocatedLCMP = new ComparisonInstruction((short) OP_lcmp);
private final static ComparisonInstruction[] preallocatedFloatingCompares = preallocateFloatingCompares();
private static ComparisonInstruction[] preallocateFloatingCompares() {
@ -38,7 +41,7 @@ final public class ComparisonInstruction extends Instruction {
return r;
}
public static ComparisonInstruction make(String type, Operator operator) {
public static ComparisonInstruction make(String type, Operator operator) throws IllegalArgumentException {
int t = Util.getTypeIndex(type);
switch (t) {
case TYPE_long_index:
@ -124,10 +127,13 @@ final public class ComparisonInstruction extends Instruction {
public String toString() {
return "Comparison(" + getType() + "," + getOperator() + ")";
}
/* (non-Javadoc)
* @see com.ibm.domo.cfg.IInstruction#isPEI()
*/
public boolean isPEI() {
return false;
}
/*
* (non-Javadoc)
*
* @see com.ibm.domo.cfg.IInstruction#isPEI()
*/
public boolean isPEI() {
return false;
}
}

View File

@ -41,7 +41,7 @@ public final class ConditionalBranchInstruction extends Instruction {
this.label = label;
}
public static ConditionalBranchInstruction make(String type, Operator operator, int label) {
public static ConditionalBranchInstruction make(String type, Operator operator, int label) throws IllegalArgumentException {
int t = Util.getTypeIndex(type);
short opcode;

View File

@ -94,7 +94,10 @@ public final class DupInstruction extends Instruction {
return "Dup(" + size + "," + delta + ")";
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException {
if (v == null) {
throw new IllegalArgumentException("illegal null visitor");
}
v.visitDup(this);
}
/* (non-Javadoc)

View File

@ -133,7 +133,10 @@ public class GetInstruction extends Instruction {
+ ")";
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException {
if (v == null) {
throw new IllegalArgumentException();
}
v.visitGet(this);
}
/* (non-Javadoc)

View File

@ -82,7 +82,10 @@ public final class GotoInstruction extends Instruction {
return "Goto(" + getLabel() + ")";
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException {
if (v == null) {
throw new IllegalArgumentException();
}
v.visitGoto(this);
}

View File

@ -54,7 +54,10 @@ public final class InstanceofInstruction extends Instruction {
return 1;
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException{
if (v == null) {
throw new IllegalArgumentException();
}
v.visitInstanceof(this);
}

View File

@ -25,7 +25,7 @@ public class InvokeInstruction extends Instruction implements IInvokeInstruction
this.opcode = opcode;
}
public static InvokeInstruction make(String type, String className, String methodName, Dispatch mode) {
public static InvokeInstruction make(String type, String className, String methodName, Dispatch mode) throws NullPointerException {
if (type == null) {
throw new NullPointerException("type must not be null");
}
@ -35,6 +35,9 @@ public class InvokeInstruction extends Instruction implements IInvokeInstruction
if (methodName == null) {
throw new NullPointerException("methodName must not be null");
}
if (mode == null) {
throw new NullPointerException("mode must not be null");
}
return new InvokeInstruction((short) (OP_invokevirtual + mode.ordinal()), type, className, methodName);
}

View File

@ -46,7 +46,10 @@ public final class MonitorInstruction extends Instruction {
return 1;
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException{
if (v == null) {
throw new IllegalArgumentException();
}
v.visitMonitor(this);
}

View File

@ -98,7 +98,10 @@ public final class NewInstruction extends Instruction {
return "New(" + type + "," + arrayBoundsCount + ")";
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException {
if (v == null) {
throw new IllegalArgumentException();
}
v.visitNew(this);
}

View File

@ -49,17 +49,23 @@ public final class PopInstruction extends Instruction {
return size;
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException {
if (v == null) {
throw new IllegalArgumentException();
}
v.visitPop(this);
}
public String toString() {
return "Pop(" + size + ")";
}
/* (non-Javadoc)
* @see com.ibm.domo.cfg.IInstruction#isPEI()
*/
public boolean isPEI() {
return false;
}
/*
* (non-Javadoc)
*
* @see com.ibm.domo.cfg.IInstruction#isPEI()
*/
public boolean isPEI() {
return false;
}
}

View File

@ -34,7 +34,7 @@ public final class ShiftInstruction extends Instruction {
return r;
}
public static ShiftInstruction make(String type, Operator operator) {
public static ShiftInstruction make(String type, Operator operator) throws IllegalArgumentException {
int t = Util.getTypeIndex(type);
if (t < 0 || t > TYPE_long_index) {
throw new IllegalArgumentException("Cannot apply shift to type " + type);

View File

@ -129,7 +129,10 @@ public final class SwitchInstruction extends Instruction {
return b.toString();
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException {
if (v == null) {
throw new IllegalArgumentException();
}
v.visitSwitch(this);
}

View File

@ -40,7 +40,10 @@ public final class ThrowInstruction extends Instruction {
return 1;
}
public void visit(Visitor v) {
public void visit(Visitor v) throws IllegalArgumentException {
if (v == null) {
throw new IllegalArgumentException();
}
v.visitThrow(this);
}

View File

@ -40,7 +40,7 @@ public final class UnaryOpInstruction extends Instruction {
return r;
}
public static UnaryOpInstruction make(String type, Operator operator) {
public static UnaryOpInstruction make(String type, Operator operator) throws IllegalArgumentException {
int t = Util.getTypeIndex(type);
if (t < 0 || t > TYPE_double_index) {
throw new IllegalArgumentException("Type " + type + " cannot have a unary operator applied");

View File

@ -52,30 +52,55 @@ public class InstructionTypeCounter implements MethodData.Results {
private final static String key = InstructionTypeCounter.class.getName();
private int countMonitors;
private int countGets;
private int countPuts;
private int countArrayLoads;
private int countArrayStores;
private int countInvokes;
private int countArrayLengths;
private int countBinaryOps;
private int countCheckCasts;
private int countComparisons;
private int countConditionalBranches;
private int countConstants;
private int countConversions;
private int countDups;
private int countGotos;
private int countInstanceOfs;
private int countLocalLoads;
private int countLocalStores;
private int countNews;
private int countPops;
private int countReturns;
private int countShifts;
private int countSwaps;
private int countSwitches;
private int countThrows;
private int countUnaryOps;
InstructionTypeCounter(MethodData info) {
@ -233,107 +258,185 @@ public class InstructionTypeCounter implements MethodData.Results {
return true;
}
public static int getArrayLoadCount(MethodData info) {
public static int getArrayLoadCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countArrayLoads;
}
public static int getArrayStoreCount(MethodData info) {
public static int getArrayStoreCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countArrayStores;
}
public static int getGetCount(MethodData info) {
public static int getGetCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countGets;
}
public static int getPutCount(MethodData info) {
public static int getPutCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countPuts;
}
public static int getMonitorCount(MethodData info) {
public static int getMonitorCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countMonitors;
}
public static int getInvokeCount(MethodData info) {
public static int getInvokeCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countInvokes;
}
public static int getComparisonCount(MethodData info) {
public static int getComparisonCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countComparisons;
}
public static int getArrayLengthCount(MethodData info) {
public static int getArrayLengthCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countArrayLengths;
}
public static int getConstantCount(MethodData info) {
public static int getConstantCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countConstants;
}
public static int getShiftCount(MethodData info) {
public static int getShiftCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countShifts;
}
public static int getSwitchesCount(MethodData info) {
public static int getSwitchesCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countSwitches;
}
public static int getSwapCount(MethodData info) {
public static int getSwapCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countSwaps;
}
public static int getBinaryOpCount(MethodData info) {
public static int getBinaryOpCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countBinaryOps;
}
public static int getCheckCastCount(MethodData info) {
public static int getCheckCastCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countCheckCasts;
}
public static int getThrowCount(MethodData info) {
public static int getThrowCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countThrows;
}
public static int getConditionalBranchCount(MethodData info) {
public static int getConditionalBranchCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countConditionalBranches;
}
public static int getConversionCount(MethodData info) {
public static int getConversionCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countConversions;
}
public static int getDupCount(MethodData info) {
public static int getDupCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countDups;
}
public static int getGotoCount(MethodData info) {
public static int getGotoCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countGotos;
}
public static int getReturnCount(MethodData info) {
public static int getReturnCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countReturns;
}
public static int getInstanceOfCount(MethodData info) {
public static int getInstanceOfCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countInstanceOfs;
}
public static int getLocalLoadCount(MethodData info) {
public static int getLocalLoadCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countLocalLoads;
}
public static int getLocalStoreCount(MethodData info) {
public static int getLocalStoreCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countLocalStores;
}
public static int getNewCount(MethodData info) {
public static int getNewCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countNews;
}
public static int getPopCount(MethodData info) {
public static int getPopCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countPops;
}
public static int getUnaryOpCount(MethodData info) {
public static int getUnaryOpCount(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
return getCounter(info).countUnaryOps;
}

View File

@ -75,7 +75,10 @@ public class LocalAllocator implements MethodData.Results {
/**
* Allocates a new local variable of the specified type.
*/
public static int allocate(MethodData info, int count) {
public static int allocate(MethodData info, int count) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
LocalAllocator l = (LocalAllocator) info.getInfo(key);
if (l == null) {
l = new LocalAllocator(info);
@ -85,14 +88,14 @@ public class LocalAllocator implements MethodData.Results {
return l.allocateLocals(count);
}
public static int allocate(MethodData info, String type) {
public static int allocate(MethodData info, String type) throws IllegalArgumentException {
return allocate(info, type == null ? 2 : Util.getWordSize(type));
}
/**
* Allocates a new local that will fit any type.
*/
public static int allocate(MethodData info) {
public static int allocate(MethodData info) throws IllegalArgumentException {
return allocate(info, null);
}
}

View File

@ -58,7 +58,10 @@ public class ThisAssignmentChecker implements MethodData.Results {
/**
* @return true iff 'this' is assigned to by the method
*/
public static boolean isThisAssigned(MethodData info) {
public static boolean isThisAssigned(MethodData info) throws IllegalArgumentException {
if (info == null) {
throw new IllegalArgumentException();
}
ThisAssignmentChecker c = (ThisAssignmentChecker) info.getInfo(key);
if (c == null) {
c = new ThisAssignmentChecker(info);

View File

@ -54,7 +54,10 @@ final public class CTDecoder extends Decoder {
* Build a ConstantPoolReader implementation to read the constant pool from
* 'cr'.
*/
public static ConstantPoolReader makeConstantPoolReader(ClassReader cr) {
public static ConstantPoolReader makeConstantPoolReader(ClassReader cr) throws IllegalArgumentException {
if (cr == null) {
throw new IllegalArgumentException("illegal null cr");
}
return new CPReader(cr.getCP());
}

View File

@ -21,7 +21,11 @@ import com.ibm.wala.shrikeCT.InvalidClassFileException;
* @author roca@us.ibm.com
*/
public class CTUtils {
public static void addClassToHierarchy(ClassHierarchyStore store, ClassReader cr) throws InvalidClassFileException {
public static void addClassToHierarchy(ClassHierarchyStore store, ClassReader cr) throws InvalidClassFileException,
IllegalArgumentException {
if (cr == null) {
throw new IllegalArgumentException();
}
String[] superInterfaces = new String[cr.getInterfaceCount()];
for (int i = 0; i < superInterfaces.length; i++) {
superInterfaces[i] = CTDecoder.convertClassToType(cr.getInterfaceName(i));

View File

@ -71,7 +71,7 @@ final public class OfflineInstrumenter extends OfflineInstrumenterBase {
* result of out.emitClass(). You can add new fields and methods to 'code' (or
* make other changes) before calling this method.
*/
public void outputModifiedClass(ClassInstrumenter out, ClassWriter code) throws IOException {
public void outputModifiedClass(ClassInstrumenter out, ClassWriter code) throws IllegalStateException, IOException {
internalOutputModifiedClass(out, code);
}
@ -79,7 +79,10 @@ final public class OfflineInstrumenter extends OfflineInstrumenterBase {
* Update the original class with some method changes. This method calls
* out.emitClass() for you.
*/
public void outputModifiedClass(ClassInstrumenter out) throws IOException {
public void outputModifiedClass(ClassInstrumenter out) throws IllegalArgumentException, IOException {
if (out == null) {
throw new IllegalArgumentException();
}
try {
internalOutputModifiedClass(out, out.emitClass());
} catch (InvalidClassFileException e) {

View File

@ -327,7 +327,10 @@ public abstract class OfflineInstrumenterBase {
* Read a list of class file names from a stream and add them to the list of
* things to instrument.
*/
final public void readInputClasses(InputStream s) throws IOException {
final public void readInputClasses(InputStream s) throws IOException, IllegalArgumentException {
if (s == null) {
throw new IllegalArgumentException("illegal null inputStream");
}
String str;
BufferedReader r = new BufferedReader(new InputStreamReader(s));
while ((str = r.readLine()) != null) {

View File

@ -186,7 +186,10 @@ public final class ClassWriter implements ClassConstants {
* but may slow down performance because the raw pool must be
* completely parsed
*/
public void setRawCP(ConstantPoolParser cp, boolean cacheEntries) throws InvalidClassFileException {
public void setRawCP(ConstantPoolParser cp, boolean cacheEntries) throws InvalidClassFileException, IllegalArgumentException {
if (cp == null) {
throw new IllegalArgumentException();
}
if (rawCP != null) {
throw new IllegalArgumentException("Cannot set raw constant pool twice");
}

View File

@ -56,7 +56,11 @@ public final class LineNumberTableReader extends AttributeReader {
* that that byte belongs to, or null if there is no line number data
* in the Code
*/
public static int[] makeBytecodeToSourceMap(CodeReader code) throws InvalidClassFileException {
public static int[] makeBytecodeToSourceMap(CodeReader code) throws InvalidClassFileException, IllegalArgumentException {
if (code == null) {
throw new IllegalArgumentException();
}
int[] r = null;
ClassReader cr = code.getClassReader();

View File

@ -63,7 +63,11 @@ public final class LocalVariableTableReader extends AttributeReader {
* typeIndex) for each local variable; a pair (0,0) indicates there is
* no information for that local variable at that offset
*/
public static int[][] makeVarMap(CodeReader code) throws InvalidClassFileException {
public static int[][] makeVarMap(CodeReader code) throws InvalidClassFileException, IllegalArgumentException{
if (code == null) {
throw new IllegalArgumentException();
}
int[][] r = null;
ClassReader cr = code.getClassReader();