From c2a17a5fbcfed99f53ef815d8abfdaefe9ca961b Mon Sep 17 00:00:00 2001 From: sjfink Date: Mon, 20 Aug 2007 13:38:41 +0000 Subject: [PATCH] IllegalArgumentExceptions and minor cleanups git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1632 f5eafffb-2e1d-0410-98e4-8ec43c5233c4 --- .../com/ibm/wala/classLoader/CodeScanner.java | 11 +- .../demandpa/flowgraph/DemandFlowGraph.java | 14 +- .../demandpa/flowgraph/GetFieldLabel.java | 5 +- .../demandpa/flowgraph/MatchBarLabel.java | 9 +- .../wala/demandpa/flowgraph/MatchLabel.java | 5 +- .../wala/demandpa/flowgraph/NewBarLabel.java | 9 +- .../ibm/wala/demandpa/flowgraph/NewLabel.java | 5 +- .../wala/demandpa/flowgraph/ParamLabel.java | 5 +- .../demandpa/flowgraph/PutFieldBarLabel.java | 9 +- .../demandpa/flowgraph/PutFieldLabel.java | 5 +- .../demandpa/flowgraph/ReturnBarLabel.java | 9 +- .../wala/demandpa/genericutil/ArraySet.java | 5 +- .../demandpa/genericutil/ImmutableStack.java | 11 +- .../ibm/wala/demandpa/genericutil/Util.java | 139 ++++++++++-------- .../wala/demandpa/util/CallGraphMapUtil.java | 9 +- .../util/PointerParamValueNumIterator.java | 5 +- .../com/ibm/wala/eclipse/util/JdtUtil.java | 13 +- .../com/ibm/wala/ipa/callgraph/impl/Util.java | 54 ++++--- .../PropagationCallGraphBuilder.java | 5 +- .../ibm/wala/ipa/cfg/InterproceduralCFG.java | 6 +- .../com/ibm/wala/ipa/cha/ClassHierarchy.java | 5 +- .../ibm/wala/ipa/slicer/thin/CISlicer.java | 5 +- .../src/com/ibm/wala/logic/BinaryFormula.java | 5 +- .../wala/logic/BooleanConstantFormula.java | 5 +- .../src/com/ibm/wala/logic/CNFFormula.java | 5 +- .../com/ibm/wala/logic/DefaultDecorator.java | 30 +++- .../src/com/ibm/wala/logic/NotFormula.java | 10 +- .../com/ibm/wala/logic/RelationFormula.java | 5 +- .../src/com/ibm/wala/logic/Simplifier.java | 23 ++- .../src/com/ibm/wala/ssa/SSACFG.java | 10 +- .../analysis/ExplodedControlFlowGraph.java | 5 +- .../src/com/ibm/wala/util/IntMapIterator.java | 2 +- .../src/com/ibm/wala/util/StringStuff.java | 3 - .../collections/FifoQueueNoDuplicates.java | 6 +- .../wala/util/collections/IteratorUtil.java | 7 +- .../com/ibm/wala/util/debug/Assertions.java | 26 ++-- .../ibm/wala/util/intset/SparseLongSet.java | 5 +- .../src/com/ibm/wala/util/io/CommandLine.java | 7 +- .../src/com/ibm/wala/util/tables/Table.java | 6 +- 39 files changed, 328 insertions(+), 175 deletions(-) diff --git a/com.ibm.wala.core/src/com/ibm/wala/classLoader/CodeScanner.java b/com.ibm.wala.core/src/com/ibm/wala/classLoader/CodeScanner.java index 00e2756c6..57153835d 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/classLoader/CodeScanner.java +++ b/com.ibm.wala.core/src/com/ibm/wala/classLoader/CodeScanner.java @@ -222,8 +222,12 @@ public class CodeScanner { /** * @return Set + * @throws IllegalArgumentException if statements == null */ - public static Set getCaughtExceptions(SSAInstruction[] statements) { + public static Set getCaughtExceptions(SSAInstruction[] statements) throws IllegalArgumentException { + if (statements == null) { + throw new IllegalArgumentException("statements == null"); + } final HashSet result = HashSetFactory.make(10); Visitor v = new Visitor() { @Override @@ -377,8 +381,11 @@ public class CodeScanner { return false; } - public static boolean hasObjectArrayStore(SSAInstruction[] statements) { + public static boolean hasObjectArrayStore(SSAInstruction[] statements) throws IllegalArgumentException { + if (statements == null) { + throw new IllegalArgumentException("statements == null"); + } class ScanVisitor extends Visitor { boolean foundOne = false; diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/DemandFlowGraph.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/DemandFlowGraph.java index 24221b0b1..74db2be0c 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/DemandFlowGraph.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/DemandFlowGraph.java @@ -149,8 +149,12 @@ public abstract class DemandFlowGraph extends FlowLabelGraph { * add representation of flow for a node, if not already present * * @param node + * @throws IllegalArgumentException if node == null */ - public void addSubgraphForNode(CGNode node) { + public void addSubgraphForNode(CGNode node) throws IllegalArgumentException { + if (node == null) { + throw new IllegalArgumentException("node == null"); + } if (node.getIR() == null) { throw new IllegalArgumentException("no ir for node " + node); } @@ -360,13 +364,15 @@ public abstract class DemandFlowGraph extends FlowLabelGraph { } /** - * - * * @param sfk * the static field * @return all the variables that get the value of sfk + * @throws IllegalArgumentException if sfk == null */ - public Iterator getReadsOfStaticField(StaticFieldKey sfk) { + public Iterator getReadsOfStaticField(StaticFieldKey sfk) throws IllegalArgumentException { + if (sfk == null) { + throw new IllegalArgumentException("sfk == null"); + } Collection fieldReads = mam.getFieldReads(sfk.getField()); for (MemoryAccess a : fieldReads) { addSubgraphForNode(a.getNode()); diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/GetFieldLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/GetFieldLabel.java index 2e672b5e5..c75290c60 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/GetFieldLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/GetFieldLabel.java @@ -81,7 +81,10 @@ public class GetFieldLabel implements IFlowLabel { return true; } - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitGetField(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchBarLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchBarLabel.java index fd443dac1..748bee049 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchBarLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchBarLabel.java @@ -53,8 +53,6 @@ public class MatchBarLabel implements IFlowLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#bar() */ public MatchLabel bar() { @@ -62,12 +60,13 @@ public class MatchBarLabel implements IFlowLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#visit(demandGraph.IFlowLabel.IFlowLabelVisitor, * java.lang.Object) */ - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitMatchBar(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchLabel.java index 6741b2261..9ae6bccad 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/MatchLabel.java @@ -48,7 +48,10 @@ public class MatchLabel implements IFlowLabel { return theInstance; } - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitMatch(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewBarLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewBarLabel.java index a09f6dfc4..617a1060c 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewBarLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewBarLabel.java @@ -53,8 +53,6 @@ public class NewBarLabel implements IFlowLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#bar() */ public NewLabel bar() { @@ -62,12 +60,13 @@ public class NewBarLabel implements IFlowLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#visit(demandGraph.IFlowLabel.IFlowLabelVisitor, * java.lang.Object) */ - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitNewBar(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewLabel.java index 9423c1741..12e79abba 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/NewLabel.java @@ -48,7 +48,10 @@ public class NewLabel implements IFlowLabel { return theInstance; } - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitNew(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ParamLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ParamLabel.java index 1c3dadef2..5040c42fc 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ParamLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ParamLabel.java @@ -49,7 +49,10 @@ public class ParamLabel extends CallLabel { return new ParamLabel(callSite); } - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitParam(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldBarLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldBarLabel.java index ae26dc7b0..15d12e9a8 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldBarLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldBarLabel.java @@ -86,8 +86,6 @@ public class PutFieldBarLabel implements IFlowLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#bar() */ public PutFieldLabel bar() { @@ -95,12 +93,13 @@ public class PutFieldBarLabel implements IFlowLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#visit(demandGraph.IFlowLabel.IFlowLabelVisitor, * java.lang.Object) */ - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitPutFieldBar(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldLabel.java index eb60c9778..b6c1e18cb 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/PutFieldLabel.java @@ -81,7 +81,10 @@ public class PutFieldLabel implements IFlowLabel { return true; } - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitPutField(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ReturnBarLabel.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ReturnBarLabel.java index 1a86e9dd5..6a39f04fb 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ReturnBarLabel.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/flowgraph/ReturnBarLabel.java @@ -54,8 +54,6 @@ public class ReturnBarLabel extends CallLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#bar() */ public ReturnLabel bar() { @@ -63,12 +61,13 @@ public class ReturnBarLabel extends CallLabel { } /* - * (non-Javadoc) - * * @see demandGraph.IFlowLabel#visit(demandGraph.IFlowLabel.IFlowLabelVisitor, * java.lang.Object) */ - public void visit(IFlowLabelVisitor v, Object dst) { + public void visit(IFlowLabelVisitor v, Object dst) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } v.visitReturnBar(this, dst); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ArraySet.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ArraySet.java index c2beddd5e..d28ffac0e 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ArraySet.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ArraySet.java @@ -117,7 +117,10 @@ public class ArraySet extends AbstractSet { return true; } - public boolean addAll(ArraySet other) { + public boolean addAll(ArraySet other) throws IllegalArgumentException { + if (other == null) { + throw new IllegalArgumentException("other == null"); + } boolean ret = false; for (int i = 0; i < other.size(); i++) { boolean added = add(other.get(i)); diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ImmutableStack.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ImmutableStack.java index adcb3e513..829b4c1b5 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ImmutableStack.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/ImmutableStack.java @@ -157,14 +157,17 @@ public class ImmutableStack { } /** - * - * @param other * @return true iff other.size() = k, k <= this.size(), and the * top k elements of this equal other + * @throws IllegalArgumentException if other == null */ - public boolean topMatches(ImmutableStack other) { - if (other.size() > size()) + public boolean topMatches(ImmutableStack other) throws IllegalArgumentException { + if (other == null) { + throw new IllegalArgumentException("other == null"); + } + if (other.size() > size()) { return false; + } for (int i = other.size() - 1, j = this.size() - 1; i >= 0; i--, j--) { if (!other.get(i).equals(get(j))) return false; diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/Util.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/Util.java index 0c7aafec8..462bc5b90 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/Util.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/genericutil/Util.java @@ -80,7 +80,7 @@ public class Util { * Factorial on doubles; avoids overflow problems present when using integers. * * @param n_ - * arg on which to compute factorial + * arg on which to compute factorial * @return (double approximation to) factorial of largest * positive integer <= (n_ + epsilon) */ @@ -179,10 +179,10 @@ public class Util { * * @return The first element satisfying the predicate; otherwise null. */ - public static T find(Collection c_, Predicate p_) { - for (Iterator iter = c_.iterator(); iter.hasNext();) { + public static T find(Collection c, Predicate p) { + for (Iterator iter = c.iterator(); iter.hasNext();) { T obj = iter.next(); - if (p_.test(obj)) + if (p.test(obj)) return obj; } @@ -195,12 +195,12 @@ public class Util { * * @return All the elements satisfying the predicate */ - public static Collection findAll(Collection c_, Predicate p_) { + public static Collection findAll(Collection c, Predicate p) { Collection result = new LinkedList(); - for (Iterator iter = c_.iterator(); iter.hasNext();) { + for (Iterator iter = c.iterator(); iter.hasNext();) { T obj = iter.next(); - if (p_.test(obj)) + if (p.test(obj)) result.add(obj); } @@ -211,9 +211,9 @@ public class Util { * Test whether all elements of the given {@link Collection} * satisfy the given {@link Predicate}. */ - public static boolean forAll(Collection c_, Predicate p_) { - for (T t : c_) { - if (!p_.test(t)) + public static boolean forAll(Collection c, Predicate p) { + for (T t : c) { + if (!p.test(t)) return false; } return true; @@ -222,14 +222,14 @@ public class Util { /** * Perform an action for all elements in a collection. * - * @param c_ - * the collection - * @param v_ - * the visitor defining the action + * @param c + * the collection + * @param v + * the visitor defining the action */ - public static void doForAll(Collection c_, ObjectVisitor v_) { - for (Iterator iter = c_.iterator(); iter.hasNext();) - v_.visit(iter.next()); + public static void doForAll(Collection c, ObjectVisitor v) { + for (Iterator iter = c.iterator(); iter.hasNext();) + v.visit(iter.next()); } /** @@ -238,11 +238,18 @@ public class Util { * {@link java.lang.reflect reflection} to create a list of the same type as * 'srcList', but reflection works really slowly in some implementations, so * it's best to avoid it. + * + * @throws IllegalArgumentException + * if srcList == null */ - public static List map(List srcList, Mapper mapper_) { + public static List map(List srcList, Mapper mapper) throws IllegalArgumentException { + if (srcList == null) { + throw new IllegalArgumentException("srcList == null"); + } ArrayList result = new ArrayList(); - for (Iterator srcIter = srcList.iterator(); srcIter.hasNext();) - result.add(mapper_.map(srcIter.next())); + for (Iterator srcIter = srcList.iterator(); srcIter.hasNext();) { + result.add(mapper.map(srcIter.next())); + } return result; } @@ -254,11 +261,11 @@ public class Util { * 'srcList', but reflection works really slowly in some implementations, so * it's best to avoid it. */ - public static List filter(Collection src_, Predicate pred_) { + public static List filter(Collection src, Predicate pred) { ArrayList result = new ArrayList(); - for (Iterator srcIter = src_.iterator(); srcIter.hasNext();) { + for (Iterator srcIter = src.iterator(); srcIter.hasNext();) { T curElem = srcIter.next(); - if (pred_.test(curElem)) + if (pred.test(curElem)) result.add(curElem); } return result; @@ -268,17 +275,17 @@ public class Util { * Filter a collection according to some predicate, placing the result in a * List * - * @param src_ - * collection to be filtered - * @param pred_ - * the predicate - * @param result_ - * the list for the result. assumed to be empty + * @param src + * collection to be filtered + * @param pred + * the predicate + * @param result + * the list for the result. assumed to be empty */ - public static void filter(Collection src_, Predicate pred_, List result_) { - for (T t : src_) { - if (pred_.test(t)) { - result_.add(t); + public static void filter(Collection src, Predicate pred, List result) { + for (T t : src) { + if (pred.test(t)) { + result.add(t); } } } @@ -290,10 +297,10 @@ public class Util { * 'srcSet', but reflection works really slowly in some implementations, so * it's best to avoid it. */ - public static Set mapToSet(Collection srcSet, Mapper mapper_) { + public static Set mapToSet(Collection srcSet, Mapper mapper) { HashSet result = new HashSet(); for (Iterator srcIter = srcSet.iterator(); srcIter.hasNext();) - result.add(mapper_.map(srcIter.next())); + result.add(mapper.map(srcIter.next())); return result; } @@ -301,42 +308,46 @@ public class Util { * Grow an int[] -- i.e. allocate a new array of the given size, with the * initial segment equal to this int[]. */ - public static int[] realloc(int[] data_, int newSize_) { - if (data_.length < newSize_) { - int[] newData = new int[newSize_]; - System.arraycopy(data_, 0, newData, 0, data_.length); + public static int[] realloc(int[] data, int newSize) { + if (data.length < newSize) { + int[] newData = new int[newSize]; + System.arraycopy(data, 0, newData, 0, data.length); return newData; } else - return data_; + return data; } /** Clear a {@link BitSet}. */ - public static void clear(BitSet bitSet_) { - bitSet_.and(EMPTY_BITSET); + public static void clear(BitSet bitSet) { + bitSet.and(EMPTY_BITSET); } /** Replace all occurrences of a given substring in a given {@link String}. */ - public static String replaceAll(String str_, String sub_, String newSub_) { - if (str_.indexOf(sub_) == -1) - return str_; - int subLen = sub_.length(); + public static String replaceAll(String str, String sub, String newSub) { + if (str.indexOf(sub) == -1) + return str; + int subLen = sub.length(); int idx; - StringBuffer result = new StringBuffer(str_); - while ((idx = result.toString().indexOf(sub_)) >= 0) - result.replace(idx, idx + subLen, newSub_); + StringBuffer result = new StringBuffer(str); + while ((idx = result.toString().indexOf(sub)) >= 0) + result.replace(idx, idx + subLen, newSub); return result.toString(); } /** Remove all occurrences of a given substring in a given {@link String} */ - public static String removeAll(String str_, String sub_) { - return replaceAll(str_, sub_, ""); + public static String removeAll(String str, String sub) { + return replaceAll(str, sub, ""); } /** Generate strings with fully qualified names or not */ public static final boolean FULLY_QUALIFIED_NAMES = false; - /** Write object fields to string - * @throws IllegalArgumentException if obj == null*/ + /** + * Write object fields to string + * + * @throws IllegalArgumentException + * if obj == null + */ public static String objectFieldsToString(Object obj) throws IllegalArgumentException { if (obj == null) { throw new IllegalArgumentException("obj == null"); @@ -402,8 +413,13 @@ public class Util { /** * @return a hash code for the array + * @throws IllegalArgumentException + * if objs == null */ - public static int hashArray(Object[] objs) { + public static int hashArray(Object[] objs) throws IllegalArgumentException { + if (objs == null) { + throw new IllegalArgumentException("objs == null"); + } // stolen from java.util.AbstractList int ret = 1; for (int i = 0; i < objs.length; i++) { @@ -469,8 +485,11 @@ public class Util { vals.add(val); } } - - public static List pickNAtRandom(List vals, int n, long seed) { + + public static List pickNAtRandom(List vals, int n, long seed) throws IllegalArgumentException { + if (vals == null) { + throw new IllegalArgumentException("vals == null"); + } if (vals.size() <= n) { return vals; } @@ -479,11 +498,11 @@ public class Util { for (int i = 0; i < n; i++) { boolean added = true; do { - int randIndex = rand.nextInt(n); - added = elems.add(vals.get(randIndex)); + int randIndex = rand.nextInt(n); + added = elems.add(vals.get(randIndex)); } while (!added); - + } - return new ArrayList(elems); + return new ArrayList(elems); } } // class Util diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/CallGraphMapUtil.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/CallGraphMapUtil.java index abf26a306..dd63c849b 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/CallGraphMapUtil.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/CallGraphMapUtil.java @@ -72,13 +72,14 @@ public class CallGraphMapUtil { * the method, i.e., the only context for the method should be * Everywhere.EVERYWHERE. * - * @param orig - * @param fromCG - * @param toCG * @return the corresponding node, or null if the method is not * in the target call graph + * @throws IllegalArgumentException if fromCG == null */ - public static CGNode mapCGNode(CGNode orig, CallGraph fromCG, CallGraph toCG) { + public static CGNode mapCGNode(CGNode orig, CallGraph fromCG, CallGraph toCG) throws IllegalArgumentException { + if (fromCG == null) { + throw new IllegalArgumentException("fromCG == null"); + } if (orig == fromCG.getFakeRootNode()) { return toCG.getFakeRootNode(); } else { diff --git a/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/PointerParamValueNumIterator.java b/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/PointerParamValueNumIterator.java index 625b53610..b074dc198 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/PointerParamValueNumIterator.java +++ b/com.ibm.wala.core/src/com/ibm/wala/demandpa/util/PointerParamValueNumIterator.java @@ -64,7 +64,10 @@ public class PointerParamValueNumIterator implements Iterator { int nextParameter; - public PointerParamValueNumIterator(CGNode node) { + public PointerParamValueNumIterator(CGNode node) throws IllegalArgumentException { + if (node == null) { + throw new IllegalArgumentException("node == null"); + } IR ir = node.getIR(); ti = new TypeInference(ir); symbolTable = ir.getSymbolTable(); diff --git a/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/JdtUtil.java b/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/JdtUtil.java index 9e438544c..b227e0488 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/JdtUtil.java +++ b/com.ibm.wala.core/src/com/ibm/wala/eclipse/util/JdtUtil.java @@ -213,9 +213,12 @@ public class JdtUtil { * TODO: this is too slow. find a better way. * * @return null if not found + * @throws IllegalArgumentException if projects == null */ - public static IType findJavaClassInProjects(String className, Collection projects) { - + public static IType findJavaClassInProjects(String className, Collection projects) throws IllegalArgumentException { + if (projects == null) { + throw new IllegalArgumentException("projects == null"); + } IJavaElement[] arr = new IJavaElement[projects.size()]; projects.toArray(arr); IJavaSearchScope scope = SearchEngine.createJavaSearchScope(arr, false); @@ -224,7 +227,6 @@ public class JdtUtil { } public static IType findJavaClassInResources(String className, Collection resources) { - Collection projects = HashSetFactory.make(); for (IResource r : resources) { projects.add(JavaCore.create(r).getJavaProject()); @@ -324,7 +326,10 @@ public class JdtUtil { } } - public static Collection getTypeParameterNames(IType type) throws JavaModelException { + public static Collection getTypeParameterNames(IType type) throws IllegalArgumentException, JavaModelException { + if (type == null) { + throw new IllegalArgumentException("type == null"); + } ITypeParameter[] tp = type.getTypeParameters(); Collection typeParameterNames = HashSetFactory.make(tp.length); for (ITypeParameter p : tp) { diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/Util.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/Util.java index d4c528baf..a8e1bf01f 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/Util.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/impl/Util.java @@ -289,10 +289,15 @@ public class Util { } /** - * @return Entryponts for a set of J2SE Main classes + * @return Entrypoints for a set of J2SE Main classes + * @throws IllegalArgumentException + * if classNames == null */ public static Iterable makeMainEntrypoints(final ClassLoaderReference loaderRef, final IClassHierarchy cha, - final String[] classNames) { + final String[] classNames) throws IllegalArgumentException { + if (classNames == null) { + throw new IllegalArgumentException("classNames == null"); + } for (int i = 0; i < classNames.length; i++) { if (classNames[i].indexOf("L") != 0) { Assertions.productionAssertion(false, "Expected class name to start with L " + classNames[i]); @@ -554,7 +559,8 @@ public class Util { * @param scope * representation of the analysis scope */ - public static CallGraphBuilder makeRTABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope) { + public static CallGraphBuilder makeRTABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope) { addDefaultSelectors(options, cha); addDefaultBypassLogic(options, scope, Util.class.getClassLoader(), cha); @@ -590,8 +596,8 @@ public class Util { * @throws IllegalArgumentException * if options is null */ - public static CFABuilder makeZeroCFABuilder(AnalysisOptions options,AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope, - ContextSelector customSelector, SSAContextInterpreter customInterpreter) { + public static CFABuilder makeZeroCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope, ContextSelector customSelector, SSAContextInterpreter customInterpreter) { if (options == null) { throw new IllegalArgumentException("options is null"); @@ -599,7 +605,8 @@ public class Util { addDefaultSelectors(options, cha); addDefaultBypassLogic(options, scope, Util.class.getClassLoader(), cha); - return new ZeroXCFABuilder(cha, options, cache, customSelector, customInterpreter, options.getReflectionSpec(), ZeroXInstanceKeys.NONE); + return new ZeroXCFABuilder(cha, options, cache, customSelector, customInterpreter, options.getReflectionSpec(), + ZeroXInstanceKeys.NONE); } /** @@ -615,7 +622,8 @@ public class Util { * @throws IllegalArgumentException * if options is null */ - public static CallGraphBuilder makeOneCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, ClassLoader cl, AnalysisScope scope) { + public static CallGraphBuilder makeOneCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + ClassLoader cl, AnalysisScope scope) { if (options == null) { throw new IllegalArgumentException("options is null"); @@ -625,7 +633,7 @@ public class Util { ContextSelector appSelector = null; SSAContextInterpreter appInterpreter = null; - CallGraphBuilder builder = new OneCFABuilder(cha, options,cache, appSelector, appInterpreter, options.getReflectionSpec()); + CallGraphBuilder builder = new OneCFABuilder(cha, options, cache, appSelector, appInterpreter, options.getReflectionSpec()); return builder; } @@ -642,7 +650,8 @@ public class Util { * @param scope * representation of the analysis scope */ - public static CFABuilder makeZeroOneCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope) { + public static CFABuilder makeZeroOneCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope) { return makeZeroOneCFABuilder(options, cache, cha, scope, null, null); } @@ -661,8 +670,8 @@ public class Util { * @throws IllegalArgumentException * if options is null */ - public static CFABuilder makeVanillaZeroOneCFABuilder(AnalysisOptions options, AnalysisCache cache,IClassHierarchy cha, AnalysisScope scope, - ContextSelector customSelector, SSAContextInterpreter customInterpreter) { + public static CFABuilder makeVanillaZeroOneCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope, ContextSelector customSelector, SSAContextInterpreter customInterpreter) { if (options == null) { throw new IllegalArgumentException("options is null"); @@ -670,7 +679,7 @@ public class Util { addDefaultSelectors(options, cha); addDefaultBypassLogic(options, scope, Util.class.getClassLoader(), cha); - return new ZeroXCFABuilder(cha, options,cache, customSelector, customInterpreter, options.getReflectionSpec(), + return new ZeroXCFABuilder(cha, options, cache, customSelector, customInterpreter, options.getReflectionSpec(), ZeroXInstanceKeys.ALLOCATIONS); } @@ -687,7 +696,8 @@ public class Util { * @param scope * representation of the analysis scope */ - public static CFABuilder makeVanillaZeroOneCFABuilder(AnalysisOptions options,AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope) { + public static CFABuilder makeVanillaZeroOneCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope) { return makeVanillaZeroOneCFABuilder(options, cache, cha, scope, null, null); } @@ -706,8 +716,8 @@ public class Util { * @throws IllegalArgumentException * if options is null */ - public static CFABuilder makeZeroOneCFABuilder(AnalysisOptions options, AnalysisCache cache,IClassHierarchy cha, AnalysisScope scope, - ContextSelector customSelector, SSAContextInterpreter customInterpreter) { + public static CFABuilder makeZeroOneCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope, ContextSelector customSelector, SSAContextInterpreter customInterpreter) { if (options == null) { throw new IllegalArgumentException("options is null"); @@ -732,7 +742,8 @@ public class Util { * @throws IllegalArgumentException * if options is null */ - public static CFABuilder makeZeroContainerCFABuilder(AnalysisOptions options,AnalysisCache cache,IClassHierarchy cha, AnalysisScope scope) { + public static CFABuilder makeZeroContainerCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope) { if (options == null) { throw new IllegalArgumentException("options is null"); @@ -757,7 +768,8 @@ public class Util { * @throws IllegalArgumentException * if options is null */ - public static CFABuilder makeZeroOneContainerCFABuilder(AnalysisOptions options, AnalysisCache cache,IClassHierarchy cha, AnalysisScope scope ) { + public static CFABuilder makeZeroOneContainerCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope) { if (options == null) { throw new IllegalArgumentException("options is null"); @@ -767,7 +779,7 @@ public class Util { ContextSelector appSelector = null; SSAContextInterpreter appInterpreter = null; - return new ZeroOneContainerCFABuilder(cha, options,cache, appSelector, appInterpreter, options.getReflectionSpec()); + return new ZeroOneContainerCFABuilder(cha, options, cache, appSelector, appInterpreter, options.getReflectionSpec()); } /** @@ -782,7 +794,8 @@ public class Util { * @throws IllegalArgumentException * if options is null */ - public static CFABuilder makeVanillaZeroOneContainerCFABuilder(AnalysisOptions options,AnalysisCache cache, IClassHierarchy cha, AnalysisScope scope) { + public static CFABuilder makeVanillaZeroOneContainerCFABuilder(AnalysisOptions options, AnalysisCache cache, IClassHierarchy cha, + AnalysisScope scope) { if (options == null) { throw new IllegalArgumentException("options is null"); @@ -794,8 +807,7 @@ public class Util { return new ZeroOneContainerCFABuilder(cha, options, cache, appSelector, appInterpreter, options.getReflectionSpec()) { @Override - protected ZeroXInstanceKeys makeInstanceKeys(IClassHierarchy c, AnalysisOptions o, - SSAContextInterpreter contextInterpreter) { + protected ZeroXInstanceKeys makeInstanceKeys(IClassHierarchy c, AnalysisOptions o, SSAContextInterpreter contextInterpreter) { ZeroXInstanceKeys zik = new ZeroXInstanceKeys(o, c, contextInterpreter, ZeroXInstanceKeys.ALLOCATIONS); return zik; } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java index fad558444..62ecb5f47 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/callgraph/propagation/PropagationCallGraphBuilder.java @@ -660,7 +660,10 @@ public abstract class PropagationCallGraphBuilder implements CallGraphBuilder { return false; } - public static boolean representsNullType(InstanceKey key) { + public static boolean representsNullType(InstanceKey key) throws IllegalArgumentException { + if (key == null) { + throw new IllegalArgumentException("key == null"); + } IClass cls = key.getConcreteType(); Language L = cls.getClassLoader().getLanguage(); return L.isNullType(cls.getReference()); diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/InterproceduralCFG.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/InterproceduralCFG.java index e96e2ca23..f651487a9 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/InterproceduralCFG.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/cfg/InterproceduralCFG.java @@ -190,8 +190,12 @@ public class InterproceduralCFG implements NumberedGraph { /** * @param n * @return the cfg for n, or null if none found + * @throws IllegalArgumentException if n == null */ - public ControlFlowGraph getCFG(CGNode n) { + public ControlFlowGraph getCFG(CGNode n) throws IllegalArgumentException { + if (n == null) { + throw new IllegalArgumentException("n == null"); + } ControlFlowGraph cfg = n.getCFG(); if (cfg == null) { return null; diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/cha/ClassHierarchy.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/cha/ClassHierarchy.java index 431beb17f..a07e3e255 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/cha/ClassHierarchy.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/cha/ClassHierarchy.java @@ -1152,7 +1152,10 @@ public class ClassHierarchy implements IClassHierarchy { return root.getJavaClass(); } - public boolean isRootClass(IClass c) { + public boolean isRootClass(IClass c) throws IllegalArgumentException { + if (c == null) { + throw new IllegalArgumentException("c == null"); + } return c.equals(root.getJavaClass()); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/thin/CISlicer.java b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/thin/CISlicer.java index a057bbf2f..ee26dd6bd 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/thin/CISlicer.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ipa/slicer/thin/CISlicer.java @@ -59,7 +59,10 @@ public class CISlicer { } public CISlicer(CallGraph cg, PointerAnalysis pa, ModRef modRef, - DataDependenceOptions dOptions, ControlDependenceOptions cOptions) { + DataDependenceOptions dOptions, ControlDependenceOptions cOptions) throws IllegalArgumentException { + if (dOptions == null) { + throw new IllegalArgumentException("dOptions == null"); + } if (dOptions.equals(DataDependenceOptions.NO_BASE_PTRS) || dOptions.equals(DataDependenceOptions.FULL)) { throw new IllegalArgumentException("Heap data dependences requested in CISlicer!"); diff --git a/com.ibm.wala.core/src/com/ibm/wala/logic/BinaryFormula.java b/com.ibm.wala.core/src/com/ibm/wala/logic/BinaryFormula.java index b671dc0a9..0bf200142 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/logic/BinaryFormula.java +++ b/com.ibm.wala.core/src/com/ibm/wala/logic/BinaryFormula.java @@ -65,7 +65,10 @@ public class BinaryFormula extends AbstractBinaryFormula { return new BinaryFormula(connective, f1, f2); } - public static IFormula or(IFormula f1, IFormula f2) { + public static IFormula or(IFormula f1, IFormula f2) throws IllegalArgumentException { + if (f1 == null) { + throw new IllegalArgumentException("f1 == null"); + } if (f1.equals(BooleanConstantFormula.FALSE)) { return f2; } else if (f2.equals(BooleanConstantFormula.FALSE)) { diff --git a/com.ibm.wala.core/src/com/ibm/wala/logic/BooleanConstantFormula.java b/com.ibm.wala.core/src/com/ibm/wala/logic/BooleanConstantFormula.java index ad668528b..00deaf401 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/logic/BooleanConstantFormula.java +++ b/com.ibm.wala.core/src/com/ibm/wala/logic/BooleanConstantFormula.java @@ -47,7 +47,10 @@ public class BooleanConstantFormula implements IMaxTerm { return prettyPrint(DefaultDecorator.instance()); } - public String prettyPrint(ILogicDecorator d) { + public String prettyPrint(ILogicDecorator d) throws IllegalArgumentException { + if (d == null) { + throw new IllegalArgumentException("d == null"); + } return d.prettyPrint(c); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/logic/CNFFormula.java b/com.ibm.wala.core/src/com/ibm/wala/logic/CNFFormula.java index 1237c69d5..a034bb2ac 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/logic/CNFFormula.java +++ b/com.ibm.wala.core/src/com/ibm/wala/logic/CNFFormula.java @@ -64,7 +64,10 @@ public class CNFFormula extends AbstractBinaryFormula implements ICNFFormula { return result; } - public String prettyPrint(ILogicDecorator d) { + public String prettyPrint(ILogicDecorator d) throws IllegalArgumentException { + if (d == null) { + throw new IllegalArgumentException("d == null"); + } return d.prettyPrint(this); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/logic/DefaultDecorator.java b/com.ibm.wala.core/src/com/ibm/wala/logic/DefaultDecorator.java index b5a986448..8ee65ba89 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/logic/DefaultDecorator.java +++ b/com.ibm.wala.core/src/com/ibm/wala/logic/DefaultDecorator.java @@ -38,11 +38,17 @@ public class DefaultDecorator implements ILogicDecorator { return c.toString(); } - public String prettyPrint(AbstractVariable v) { + public String prettyPrint(AbstractVariable v) throws IllegalArgumentException { + if (v == null) { + throw new IllegalArgumentException("v == null"); + } return v.toString(); } - public String prettyPrint(Quantifier q) { + public String prettyPrint(Quantifier q) throws IllegalArgumentException { + if (q == null) { + throw new IllegalArgumentException("q == null"); + } return q.toString(); } @@ -53,7 +59,10 @@ public class DefaultDecorator implements ILogicDecorator { return constant.toString(); } - public String prettyPrint(FunctionTerm term) { + public String prettyPrint(FunctionTerm term) throws IllegalArgumentException { + if (term == null) { + throw new IllegalArgumentException("term == null"); + } StringBuffer result = new StringBuffer(term.getFunction().getSymbol()); result.append("("); for (int i = 0; i < term.getFunction().getNumberOfParameters() - 1; i++) { @@ -67,7 +76,10 @@ public class DefaultDecorator implements ILogicDecorator { return result.toString(); } - public String prettyPrint(RelationFormula r) { + public String prettyPrint(RelationFormula r) throws IllegalArgumentException { + if (r == null) { + throw new IllegalArgumentException("r == null"); + } if (r.getRelation().getValence() == 2) { return infixNotation(r); } else { @@ -100,7 +112,10 @@ public class DefaultDecorator implements ILogicDecorator { return result.toString(); } - public String prettyPrint(IRelation r) { + public String prettyPrint(IRelation r) throws IllegalArgumentException { + if (r == null) { + throw new IllegalArgumentException("r == null"); + } return r.getSymbol(); } @@ -116,7 +131,10 @@ public class DefaultDecorator implements ILogicDecorator { return result.toString(); } - public String prettyPrint(NotFormula n) { + public String prettyPrint(NotFormula n) throws IllegalArgumentException { + if (n == null) { + throw new IllegalArgumentException("n == null"); + } StringBuffer result = new StringBuffer(); result.append("not ( "); result.append(n.getFormula().prettyPrint(this)); diff --git a/com.ibm.wala.core/src/com/ibm/wala/logic/NotFormula.java b/com.ibm.wala.core/src/com/ibm/wala/logic/NotFormula.java index 51e5b0306..46d18cdd0 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/logic/NotFormula.java +++ b/com.ibm.wala.core/src/com/ibm/wala/logic/NotFormula.java @@ -29,7 +29,10 @@ public class NotFormula implements IFormula { } } - public static IFormula make(IFormula f) { + public static IFormula make(IFormula f) throws IllegalArgumentException { + if (f == null) { + throw new IllegalArgumentException("f == null"); + } switch (f.getKind()) { case RELATION: RelationFormula r = (RelationFormula) f; @@ -92,7 +95,10 @@ public class NotFormula implements IFormula { return prettyPrint(DefaultDecorator.instance()); } - public String prettyPrint(ILogicDecorator d) { + public String prettyPrint(ILogicDecorator d) throws IllegalArgumentException { + if (d == null) { + throw new IllegalArgumentException("d == null"); + } return d.prettyPrint(this); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/logic/RelationFormula.java b/com.ibm.wala.core/src/com/ibm/wala/logic/RelationFormula.java index fbe81a84b..676191a97 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/logic/RelationFormula.java +++ b/com.ibm.wala.core/src/com/ibm/wala/logic/RelationFormula.java @@ -153,7 +153,10 @@ public class RelationFormula implements IMaxTerm { return prettyPrint(DefaultDecorator.instance()); } - public String prettyPrint(ILogicDecorator d) { + public String prettyPrint(ILogicDecorator d) throws IllegalArgumentException { + if (d == null) { + throw new IllegalArgumentException("d == null"); + } return d.prettyPrint(this); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/logic/Simplifier.java b/com.ibm.wala.core/src/com/ibm/wala/logic/Simplifier.java index 4dbf7af0e..1c5002c98 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/logic/Simplifier.java +++ b/com.ibm.wala.core/src/com/ibm/wala/logic/Simplifier.java @@ -211,8 +211,12 @@ public class Simplifier { * @param facts * formulae that can be treated as axioms * @return true if we can easily prove f is a contradiction + * @throws IllegalArgumentException if facts == null */ - public static boolean isContradiction(IFormula f, Collection facts) { + public static boolean isContradiction(IFormula f, Collection facts) throws IllegalArgumentException { + if (facts == null) { + throw new IllegalArgumentException("facts == null"); + } for (IMaxTerm d : facts) { if (contradicts(d, f)) { return true; @@ -379,7 +383,10 @@ public class Simplifier { // some ad-hoc formula normalization // 1) change >, >= to <, <= // TODO: do normalization in a principled manner - public static IFormula normalize(IFormula f) { + public static IFormula normalize(IFormula f) throws IllegalArgumentException { + if (f == null) { + throw new IllegalArgumentException("f == null"); + } switch (f.getKind()) { case RELATION: RelationFormula r = (RelationFormula) f; @@ -397,8 +404,12 @@ public class Simplifier { * @param facts * formulae that can be treated as axioms * @return true if we can easily prove f is a tautology + * @throws IllegalArgumentException if facts == null */ - public static boolean isTautology(IFormula f, Collection facts) { + public static boolean isTautology(IFormula f, Collection facts) throws IllegalArgumentException { + if (facts == null) { + throw new IllegalArgumentException("facts == null"); + } for (IMaxTerm d : facts) { if (implies(d, f)) { return true; @@ -717,8 +728,12 @@ public class Simplifier { * Attempt to distribute the NOT from a NotFormula * * @return the original formula if the distribution is unsuccessful + * @throws IllegalArgumentException if f == null */ - public static IFormula distributeNot(NotFormula f) { + public static IFormula distributeNot(NotFormula f) throws IllegalArgumentException { + if (f == null) { + throw new IllegalArgumentException("f == null"); + } IFormula f1 = f.getFormula(); if (f1 instanceof RelationFormula) { RelationFormula r = (RelationFormula) f1; diff --git a/com.ibm.wala.core/src/com/ibm/wala/ssa/SSACFG.java b/com.ibm.wala.core/src/com/ibm/wala/ssa/SSACFG.java index 97a110110..66c849b27 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ssa/SSACFG.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ssa/SSACFG.java @@ -793,7 +793,10 @@ public class SSACFG implements ControlFlowGraph { /* * @see com.ibm.wala.util.graph.Graph#getPredNodeCount(com.ibm.wala.util.graph.Node) */ - public int getPredNodeCount(IBasicBlock b) { + public int getPredNodeCount(IBasicBlock b) throws IllegalArgumentException { + if (b == null) { + throw new IllegalArgumentException("b == null"); + } IBasicBlock n = cfg.getNode(b.getNumber()); return cfg.getPredNodeCount(n); } @@ -827,7 +830,10 @@ public class SSACFG implements ControlFlowGraph { /* * @see com.ibm.wala.util.graph.Graph#getSuccNodeCount(com.ibm.wala.util.graph.Node) */ - public int getSuccNodeCount(IBasicBlock b) { + public int getSuccNodeCount(IBasicBlock b) throws IllegalArgumentException { + if (b == null) { + throw new IllegalArgumentException("b == null"); + } IBasicBlock n = cfg.getNode(b.getNumber()); return cfg.getSuccNodeCount(n); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/ssa/analysis/ExplodedControlFlowGraph.java b/com.ibm.wala.core/src/com/ibm/wala/ssa/analysis/ExplodedControlFlowGraph.java index 4c15bc874..bdf151bf5 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/ssa/analysis/ExplodedControlFlowGraph.java +++ b/com.ibm.wala.core/src/com/ibm/wala/ssa/analysis/ExplodedControlFlowGraph.java @@ -343,7 +343,10 @@ public class ExplodedControlFlowGraph implements ControlFlowGraph { } } - public int getNumber(IBasicBlock n) { + public int getNumber(IBasicBlock n) throws IllegalArgumentException { + if (n == null) { + throw new IllegalArgumentException("n == null"); + } return n.getNumber(); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/IntMapIterator.java b/com.ibm.wala.core/src/com/ibm/wala/util/IntMapIterator.java index 77636c3db..03cdc58d7 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/IntMapIterator.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/IntMapIterator.java @@ -38,7 +38,7 @@ public class IntMapIterator implements Iterator { return i.hasNext(); } - public void remove() { + public void remove() throws UnsupportedOperationException { throw new java.lang.UnsupportedOperationException(); } diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/StringStuff.java b/com.ibm.wala.core/src/com/ibm/wala/util/StringStuff.java index ebed1ae21..9bba94370 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/StringStuff.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/StringStuff.java @@ -288,9 +288,6 @@ public class StringStuff { * Given that name[start:start+length] is a Type name in JVM format, parse it * for the package * - * @param name - * @param start - * @param length * @return an ImmutableByteArray that represents the package, or null if it's * the unnamed package */ diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/collections/FifoQueueNoDuplicates.java b/com.ibm.wala.core/src/com/ibm/wala/util/collections/FifoQueueNoDuplicates.java index d8572606c..df2fc9796 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/collections/FifoQueueNoDuplicates.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/collections/FifoQueueNoDuplicates.java @@ -71,9 +71,13 @@ public class FifoQueueNoDuplicates extends FifoQueue { * @param elements * an Iterator of Objects to be added to the queue if never already * queued. + * @throws IllegalArgumentException if elements == null */ @Override - public void push(Iterator elements) { + public void push(Iterator elements) throws IllegalArgumentException { + if (elements == null) { + throw new IllegalArgumentException("elements == null"); + } while (elements.hasNext()) { T element = elements.next(); if (wasInQueue.add(element)) { diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/collections/IteratorUtil.java b/com.ibm.wala.core/src/com/ibm/wala/util/collections/IteratorUtil.java index 9444903a5..494e8b143 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/collections/IteratorUtil.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/collections/IteratorUtil.java @@ -21,8 +21,6 @@ import java.util.Iterator; public class IteratorUtil { /** - * @param it - * @param o * @return true iff the Iterator returns some elements which equals() the * object o */ @@ -35,7 +33,10 @@ public class IteratorUtil { return false; } - public final static int count(Iterator it) { + public final static int count(Iterator it) throws IllegalArgumentException { + if (it == null) { + throw new IllegalArgumentException("it == null"); + } int count = 0; while (it.hasNext()) { it.next(); diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/debug/Assertions.java b/com.ibm.wala.core/src/com/ibm/wala/util/debug/Assertions.java index 6e6da6dd1..5dc6153f8 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/debug/Assertions.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/debug/Assertions.java @@ -31,10 +31,9 @@ public class Assertions { } /** - * Method _assert. - * @param b + * @throws UnimplementedError if b == false */ - public static void _assert(boolean b) { + public static void _assert(boolean b) throws UnimplementedError { checkGuard(); if (!b) throw new UnimplementedError(); @@ -67,8 +66,9 @@ public class Assertions { * An assertion which does not need to be guarded by verifyAssertions. * These assertions will be enabled in production! * @param b + * @throws UnimplementedError if b == false */ - public static void productionAssertion(boolean b) { + public static void productionAssertion(boolean b) throws UnimplementedError { if (!b) throw new UnimplementedError(); } @@ -97,9 +97,9 @@ public class Assertions { /** * This is only a convenience method, identical to _assert. * Allows the programmer to distinguish preconditions from other assertions. - * @param b + * @throws UnimplementedError if b == false */ - public static void precondition(boolean b) { + public static void precondition(boolean b) throws UnimplementedError { checkGuard(); if (!b) throw new UnimplementedError(); @@ -108,10 +108,9 @@ public class Assertions { /** * This is only a convenience method, identical to _assert. * It allows the programmer to distinguish preconditions from other assertions. - * @param b - * @param string + * @throws UnimplementedError if b == false */ - public static void precondition(boolean b, String string) { + public static void precondition(boolean b, String string) throws UnimplementedError { checkGuard(); if (!b) throw new UnimplementedError(string); @@ -120,9 +119,9 @@ public class Assertions { /** * This is only a convenience method, identical to _assert. * Allows the programmer to distinguish postconditions from other assertions. - * @param b + * @throws UnimplementedError if b == false */ - public static void postcondition(boolean b) { + public static void postcondition(boolean b) throws UnimplementedError { checkGuard(); if (!b) throw new UnimplementedError(); @@ -131,10 +130,9 @@ public class Assertions { /** * This is only a convenience method, identical to _assert. * It allows the programmer to distinguish postconditions from other assertions. - * @param b - * @param string + * @throws UnimplementedError if b == false */ - public static void postcondition(boolean b, String string) { + public static void postcondition(boolean b, String string) throws UnimplementedError { checkGuard(); if (!b) throw new UnimplementedError(string); diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseLongSet.java b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseLongSet.java index a2ce49564..7011b32d1 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseLongSet.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/intset/SparseLongSet.java @@ -424,7 +424,10 @@ public class SparseLongSet implements LongSet { } } - public boolean containsAny(SparseLongSet set) { + public boolean containsAny(SparseLongSet set) throws IllegalArgumentException { + if (set == null) { + throw new IllegalArgumentException("set == null"); + } int i = 0; for (int j = 0; j < set.size; j++) { long x = set.elements[j]; diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/io/CommandLine.java b/com.ibm.wala.core/src/com/ibm/wala/util/io/CommandLine.java index d7f65537e..9a690b569 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/io/CommandLine.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/io/CommandLine.java @@ -27,9 +27,12 @@ public class CommandLine { * line args. if args[i] is "-foo" and args[i+1] is "bar", then the result * will define a property with key "foo" and value "bar" * - * @throws WalaException + * @throws IllegalArgumentException if args == null */ - public static Properties parse(String[] args) throws WalaException { + public static Properties parse(String[] args) throws IllegalArgumentException, WalaException { + if (args == null) { + throw new IllegalArgumentException("args == null"); + } Properties result = new Properties(); for (int i = 0; i < args.length; i++) { String key = parseForKey(args[i]); diff --git a/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java b/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java index e341cbc1c..205460c58 100644 --- a/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java +++ b/com.ibm.wala.core/src/com/ibm/wala/util/tables/Table.java @@ -36,8 +36,12 @@ public class Table implements Cloneable { /** * create an empty table with the same column headings as t + * @throws IllegalArgumentException if t == null */ - public Table(Table t) { + public Table(Table t) throws IllegalArgumentException { + if (t == null) { + throw new IllegalArgumentException("t == null"); + } for (int i = 0; i < t.getNumberOfColumns(); i++) { columnHeadings.set(i, t.getColumnHeading(i)); }