more argument checking

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1163 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-05-22 02:26:58 +00:00
parent 637bdaf379
commit 42e43625cd
18 changed files with 109 additions and 8 deletions

View File

@ -188,6 +188,9 @@ public class FactoryBypassInterpreter implements RTAContextInterpreter, SSAConte
* com.ibm.wala.util.warnings.WarningSet)
*/
public int getNumberOfStatements(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
SpecializedFactoryMethod m = findOrCreateSpecializedFactoryMethod(node);
return m.allInstructions.size();
}
@ -654,6 +657,9 @@ public class FactoryBypassInterpreter implements RTAContextInterpreter, SSAConte
* com.ibm.wala.util.warnings.WarningSet)
*/
public Iterator iterateFieldsRead(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
SpecializedFactoryMethod m = findOrCreateSpecializedFactoryMethod(node);
try {
return CodeScanner.iterateFieldsRead(m, warnings);
@ -671,6 +677,9 @@ public class FactoryBypassInterpreter implements RTAContextInterpreter, SSAConte
* com.ibm.wala.util.warnings.WarningSet)
*/
public Iterator iterateFieldsWritten(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
SpecializedFactoryMethod m = findOrCreateSpecializedFactoryMethod(node);
try {
return CodeScanner.iterateFieldsWritten(m, warnings);
@ -706,6 +715,9 @@ public class FactoryBypassInterpreter implements RTAContextInterpreter, SSAConte
}
public boolean hasObjectArrayLoad(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
SpecializedFactoryMethod m = findOrCreateSpecializedFactoryMethod(node);
try {
return CodeScanner.hasObjectArrayLoad(m, warnings);
@ -717,6 +729,9 @@ public class FactoryBypassInterpreter implements RTAContextInterpreter, SSAConte
}
public boolean hasObjectArrayStore(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
SpecializedFactoryMethod m = findOrCreateSpecializedFactoryMethod(node);
try {
return CodeScanner.hasObjectArrayStore(m, warnings);
@ -728,6 +743,9 @@ public class FactoryBypassInterpreter implements RTAContextInterpreter, SSAConte
}
public Iterator iterateCastTypes(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
SpecializedFactoryMethod m = findOrCreateSpecializedFactoryMethod(node);
try {
return CodeScanner.iterateCastTypes(m, warnings);

View File

@ -112,6 +112,9 @@ public class EclipseProjectPath {
}
public static EclipseProjectPath make(IPath workspaceRootPath, IJavaProject project) {
if (workspaceRootPath == null) {
throw new IllegalArgumentException("workspaceRootPath is null");
}
return new EclipseProjectPath(workspaceRootPath, project);
}

View File

@ -51,11 +51,17 @@ import com.ibm.wala.util.debug.Assertions;
public class JdtUtil {
public static String getFilePath(IJavaElement javaElt) {
if (javaElt == null) {
throw new IllegalArgumentException("javaElt is null");
}
String filePath = javaElt.getPath().toString();
return filePath;
}
public static String getPackageName(ICompilationUnit cu) {
if (cu == null) {
throw new IllegalArgumentException("cu is null");
}
try {
IPackageDeclaration[] pkgDecl = cu.getPackageDeclarations();
@ -72,6 +78,9 @@ public class JdtUtil {
}
public static String getFullyQualifiedClassName(IType type) {
if (type == null) {
throw new IllegalArgumentException("type is null");
}
ICompilationUnit cu = (ICompilationUnit) type.getParent();
String packageName = getPackageName(cu);
String className = type.getElementName();
@ -112,8 +121,12 @@ public class JdtUtil {
*
* @param javaElt
* @return
* @throws IllegalArgumentException if javaElt is null
*/
public static String getJdtHandleString(IJavaElement javaElt) {
if (javaElt == null) {
throw new IllegalArgumentException("javaElt is null");
}
return javaElt.getHandleIdentifier();
}
@ -134,6 +147,9 @@ public class JdtUtil {
}
public static IJavaProject getProject(IJavaElement javaElt) {
if (javaElt == null) {
throw new IllegalArgumentException("javaElt is null");
}
IJavaProject javaProject = javaElt.getJavaProject();
return javaProject;
}
@ -156,6 +172,9 @@ public class JdtUtil {
}
public static IJavaProject getJavaProject(IFile appJar) {
if (appJar == null) {
throw new IllegalArgumentException("appJar is null");
}
String projectName = appJar.getProject().getName();
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
IJavaModel javaModel = JavaCore.create(workspaceRoot);

View File

@ -114,6 +114,9 @@ public class ETypeHierarchyWrapper {
}
public static ETypeHierarchyWrapper loadFromFile(String fileName) throws FileNotFoundException {
if (fileName == null) {
throw new IllegalArgumentException("fileName is null");
}
System.err.println("eload..");
ETypeHierarchy t = eloadFromFile(fileName);
Assertions.productionAssertion(t != null);

View File

@ -259,8 +259,12 @@ public abstract class BasicCallGraph extends AbstractNumberedGraph<CGNode> imple
/**
* Dump this callgraph to the specified file in dotty(1) format.
* @throws IllegalArgumentException if filename is null
*/
public void dump(String filename) {
if (filename == null) {
throw new IllegalArgumentException("filename is null");
}
File file = new File(filename);
try {
PrintWriter out = new PrintWriter(new FileOutputStream(file));

View File

@ -15,8 +15,10 @@ public abstract class AbstractFieldPointerKey extends AbstractPointerKey impleme
final protected InstanceKey instance;
protected AbstractFieldPointerKey(InstanceKey container) {
if (container == null) {
throw new IllegalArgumentException("container is null");
}
this.instance = container;
assert container != null;
}
public InstanceKey getInstanceKey() {

View File

@ -175,9 +175,9 @@ public abstract class SSAPropagationCallGraphBuilder extends PropagationCallGrap
private final boolean usePreTransitiveSolver;
protected SSAPropagationCallGraphBuilder(ClassHierarchy cha, WarningSet warnings, AnalysisOptions options,
PointerKeyFactory pointerKeyFactory, boolean preTransitive) {
PointerKeyFactory pointerKeyFactory) {
super(cha, warnings, options, pointerKeyFactory);
this.usePreTransitiveSolver = preTransitive;
this.usePreTransitiveSolver = options.usePreTransitiveSolver();
}
public SSAContextInterpreter getCFAContextInterpreter() {

View File

@ -33,7 +33,7 @@ public abstract class CFABuilder extends SSAPropagationCallGraphBuilder {
* @throws NullPointerException if options is null
*/
public CFABuilder(ClassHierarchy cha, WarningSet warnings, AnalysisOptions options) throws NullPointerException {
super(cha, warnings, options, new CFAPointerKeys(), options.usePreTransitiveSolver());
super(cha, warnings, options, new CFAPointerKeys());
}
public SSAContextInterpreter makeDefaultContextInterpreters(SSAContextInterpreter appContextInterpreter, AnalysisOptions options,

View File

@ -70,6 +70,9 @@ public class DefaultRTAInterpreter implements RTAContextInterpreter {
* @see com.ibm.wala.ipa.rta.RTAContextInterpreter#getAllocatedTypes(com.ibm.wala.classLoader.IMethod, com.ibm.detox.ipa.callgraph.Context, com.ibm.wala.util.warnings.WarningSet)
*/
public Iterator<NewSiteReference> iterateNewSites(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
return getNodeInterpreter(node).iterateNewSites(node,warnings);
}
@ -97,6 +100,9 @@ public class DefaultRTAInterpreter implements RTAContextInterpreter {
* @see com.ibm.wala.ipa.callgraph.propagation.xta.XTAContextInterpreter#iterateFieldsWritten(com.ibm.wala.ipa.callgraph.CGNode, com.ibm.wala.util.warnings.WarningSet)
*/
public Iterator iterateFieldsWritten(CGNode node, WarningSet warnings) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
return getNodeInterpreter(node).iterateFieldsWritten(node, warnings);
}

View File

@ -57,8 +57,9 @@ public class TypeBasedPointerAnalysis extends AbstractPointerAnalysis {
/**
* @param klasses
* Collection<IClass>
* @throws AssertionError if klasses is null
*/
public TypeBasedPointerAnalysis(AnalysisOptions options, Collection<IClass> klasses, CallGraph cg) {
public TypeBasedPointerAnalysis(AnalysisOptions options, Collection<IClass> klasses, CallGraph cg) throws AssertionError {
super(cg, makeInstanceKeys(klasses));
this.klasses = klasses;
heapModel = new TypeBasedHeapModel(options, klasses, cg);
@ -69,6 +70,7 @@ public class TypeBasedPointerAnalysis extends AbstractPointerAnalysis {
* Collection<IClass>
*/
private static MutableMapping<InstanceKey> makeInstanceKeys(Collection<IClass> c) {
assert c != null;
MutableMapping<InstanceKey> result = new MutableMapping<InstanceKey>();
for (Iterator<IClass> it = c.iterator(); it.hasNext();) {
IClass klass = it.next();

View File

@ -39,9 +39,10 @@ public class SyntheticIR extends IR {
* a Map giving information on constant values for the symbol table
* @param warnings
* an object to track analysis warnings with
* @throws AssertionError if method is null
*/
public SyntheticIR(IMethod method, Context context, AbstractCFG cfg, SSAInstruction[] instructions, SSAOptions options,
Map<Integer, ConstantValue> constants, WarningSet warnings) {
Map<Integer, ConstantValue> constants, WarningSet warnings) throws AssertionError {
super(method, instructions, makeSymbolTable(method, instructions, constants), new SSACFG(method, cfg, instructions, warnings),
options);
@ -55,6 +56,7 @@ public class SyntheticIR extends IR {
* Map: valune number (Integer) -> ConstantValue
*/
private static SymbolTable makeSymbolTable(IMethod method, SSAInstruction[] instructions, Map<Integer, ConstantValue> constants) {
assert method != null;
SymbolTable symbolTable = new SymbolTable(method.getNumberOfParameters());
// simulate allocation of value numbers

View File

@ -134,6 +134,9 @@ public class DelegatingNumberedEdgeManager<T extends INodeWithNumberedEdges> imp
* @see com.ibm.wala.util.graph.EdgeManager#getSuccNodeCount(com.ibm.wala.util.graph.Node)
*/
public int getSuccNodeCount(T N) {
if (N == null) {
throw new IllegalArgumentException("N is null");
}
INodeWithNumberedEdges en = (INodeWithNumberedEdges) N;
return en.getSuccNumbers().size();
}
@ -145,6 +148,9 @@ public class DelegatingNumberedEdgeManager<T extends INodeWithNumberedEdges> imp
* com.ibm.wala.util.graph.Node)
*/
public void addEdge(T src, T dst) {
if (dst == null) {
throw new IllegalArgumentException("dst is null");
}
src.addSucc(dst.getGraphNodeId());
}
@ -158,6 +164,9 @@ public class DelegatingNumberedEdgeManager<T extends INodeWithNumberedEdges> imp
* @see com.ibm.wala.util.graph.EdgeManager#removeEdges(com.ibm.wala.util.graph.Node)
*/
public void removeAllIncidentEdges(T node) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
INodeWithNumberedEdges n = (INodeWithNumberedEdges) node;
n.removeAllIncidentEdges();
}

View File

@ -73,8 +73,12 @@ public class BoundedBFSIterator<T> implements Iterator<T> {
*
* @param G
* the graph whose nodes to enumerate
* @throws IllegalArgumentException if G is null
*/
public BoundedBFSIterator(Graph<T> G, T N, int k) {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
this.k = k;
boundary = new int[k];
init(G, new NonNullSingletonIterator<T>(N));
@ -88,8 +92,12 @@ public class BoundedBFSIterator<T> implements Iterator<T> {
* the graph whose nodes to enumerate
* @param nodes
* the set of nodes from which to start searching
* @throws IllegalArgumentException if G is null
*/
public BoundedBFSIterator(Graph<T> G, Iterator <? extends T> nodes, int k) {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
this.k = k;
boundary = new int[k];
init(G, nodes);

View File

@ -67,6 +67,9 @@ public class SparseIntSet implements IntSet {
* @param backingArray
*/
protected SparseIntSet(int[] backingArray) {
if (backingArray == null) {
throw new IllegalArgumentException("backingArray is null");
}
elements = backingArray;
this.size = backingArray.length;
}

View File

@ -67,6 +67,9 @@ public class SparseLongSet implements LongSet {
* @param backingArray
*/
protected SparseLongSet(long[] backingArray) {
if (backingArray == null) {
throw new IllegalArgumentException("backingArray is null");
}
elements = backingArray;
this.size = backingArray.length;
}

View File

@ -33,8 +33,12 @@ public class FileUtil {
* List all the files in a directory that match a regular expression
*
* @param recurse recurse to subdirectories?
* @throws IllegalArgumentException if dir is null
*/
public static Collection<File> listFiles(String dir, String regex, boolean recurse) {
if (dir == null) {
throw new IllegalArgumentException("dir is null");
}
File d = new File(dir);
Pattern p = null;
if (regex != null) {

View File

@ -58,9 +58,13 @@ public class StringTable extends Table<String> implements Cloneable {
* read from a direct (native) text file
* @throws IOException
* @throws FileNotFoundException
* @throws IllegalArgumentException if fileName is null
*
*/
public static StringTable readFromDirectTextFile(String fileName) throws FileNotFoundException, IOException{
if (fileName == null) {
throw new IllegalArgumentException("fileName is null");
}
File f = new File(fileName);
return readFromTextFile(f);
}
@ -109,8 +113,12 @@ public class StringTable extends Table<String> implements Cloneable {
* @param s
* a stream containing a table in text format, whitespace delimited
* @throws IOException
* @throws IllegalArgumentException if s is null
*/
public static StringTable readFromStream(InputStream s) throws IOException {
if (s == null) {
throw new IllegalArgumentException("s is null");
}
StringTable result = new StringTable();
LineNumberReader reader = new LineNumberReader(new InputStreamReader(s));

View File

@ -35,7 +35,7 @@ public class ResolutionFailure extends MethodWarning {
this.ref = ref;
}
public ResolutionFailure(CGNode node, Object ref) {
private ResolutionFailure(CGNode node, Object ref) {
this(node, ref, null);
}
@ -54,7 +54,7 @@ public class ResolutionFailure extends MethodWarning {
if (node == null) {
throw new IllegalArgumentException("node cannot be null");
}
return new ResolutionFailure(node, ref);
return make(node, ref);
}
public static ResolutionFailure create(CGNode node, Object ref, String msg) throws IllegalArgumentException {
@ -64,6 +64,13 @@ public class ResolutionFailure extends MethodWarning {
return new ResolutionFailure(node, ref, msg);
}
public static ResolutionFailure make(CGNode node, Object ref) {
if (node == null) {
throw new IllegalArgumentException("node is null");
}
return new ResolutionFailure(node, ref);
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/