more IllegalArgumentExceptions

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@1148 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2007-05-17 20:27:28 +00:00
parent 57477189ea
commit b5e513cf3e
16 changed files with 75 additions and 11 deletions

View File

@ -21,10 +21,15 @@ public class InstanceFieldKey extends AbstractFieldPointerKey {
private final IField field;
public InstanceFieldKey(InstanceKey instance, IField field) {
super(instance);
if (field == null) {
throw new IllegalArgumentException("field is null");
}
if (instance == null) {
throw new IllegalArgumentException("instance is null");
}
this.field = field;
assert instance != null;
assert field != null;
}
public boolean equals(Object obj) {

View File

@ -65,7 +65,9 @@ public class CFAPointerKeys implements PointerKeyFactory {
}
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField field) {
assert field != null;
if (field == null) {
throw new IllegalArgumentException("field is null");
}
return new InstanceFieldKey(I, field);
}

View File

@ -1177,10 +1177,16 @@ public class ClassHierarchy implements Iterable<IClass> {
* Does an expression c1 x := c2 y typecheck?
*
* i.e. is c2 a subtype of c1?
* @throws IllegalArgumentException if c1 is null
* @throws IllegalArgumentException if c2 is null
*/
public boolean isAssignableFrom(IClass c1, IClass c2) {
assert c1 != null;
assert c2 != null;
if (c2 == null) {
throw new IllegalArgumentException("c2 is null");
}
if (c1 == null) {
throw new IllegalArgumentException("c1 is null");
}
if (c1.isInterface()) {
if (c2.isInterface()) {
return isSubclassOf(c2, c1);

View File

@ -67,7 +67,9 @@ public class DelegatingExtendedHeapModel implements ExtendedHeapModel {
}
public PointerKey getPointerKeyForArrayContents(InstanceKey I) {
assert I != null;
if (I == null) {
throw new IllegalArgumentException("I is null");
}
return h.getPointerKeyForArrayContents(I);
}
@ -76,7 +78,9 @@ public class DelegatingExtendedHeapModel implements ExtendedHeapModel {
}
public PointerKey getPointerKeyForInstanceField(InstanceKey I, IField field) {
assert field != null;
if (field == null) {
throw new IllegalArgumentException("field is null");
}
return h.getPointerKeyForInstanceField(I, field);
}

View File

@ -19,8 +19,11 @@ public abstract class HeapStatement extends Statement {
private final PointerKey loc;
public HeapStatement(CGNode node, PointerKey loc) {
super(node);
assert loc != null;
if (loc == null) {
throw new IllegalArgumentException("loc is null");
}
this.loc = loc;
}

View File

@ -27,7 +27,7 @@ public class HashCodeComparator<T> implements Comparator<T> {
*
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(T o1, T o2) {
public int compare(T o1, T o2) throws NullPointerException {
return o1.hashCode() - o2.hashCode();
}

View File

@ -27,8 +27,12 @@ public class MapUtil {
* a mapping from Object -> Set
* @param key
* @return the Set corresponding to key in M; create one if needed
* @throws IllegalArgumentException if M is null
*/
public static <K, T> Set<T> findOrCreateSet(Map<K, Set<T>> M, K key) {
if (M == null) {
throw new IllegalArgumentException("M is null");
}
Set<T> result = M.get(key);
if (result == null) {
result = HashSetFactory.make(2);
@ -42,8 +46,12 @@ public class MapUtil {
* a mapping from Object -> Map
* @param key
* @return the Map corresponding to key in M; create one if needed
* @throws IllegalArgumentException if M is null
*/
public static <K, K2, V> Map<K2, V> findOrCreateMap(Map<K, Map<K2, V>> M, K key) {
if (M == null) {
throw new IllegalArgumentException("M is null");
}
Map<K2, V> result = M.get(key);
if (result == null) {
result = HashMapFactory.make(2);

View File

@ -59,7 +59,7 @@ public class ParanoidHashMap<K,V> extends HashMap<K,V> {
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
*/
public V put(K arg0, V arg1) {
if (arg0.hashCode() == System.identityHashCode(arg0)) {
if (arg0 != null && arg0.hashCode() == System.identityHashCode(arg0)) {
Assertions._assert(false, arg0.getClass().toString());
}
return super.put(arg0, arg1);

View File

@ -78,6 +78,9 @@ public class ParanoidHashSet<T> extends HashSet<T> {
* @see java.util.Collection#add(java.lang.Object)
*/
public boolean add(T arg0) {
if (arg0 == null) {
throw new IllegalArgumentException("arg0 is null");
}
if (arg0.hashCode() == System.identityHashCode(arg0)) {
Assertions._assert(false, arg0.getClass().toString());
}

View File

@ -27,7 +27,7 @@ public class ToStringComparator<T> implements Comparator<T> {
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
public int compare(T o1, T o2) {
public int compare(T o1, T o2) throws NullPointerException {
return o1.toString().compareTo(o2.toString());
}

View File

@ -63,9 +63,13 @@ public class Dominators<T> {
* The graph
* @param root
* The root from which to compute dominators
* @throws IllegalArgumentException if G is null
*/
@SuppressWarnings("unchecked")
public Dominators(Graph<T> G, T root) throws IllegalArgumentException {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
this.G = G;
this.root = root;
if (G.getNumberOfNodes() == 0) {

View File

@ -43,6 +43,9 @@ public class DelegatingNumberedNodeManager<T extends INodeWithNumber> implements
* @see com.ibm.wala.util.graph.NumberedGraph#getNumber(com.ibm.wala.util.graph.Node)
*/
public int getNumber(T N) {
if (N == null) {
throw new IllegalArgumentException("N is null");
}
INodeWithNumber n = (INodeWithNumber) N;
return n.getGraphNodeId();
}
@ -124,8 +127,12 @@ public class DelegatingNumberedNodeManager<T extends INodeWithNumber> implements
* graph. Use with extreme care.
*
* @see com.ibm.wala.util.graph.NodeManager#addNode(java.lang.Object)
* @throws IllegalArgumentException if n is null
*/
public void addNode(T n) {
if (n == null) {
throw new IllegalArgumentException("n is null");
}
INodeWithNumber N = (INodeWithNumber) n;
int number = N.getGraphNodeId();
if (number == -1) {
@ -165,6 +172,9 @@ public class DelegatingNumberedNodeManager<T extends INodeWithNumber> implements
* @see com.ibm.wala.util.graph.NodeManager#remove(com.ibm.wala.util.graph.Node)
*/
public void removeNode(T n) {
if (n == null) {
throw new IllegalArgumentException("n is null");
}
INodeWithNumber N = (INodeWithNumber) n;
int number = N.getGraphNodeId();
if (nodes[number] != null) {
@ -196,6 +206,9 @@ public class DelegatingNumberedNodeManager<T extends INodeWithNumber> implements
* @see com.ibm.wala.util.graph.NodeManager#containsNode(com.ibm.wala.util.graph.Node)
*/
public boolean containsNode(T n) {
if (n == null) {
throw new IllegalArgumentException("n is null");
}
INodeWithNumber N = (INodeWithNumber) n;
int number = N.getGraphNodeId();
if (number == -1) {

View File

@ -75,8 +75,12 @@ public class BFSPathFinder<T> {
*
* @param G
* the graph whose nodes to enumerate
* @throws IllegalArgumentException if G is null
*/
public BFSPathFinder(Graph<T> G, T src, final T target) throws IllegalArgumentException {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
this.G = G;
this.roots = new NonNullSingletonIterator<T>(src);
if (!G.containsNode(src)) {

View File

@ -62,8 +62,12 @@ public class DFSPathFinder<T> extends Stack<T> {
* in a directed graph.
*
* @param G the graph whose nodes to enumerate
* @throws IllegalArgumentException if G is null
*/
public DFSPathFinder(Graph<T> G, T N, Filter f) throws IllegalArgumentException {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
if (!G.containsNode(N)) {
throw new IllegalArgumentException("source node not in graph: " + N);
}

View File

@ -43,9 +43,13 @@ public class NumberedDFSDiscoverTimeIterator<T> extends GraphDFSDiscoverTimeIter
* in a directed graph.
*
* @param G the graph whose nodes to enumerate
* @throws IllegalArgumentException if G is null
*/
@SuppressWarnings("unchecked")
public NumberedDFSDiscoverTimeIterator(NumberedGraph<T> G, T N) {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
this.G = G;
pendingChildren = new Iterator[G.getMaxNumber() + 1];
init(G, new NonNullSingletonIterator<T>(N));

View File

@ -40,8 +40,12 @@ public class SlowDFSFinishTimeIterator<T> extends DFSFinishTimeIterator<T> {
* in a directed graph.
*
* @param G the graph whose nodes to enumerate
* @throws IllegalArgumentException if G is null
*/
public SlowDFSFinishTimeIterator(Graph<T> G, T N) throws IllegalArgumentException {
if (G == null) {
throw new IllegalArgumentException("G is null");
}
if (!G.containsNode(N)) {
throw new IllegalArgumentException("source node not in graph: " + N);
}