more IllegalArgument checks

propagate IOExceptions when reading AnalysisScopes from files

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3396 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
sjfink 2009-03-31 20:16:52 +00:00
parent b6b5f56ac2
commit 7fdacaef22
14 changed files with 90 additions and 137 deletions

View File

@ -10,6 +10,8 @@
*******************************************************************************/ *******************************************************************************/
package com.ibm.wala.core.tests.cha; package com.ibm.wala.core.tests.cha;
import java.io.IOException;
import com.ibm.wala.classLoader.IClass; import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.core.tests.util.TestConstants; import com.ibm.wala.core.tests.util.TestConstants;
import com.ibm.wala.core.tests.util.WalaTestCase; import com.ibm.wala.core.tests.util.WalaTestCase;
@ -29,7 +31,7 @@ public class SourceMapTest extends WalaTestCase {
private final static String CLASS_IN_PRIMORDIAL_JAR = "Lcom/ibm/wala/model/SyntheticFactory"; private final static String CLASS_IN_PRIMORDIAL_JAR = "Lcom/ibm/wala/model/SyntheticFactory";
public void testHello() throws ClassHierarchyException { public void testHello() throws ClassHierarchyException, IOException {
AnalysisScope scope = null; AnalysisScope scope = null;
scope = AnalysisScopeReader.readJavaScope(TestConstants.HELLO, null, MY_CLASSLOADER); scope = AnalysisScopeReader.readJavaScope(TestConstants.HELLO, null, MY_CLASSLOADER);
// TODO: it's annoying to have to build a class hierarchy here. // TODO: it's annoying to have to build a class hierarchy here.
@ -43,7 +45,7 @@ public class SourceMapTest extends WalaTestCase {
assertTrue(sourceFile != null); assertTrue(sourceFile != null);
} }
public void testFromJar() throws ClassHierarchyException { public void testFromJar() throws ClassHierarchyException, IOException {
AnalysisScope scope = null; AnalysisScope scope = null;
scope = AnalysisScopeReader.readJavaScope(TestConstants.HELLO, null, MY_CLASSLOADER); scope = AnalysisScopeReader.readJavaScope(TestConstants.HELLO, null, MY_CLASSLOADER);
// TODO: it's annoying to have to build a class hierarchy here. // TODO: it's annoying to have to build a class hierarchy here.

View File

@ -118,7 +118,7 @@ public class CompareToZeroOneCFADriver {
} }
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static void runApplication(String appJar) throws IllegalArgumentException, CancelException { private static void runApplication(String appJar) throws IllegalArgumentException, CancelException, IOException {
Trace.println("=======---------------============="); Trace.println("=======---------------=============");
Trace.println("ANALYZING " + appJar + "\n\n"); Trace.println("ANALYZING " + appJar + "\n\n");

View File

@ -40,8 +40,7 @@ import com.ibm.wala.viz.DotUtil;
import com.ibm.wala.viz.GVUtil; import com.ibm.wala.viz.GVUtil;
/** /**
* This simple example WALA application builds a call graph and fires off * This simple example WALA application builds a call graph and fires off ghostview to visualize a DOT representation.
* ghostview to visualize a DOT representation.
* *
* @author sfink * @author sfink
*/ */
@ -50,8 +49,7 @@ public class GVCallGraph {
private final static String PS_FILE = "cg.ps"; private final static String PS_FILE = "cg.ps";
/** /**
* Usage: args = "-appJar [jar file name] {-exclusionFile * Usage: args = "-appJar [jar file name] {-exclusionFile [exclusionFileName]}" The "jar file name" should be something like
* [exclusionFileName]}" The "jar file name" should be something like
* "c:/temp/testdata/java_cup.jar" * "c:/temp/testdata/java_cup.jar"
* *
* @throws CancelException * @throws CancelException
@ -62,8 +60,7 @@ public class GVCallGraph {
} }
/** /**
* Usage: args = "-appJar [jar file name] {-exclusionFile * Usage: args = "-appJar [jar file name] {-exclusionFile [exclusionFileName]}" The "jar file name" should be something like
* [exclusionFileName]}" The "jar file name" should be something like
* "c:/temp/testdata/java_cup.jar" * "c:/temp/testdata/java_cup.jar"
* *
* @throws CancelException * @throws CancelException
@ -76,8 +73,7 @@ public class GVCallGraph {
} }
/** /**
* @param appJar * @param appJar something like "c:/temp/testdata/java_cup.jar"
* something like "c:/temp/testdata/java_cup.jar"
* @throws CancelException * @throws CancelException
* @throws IllegalArgumentException * @throws IllegalArgumentException
*/ */
@ -111,16 +107,16 @@ public class GVCallGraph {
} }
/** /**
* @param appJar * @param appJar something like "c:/temp/testdata/java_cup.jar"
* something like "c:/temp/testdata/java_cup.jar"
* @return a call graph * @return a call graph
* @throws CancelException * @throws CancelException
* @throws IllegalArgumentException * @throws IllegalArgumentException
* @throws IOException
*/ */
public static Graph<CGNode> buildPrunedCallGraph(String appJar, File exclusionFile) throws WalaException, public static Graph<CGNode> buildPrunedCallGraph(String appJar, File exclusionFile) throws WalaException,
IllegalArgumentException, CancelException { IllegalArgumentException, CancelException, IOException {
AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(appJar, exclusionFile != null ? exclusionFile AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope(appJar, exclusionFile != null ? exclusionFile : new File(
: new File(CallGraphTestUtil.REGRESSION_EXCLUSIONS)); CallGraphTestUtil.REGRESSION_EXCLUSIONS));
ClassHierarchy cha = ClassHierarchy.make(scope); ClassHierarchy cha = ClassHierarchy.make(scope);
@ -132,11 +128,11 @@ public class GVCallGraph {
// // // //
com.ibm.wala.ipa.callgraph.CallGraphBuilder builder = Util.makeZeroCFABuilder(options, new AnalysisCache(), cha, scope); com.ibm.wala.ipa.callgraph.CallGraphBuilder builder = Util.makeZeroCFABuilder(options, new AnalysisCache(), cha, scope);
CallGraph cg = builder.makeCallGraph(options, null); CallGraph cg = builder.makeCallGraph(options, null);
System.err.println(CallGraphStats.getStats(cg)); System.err.println(CallGraphStats.getStats(cg));
Graph<CGNode> g = pruneForAppLoader(cg); Graph<CGNode> g = pruneForAppLoader(cg);
return g; return g;
} }
@ -149,11 +145,10 @@ public class GVCallGraph {
* *
* Usage: * Usage:
* <ul> * <ul>
* <li> args[0] : "-appJar" * <li>args[0] : "-appJar"
* <li> args[1] : something like "c:/temp/testdata/java_cup.jar" </ul? * <li> args[1] : something like "c:/temp/testdata/java_cup.jar" </ul?
* *
* @throws UnsupportedOperationException * @throws UnsupportedOperationException if command-line is malformed.
* if command-line is malformed.
*/ */
public static void validateCommandLine(Properties p) { public static void validateCommandLine(Properties p) {
if (p.get("appJar") == null) { if (p.get("appJar") == null) {

View File

@ -107,8 +107,9 @@ public abstract class AbstractJavaAnalysisAction implements IObjectActionDelegat
/** /**
* create an analysis scope as the union of a bunch of EclipseProjectPath * create an analysis scope as the union of a bunch of EclipseProjectPath
* @throws IOException
*/ */
private static AnalysisScope mergeProjectPaths(Collection<EclipseProjectPath> projectPaths) { private static AnalysisScope mergeProjectPaths(Collection<EclipseProjectPath> projectPaths) throws IOException {
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope(); AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
Collection<Module> seen = HashSetFactory.make(); Collection<Module> seen = HashSetFactory.make();
@ -121,7 +122,7 @@ public abstract class AbstractJavaAnalysisAction implements IObjectActionDelegat
} }
private static void buildScope(ClassLoaderReference loader, Collection<EclipseProjectPath> projectPaths, AnalysisScope scope, private static void buildScope(ClassLoaderReference loader, Collection<EclipseProjectPath> projectPaths, AnalysisScope scope,
Collection<Module> seen) { Collection<Module> seen) throws IOException {
for (EclipseProjectPath path : projectPaths) { for (EclipseProjectPath path : projectPaths) {
AnalysisScope pScope = path.toAnalysisScope((File) null); AnalysisScope pScope = path.toAnalysisScope((File) null);
for (Module m : pScope.getModules(loader)) { for (Module m : pScope.getModules(loader)) {

View File

@ -299,8 +299,10 @@ public class EclipseProjectPath {
/** /**
* Convert this path to a WALA analysis scope * Convert this path to a WALA analysis scope
*
* @throws IOException
*/ */
public AnalysisScope toAnalysisScope(ClassLoader classLoader, File exclusionsFile) { public AnalysisScope toAnalysisScope(ClassLoader classLoader, File exclusionsFile) throws IOException {
AnalysisScope scope = AnalysisScopeReader.readJavaScope(AbstractAnalysisEngine.SYNTHETIC_J2SE_MODEL, exclusionsFile, AnalysisScope scope = AnalysisScopeReader.readJavaScope(AbstractAnalysisEngine.SYNTHETIC_J2SE_MODEL, exclusionsFile,
classLoader); classLoader);
return toAnalysisScope(scope); return toAnalysisScope(scope);
@ -338,11 +340,11 @@ public class EclipseProjectPath {
} }
} }
public AnalysisScope toAnalysisScope(final File exclusionsFile) { public AnalysisScope toAnalysisScope(final File exclusionsFile) throws IOException {
return toAnalysisScope(getClass().getClassLoader(), exclusionsFile); return toAnalysisScope(getClass().getClassLoader(), exclusionsFile);
} }
public AnalysisScope toAnalysisScope() { public AnalysisScope toAnalysisScope() throws IOException {
return toAnalysisScope(getClass().getClassLoader(), null); return toAnalysisScope(getClass().getClassLoader(), null);
} }
@ -352,7 +354,12 @@ public class EclipseProjectPath {
@Override @Override
public String toString() { public String toString() {
return toAnalysisScope((File) null).toString(); try {
return toAnalysisScope((File) null).toString();
} catch (IOException e) {
e.printStackTrace();
return "Error in toString()";
}
} }
private IPluginModelBase findModel(IProject p) { private IPluginModelBase findModel(IProject p) {

View File

@ -104,20 +104,6 @@ public class JdtUtil {
return className; return className;
} }
// public static String getMethodSignature(IMethod method) {
// if (method == null) {
// throw new IllegalArgumentException("method is null");
// }
// try {
// String methodParamReturnInfo = method.getSignature();
// String methodName = method.getElementName();
// String methodSignature = methodName + " " + methodParamReturnInfo;
// return methodSignature;
// } catch (JavaModelException e) {
// }
// return "";
// }
/** /**
* Return a unique string representing the specified Java element across projects in the workspace. The returned string can be * Return a unique string representing the specified Java element across projects in the workspace. The returned string can be
* used as a handle to create JavaElement by 'JavaCore.create(String)' * used as a handle to create JavaElement by 'JavaCore.create(String)'
@ -135,6 +121,7 @@ public class JdtUtil {
return javaElt.getHandleIdentifier(); return javaElt.getHandleIdentifier();
} }
@Deprecated
public static IJavaElement createJavaElementFromJdtHandle(String jdtHandle) { public static IJavaElement createJavaElementFromJdtHandle(String jdtHandle) {
return JavaCore.create(jdtHandle); return JavaCore.create(jdtHandle);
} }

View File

@ -84,6 +84,9 @@ public class PointsToMap {
* If p is unified, returns the representative for p. * If p is unified, returns the representative for p.
*/ */
public PointsToSetVariable getPointsToSet(PointerKey p) { public PointsToSetVariable getPointsToSet(PointerKey p) {
if (p == null) {
throw new IllegalArgumentException("null p");
}
if (isImplicit(p)) { if (isImplicit(p)) {
throw new IllegalArgumentException("unexpected: shouldn't ask a PointsToMap for an implicit points-to-set: " + p); throw new IllegalArgumentException("unexpected: shouldn't ask a PointsToMap for an implicit points-to-set: " + p);
} }
@ -111,6 +114,9 @@ public class PointsToMap {
* record that a particular points-to-set is represented implicitly * record that a particular points-to-set is represented implicitly
*/ */
public void recordImplicit(PointerKey key) { public void recordImplicit(PointerKey key) {
if (key == null) {
throw new IllegalArgumentException("null key");
}
int i = findOrCreateIndex(key); int i = findOrCreateIndex(key);
pointsToSets.set(i, IMPLICIT); pointsToSets.set(i, IMPLICIT);
} }

View File

@ -11,10 +11,7 @@
package com.ibm.wala.model; package com.ibm.wala.model;
/** /**
*
* A bogus class to support returning "unknown" objects * A bogus class to support returning "unknown" objects
*
* @author sfink
*/ */
public class SyntheticFactory { public class SyntheticFactory {

View File

@ -32,29 +32,29 @@ import com.ibm.wala.util.strings.Atom;
/** /**
* Reads {@link AnalysisScope} from a text file. * Reads {@link AnalysisScope} from a text file.
*
*/ */
public class AnalysisScopeReader { public class AnalysisScopeReader {
private static final ClassLoader MY_CLASSLOADER = AnalysisScopeReader.class.getClassLoader(); private static final ClassLoader MY_CLASSLOADER = AnalysisScopeReader.class.getClassLoader();
private static final String BASIC_FILE = "primordial.txt"; private static final String BASIC_FILE = "primordial.txt";
public static AnalysisScope readJavaScope(String scopeFileName, File exclusionsFile, ClassLoader javaLoader) {
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
public static AnalysisScope readJavaScope(String scopeFileName, File exclusionsFile, ClassLoader javaLoader) throws IOException {
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
return read(scope, scopeFileName, exclusionsFile, javaLoader, CorePlugin.getDefault()); return read(scope, scopeFileName, exclusionsFile, javaLoader, CorePlugin.getDefault());
} }
private static AnalysisScope readJavaScope(String scopeFileName, File exclusionsFile, ClassLoader javaLoader, Plugin plugIn) { private static AnalysisScope readJavaScope(String scopeFileName, File exclusionsFile, ClassLoader javaLoader, Plugin plugIn) throws IOException {
AnalysisScope scope = AnalysisScope.createJavaAnalysisScope(); AnalysisScope scope = AnalysisScope.createJavaAnalysisScope();
return read(scope, scopeFileName, exclusionsFile, javaLoader, plugIn); return read(scope, scopeFileName, exclusionsFile, javaLoader, plugIn);
} }
private static AnalysisScope read(AnalysisScope scope, String scopeFileName, File exclusionsFile, ClassLoader javaLoader, Plugin plugIn) { private static AnalysisScope read(AnalysisScope scope, String scopeFileName, File exclusionsFile, ClassLoader javaLoader,
Plugin plugIn) throws IOException {
BufferedReader r = null; BufferedReader r = null;
try { try {
File scopeFile = (plugIn == null) ? FileProvider.getFile(scopeFileName, javaLoader): FileProvider.getFileFromPlugin(plugIn, scopeFileName); File scopeFile = (plugIn == null) ? FileProvider.getFile(scopeFileName, javaLoader) : FileProvider.getFileFromPlugin(plugIn,
scopeFileName);
assert scopeFile.exists(); assert scopeFile.exists();
String line; String line;
@ -67,15 +67,12 @@ public class AnalysisScopeReader {
scope.setExclusions(FileOfClasses.createFileOfClasses(exclusionsFile)); scope.setExclusions(FileOfClasses.createFileOfClasses(exclusionsFile));
} }
} catch (IOException e) {
e.printStackTrace();
Assertions.UNREACHABLE(e.toString());
} finally { } finally {
if (r != null) { if (r != null) {
try { try {
r.close(); r.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
@ -126,34 +123,37 @@ public class AnalysisScopeReader {
Assertions.UNREACHABLE(); Assertions.UNREACHABLE();
} }
} }
/** /**
* @param exclusionsFile file holding class hierarchy exclusions. may be null * @param exclusionsFile file holding class hierarchy exclusions. may be null
* @throws IOException
* @throws IllegalStateException if there are problmes reading wala properties * @throws IllegalStateException if there are problmes reading wala properties
*/ */
public static AnalysisScope makePrimordialScope(File exclusionsFile) { public static AnalysisScope makePrimordialScope(File exclusionsFile) throws IOException {
return readJavaScope(BASIC_FILE, exclusionsFile, MY_CLASSLOADER, CorePlugin.getDefault()); return readJavaScope(BASIC_FILE, exclusionsFile, MY_CLASSLOADER, CorePlugin.getDefault());
} }
private static AnalysisScope makePrimordialScope(File exclusionsFile, Plugin plugIn) { private static AnalysisScope makePrimordialScope(File exclusionsFile, Plugin plugIn) throws IOException {
return readJavaScope(BASIC_FILE, exclusionsFile, MY_CLASSLOADER, plugIn); return readJavaScope(BASIC_FILE, exclusionsFile, MY_CLASSLOADER, plugIn);
} }
/** /**
* @param classPath class path to analyze, delimited by File.pathSeparator * @param classPath class path to analyze, delimited by File.pathSeparator
* @param exclusionsFile file holding class hierarchy exclusions. may be null * @param exclusionsFile file holding class hierarchy exclusions. may be null
* @throws IOException
* @throws IllegalStateException if there are problems reading wala properties * @throws IllegalStateException if there are problems reading wala properties
*/ */
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile) { public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile) throws IOException {
return makeJavaBinaryAnalysisScope(classPath, exclusionsFile, CorePlugin.getDefault()); return makeJavaBinaryAnalysisScope(classPath, exclusionsFile, CorePlugin.getDefault());
} }
/** /**
* @param classPath class path to analyze, delimited by File.pathSeparator * @param classPath class path to analyze, delimited by File.pathSeparator
* @param exclusionsFile file holding class hierarchy exclusions. may be null * @param exclusionsFile file holding class hierarchy exclusions. may be null
* @throws IOException
* @throws IllegalStateException if there are problems reading wala properties * @throws IllegalStateException if there are problems reading wala properties
*/ */
public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile, Plugin plugIn) { public static AnalysisScope makeJavaBinaryAnalysisScope(String classPath, File exclusionsFile, Plugin plugIn) throws IOException {
if (classPath == null) { if (classPath == null) {
throw new IllegalArgumentException("classPath null"); throw new IllegalArgumentException("classPath null");
} }

View File

@ -19,13 +19,10 @@ import com.ibm.wala.util.debug.Assertions;
import com.ibm.wala.util.debug.Trace; import com.ibm.wala.util.debug.Trace;
/** /**
*
* A relation between non-negative integers * A relation between non-negative integers
* *
* This implementation uses n IntVectors, to hold the first n y's associated with each x, and then 1 extra vector of SparseIntSet to * This implementation uses n IntVectors, to hold the first n y's associated with each x, and then 1 extra vector of SparseIntSet to
* hold the remaining ys. * hold the remaining ys.
*
* @author sfink
*/ */
public final class BasicNaturalRelation implements IBinaryNaturalRelation { public final class BasicNaturalRelation implements IBinaryNaturalRelation {
@ -126,18 +123,14 @@ public final class BasicNaturalRelation implements IBinaryNaturalRelation {
* This is performance-critical, so the implementation looks a little ugly in order to help out the compiler with redundancy * This is performance-critical, so the implementation looks a little ugly in order to help out the compiler with redundancy
* elimination. * elimination.
* *
* @param x
* @param y
* @return true iff the relation changes as a result of this call. * @return true iff the relation changes as a result of this call.
*/ */
public boolean add(int x, int y) throws IllegalArgumentException { public boolean add(int x, int y) throws IllegalArgumentException {
if (Assertions.verifyAssertions) { if (x < 0) {
if (x < 0) { throw new IllegalArgumentException("illegal x: " + x);
throw new IllegalArgumentException("illegal x: " + x); }
} if (y < 0) {
if (y < 0) { throw new IllegalArgumentException("illegal y: " + y);
throw new IllegalArgumentException("illegal y: " + y);
}
} }
maxX = Math.max(maxX, x); maxX = Math.max(maxX, x);
MutableIntSet delegated = (MutableIntSet) delegateStore.get(x); MutableIntSet delegated = (MutableIntSet) delegateStore.get(x);
@ -351,6 +344,12 @@ public final class BasicNaturalRelation implements IBinaryNaturalRelation {
} }
public void remove(int x, int y) { public void remove(int x, int y) {
if (x < 0) {
throw new IllegalArgumentException("illegal x: " + x);
}
if (y < 0) {
throw new IllegalArgumentException("illegal y: " + y);
}
if (usingDelegate(x)) { if (usingDelegate(x)) {
// TODO: switch representation back to small store? // TODO: switch representation back to small store?
MutableIntSet s = (MutableIntSet) delegateStore.get(x); MutableIntSet s = (MutableIntSet) delegateStore.get(x);

View File

@ -14,50 +14,35 @@ import com.ibm.wala.util.debug.VerboseAction;
/** /**
* a relation R(x,y) where x >= 0 * a relation R(x,y) where x >= 0
*
* @author sfink
*/ */
public interface IBinaryNaturalRelation extends VerboseAction, Iterable<IntPair> { public interface IBinaryNaturalRelation extends VerboseAction, Iterable<IntPair> {
/** /**
* Add (x,y) to the relation * Add (x,y) to the relation
* *
* @param x
* @param y
* @return true iff the relation changes as a result of this call. * @return true iff the relation changes as a result of this call.
*/ */
public abstract boolean add(int x, int y); public abstract boolean add(int x, int y);
/** /**
* @param x
* @return IntSet of y s.t. R(x,y) or null if none. * @return IntSet of y s.t. R(x,y) or null if none.
*/ */
public abstract IntSet getRelated(int x); public abstract IntSet getRelated(int x);
/** /**
* @param x
* @return number of y s.t. R(x,y) * @return number of y s.t. R(x,y)
*/ */
public abstract int getRelatedCount(int x); public abstract int getRelatedCount(int x);
/** /**
* @param x
* @return true iff there exists pair (x,y) for some y * @return true iff there exists pair (x,y) for some y
*/ */
public abstract boolean anyRelated(int x); public abstract boolean anyRelated(int x);
/**
* @param x
* @param y
*/
public abstract void remove(int x, int y); public abstract void remove(int x, int y);
/**
*/
public abstract void removeAll(int x); public abstract void removeAll(int x);
/** /**
* @param x
* @param y
* @return true iff (x,y) \in R * @return true iff (x,y) \in R
*/ */
public abstract boolean contains(int x, int y); public abstract boolean contains(int x, int y);

View File

@ -62,6 +62,9 @@ public class MultiModalIntVector implements IntVector {
} }
public MultiModalIntVector(int defaultValue, int initialSize) { public MultiModalIntVector(int defaultValue, int initialSize) {
if (initialSize <= 0) {
throw new IllegalArgumentException("invalid initialSize: " + initialSize);
}
this.defaultValue = defaultValue; this.defaultValue = defaultValue;
init(initialSize, defaultValue); init(initialSize, defaultValue);
} }
@ -94,8 +97,8 @@ public class MultiModalIntVector implements IntVector {
* @see com.ibm.wala.util.intset.IntVector#get(int) * @see com.ibm.wala.util.intset.IntVector#get(int)
*/ */
public int get(int x) { public int get(int x) {
if (Assertions.verifyAssertions) { if (x < 0) {
Assertions._assert(x >= 0); throw new IllegalArgumentException("illegal x: " + x);
} }
int index = x; int index = x;
if (index < byteStore.length) { if (index < byteStore.length) {
@ -120,8 +123,11 @@ public class MultiModalIntVector implements IntVector {
* @see com.ibm.wala.util.intset.IntVector#set(int, int) * @see com.ibm.wala.util.intset.IntVector#set(int, int)
*/ */
public void set(int x, int value) { public void set(int x, int value) {
if (Assertions.verifyAssertions) { if (x < 0) {
Assertions._assert(x >= 0); throw new IllegalArgumentException("illegal x: " + x);
}
if (x > MAX_SIZE) {
throw new IllegalArgumentException("x is too big: " + x);
} }
maxIndex = Math.max(maxIndex, x); // Find out if the new position is bigger than size of the array maxIndex = Math.max(maxIndex, x); // Find out if the new position is bigger than size of the array
handleMorph(x, value); handleMorph(x, value);
@ -241,42 +247,6 @@ public class MultiModalIntVector implements IntVector {
} }
} }
/*
* @see com.ibm.wala.util.intset.IntVector#reportStats()
*/
public void performVerboseAction() {
int length = getStoreLength();
Trace.println("size: " + length);
Trace.println("occupancy: " + computeOccupancy(length));
}
/**
* @return the percentage of entries in delegateStore that are non-null
*/
private double computeOccupancy(int length) {
int count1 = 0;
int internalLength = length;
for (int i = 0; i < internalLength && i < byteStore.length; i++) {
if (byteStore[i] != -1) {
count1++;
}
}
length -= byteStore.length;
for (int i = 0; i < internalLength && i < byteStore.length; i++) {
if (shortStore[i] != -1) {
count1++;
}
}
length -= shortStore.length;
for (int i = 0; i < internalLength && i < intStore.length; i++) {
if (intStore[i] != -1) {
count1++;
}
}
int count = count1;
return (double) count / (double) length;
}
public int getMaxIndex() { public int getMaxIndex() {
return maxIndex; return maxIndex;
} }

View File

@ -469,6 +469,9 @@ public class MutableSharedBitVectorIntSet implements MutableIntSet {
* @see com.ibm.wala.util.intset.IntSet#isSubset(com.ibm.wala.util.intset.IntSet) * @see com.ibm.wala.util.intset.IntSet#isSubset(com.ibm.wala.util.intset.IntSet)
*/ */
public boolean isSubset(IntSet that) { public boolean isSubset(IntSet that) {
if (that == null) {
throw new IllegalArgumentException("null that");
}
if (that instanceof MutableSharedBitVectorIntSet) { if (that instanceof MutableSharedBitVectorIntSet) {
return isSubset((MutableSharedBitVectorIntSet) that); return isSubset((MutableSharedBitVectorIntSet) that);
} else { } else {

View File

@ -350,11 +350,8 @@ public class StringStuff {
* *
* TODO: inefficient; needs tuning. * TODO: inefficient; needs tuning.
* *
* @param name
* @param start
* @param length
* @return an ImmutableByteArray that represents the package, or null if it's the unnamed package * @return an ImmutableByteArray that represents the package, or null if it's the unnamed package
* @throws IllegalArgumentException if name is null * @throws IllegalArgumentException if name is null or malformed
*/ */
public static ImmutableByteArray parseForClass(ImmutableByteArray name, int start, int length) throws IllegalArgumentException { public static ImmutableByteArray parseForClass(ImmutableByteArray name, int start, int length) throws IllegalArgumentException {
if (name == null) { if (name == null) {
@ -363,6 +360,7 @@ public class StringStuff {
if (name.length() == 0) { if (name.length() == 0) {
throw new IllegalArgumentException("invalid class name: zero length"); throw new IllegalArgumentException("invalid class name: zero length");
} }
try {
if (parseForPackage(name, start, length) == null) { if (parseForPackage(name, start, length) == null) {
while (name.b[start] == '[') { while (name.b[start] == '[') {
start++; start++;
@ -383,6 +381,9 @@ public class StringStuff {
int L = length - (lastSlash - start + 1); int L = length - (lastSlash - start + 1);
return new ImmutableByteArray(name.b, lastSlash + 1, L); return new ImmutableByteArray(name.b, lastSlash + 1, L);
} }
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Malformed name: " + name + " " + start + " " + length);
}
} }
/** /**