Fix 65 Eclipse warnings about unused exception parameters

In the cases addressed here, the caught exception was being "handled"
by throwing some new exception.  Instead of discarding the old
exception, pass it to the new exception's constructor to indicate the
original cause of the newly-created exception.  This practice, called
"exception chaining", can often be useful in debugging.
This commit is contained in:
Ben Liblit 2017-03-17 23:38:59 -05:00
parent 059810c1ca
commit aaf66705e1
34 changed files with 65 additions and 65 deletions

View File

@ -377,7 +377,7 @@ public class JSAstTranslator extends AstTranslator {
resultVal, context.currentScope().getConstantValue( null )));
}
} catch (ClassCastException e) {
throw new RuntimeException("Cannot translate primitive " + primitiveCall.getChild(0).getValue());
throw new RuntimeException("Cannot translate primitive " + primitiveCall.getChild(0).getValue(), e);
}
}

View File

@ -79,7 +79,7 @@ public class NullPointerExceptionInterTest extends WalaTestCase {
CallGraphBuilder builder = Util.makeNCFABuilder(1, options, cache, cha, scope);
cg = builder.makeCallGraph(options, null);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -71,7 +71,7 @@ public class NullPointerExceptionIntraTest extends WalaTestCase {
try {
cha = ClassHierarchyFactory.make(scope, factory);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -56,7 +56,7 @@ public class GetTargetsTest extends WalaTestCase {
try {
cha = ClassHierarchyFactory.make(scope, factory);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -57,7 +57,7 @@ public class InnerClassesTest extends WalaTestCase {
try {
cha = ClassHierarchyFactory.make(scope, factory);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -53,7 +53,7 @@ public class InterfaceTest extends WalaTestCase {
try {
cha = ClassHierarchyFactory.make(scope, factory);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -79,7 +79,7 @@ public class LocalNamesTest extends WalaTestCase {
try {
cha = ClassHierarchyFactory.make(scope, factory);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -75,7 +75,7 @@ public class TypeInferenceTest extends WalaTestCase {
try {
cha = ClassHierarchyFactory.make(scope, factory);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -90,7 +90,7 @@ public class DataflowTest extends WalaTestCase {
try {
cha = ClassHierarchyFactory.make(scope);
} catch (ClassHierarchyException e) {
throw new Exception();
throw new Exception(e);
}
}

View File

@ -73,7 +73,7 @@ public class SourceFileModule extends FileModule implements Module, ModuleEntry,
try {
return getFile().toURI().toURL();
} catch (MalformedURLException e) {
throw new Error("error making URL for " + getFile());
throw new Error("error making URL for " + getFile(), e);
}
}
}

View File

@ -95,7 +95,7 @@ public class SymbolTable implements Cloneable {
assert vn < nextFreeValueNumber;
values[vn] = val;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid vn: " + vn);
throw new IllegalArgumentException("invalid vn: " + vn, e);
}
}
@ -167,7 +167,7 @@ public class SymbolTable implements Cloneable {
try {
return parameters[i];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid i: " + i);
throw new IllegalArgumentException("invalid i: " + i, e);
}
}
@ -204,7 +204,7 @@ public class SymbolTable implements Cloneable {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid i: " + i);
throw new IllegalArgumentException("invalid i: " + i, e);
}
}
@ -222,7 +222,7 @@ public class SymbolTable implements Cloneable {
try {
return v < values.length && values[v] instanceof ConstantValue;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -230,7 +230,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).isZeroConstant();
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -238,7 +238,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).isOneConstant();
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -246,7 +246,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).isTrueConstant();
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -262,7 +262,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).isFalseConstant();
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -274,7 +274,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).getValue() instanceof Boolean;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -282,7 +282,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && (((ConstantValue) values[v]).getValue() instanceof Integer);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -290,7 +290,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && (((ConstantValue) values[v]).getValue() instanceof Long);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -298,7 +298,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).getValue() instanceof Float;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -306,7 +306,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).getValue() instanceof Double;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -314,7 +314,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).getValue() instanceof Number;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -322,7 +322,7 @@ public class SymbolTable implements Cloneable {
try {
return (values[v] instanceof ConstantValue) && ((ConstantValue) values[v]).getValue() instanceof String;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -330,7 +330,7 @@ public class SymbolTable implements Cloneable {
try {
return (values.length > v) && (values[v] instanceof ConstantValue) && (((ConstantValue) values[v]).getValue() == null);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid v: " + v);
throw new IllegalArgumentException("invalid v: " + v, e);
}
}
@ -355,9 +355,9 @@ public class SymbolTable implements Cloneable {
try {
return (PhiValue) values[valueNumber];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid valueNumber: " + valueNumber);
throw new IllegalArgumentException("invalid valueNumber: " + valueNumber, e);
} catch (ClassCastException e) {
throw new IllegalArgumentException("invalid valueNumber: " + valueNumber);
throw new IllegalArgumentException("invalid valueNumber: " + valueNumber, e);
}
}

View File

@ -37,7 +37,7 @@ public final class Selector {
String desc = selectorStr.substring(selectorStr.indexOf('('));
return new Selector(Atom.findOrCreateUnicodeAtom(methodName), Descriptor.findOrCreateUTF8(l, desc));
} catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid selectorStr: " + selectorStr);
throw new IllegalArgumentException("invalid selectorStr: " + selectorStr, e);
}
}

View File

@ -184,7 +184,7 @@ public class ProgressMaster implements IProgressMonitor {
try {
ManagementFactory.getPlatformMBeanServer().addNotificationListener(gcbean.getObjectName(), listener, null, null);
} catch (InstanceNotFoundException e) {
throw new Error("cannot find existing bean");
throw new Error("cannot find existing bean", e);
}
}
@ -194,7 +194,7 @@ public class ProgressMaster implements IProgressMonitor {
try {
ManagementFactory.getPlatformMBeanServer().removeNotificationListener(gcbean.getObjectName(), listener);
} catch (InstanceNotFoundException | ListenerNotFoundException e) {
throw new Error("cannot find existing bean");
throw new Error("cannot find existing bean", e);
}
}

View File

@ -159,7 +159,7 @@ public class FileProvider {
try {
return new JarFileModule(new JarFile(fileName, false));
} catch (ZipException e) {
throw new IOException("Could not find file: " + fileName);
throw new IOException("Could not find file: " + fileName, e);
}
}
if (url.getProtocol().equals("jar")) {

View File

@ -278,7 +278,7 @@ public final class Atom implements Serializable {
}
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalStateException("not an array: " + this);
throw new IllegalStateException("not an array: " + this, e);
}
}
@ -299,7 +299,7 @@ public final class Atom implements Serializable {
}
return findOrCreate(val, i, val.length - i);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalStateException("not an array: " + this);
throw new IllegalStateException("not an array: " + this, e);
}
}
@ -403,7 +403,7 @@ public final class Atom implements Serializable {
try {
return val[i];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Illegal index: " + i + " length is " + val.length);
throw new IllegalArgumentException("Illegal index: " + i + " length is " + val.length, e);
}
}

View File

@ -39,7 +39,7 @@ public final class ImmutableByteArray {
try {
System.arraycopy(b, start, this.b, 0, length);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("illegal parameters " + b.length + " " + start + " " + length);
throw new IllegalArgumentException("illegal parameters " + b.length + " " + start + " " + length, e);
}
}
@ -65,7 +65,7 @@ public final class ImmutableByteArray {
try {
System.arraycopy(b, i, result, 0, length);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Invalid combination: " + i + " " + length);
throw new IllegalArgumentException("Invalid combination: " + i + " " + length, e);
}
return result;
}

View File

@ -340,7 +340,7 @@ public class StringStuff {
}
return new ImmutableByteArray(name.b, start + 1 + dim, lastSlash - start - 1 - dim);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid name " + name + " start: " + start + " length: " + length);
throw new IllegalArgumentException("invalid name " + name + " start: " + start + " length: " + length, e);
}
}
@ -394,7 +394,7 @@ public class StringStuff {
return new ImmutableByteArray(name.b, lastSlash + 1, L);
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Malformed name: " + name + " " + start + " " + length);
throw new IllegalArgumentException("Malformed name: " + name + " " + start + " " + length, e);
}
}
@ -443,7 +443,7 @@ public class StringStuff {
}
return code;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("ill-formed array descriptor " + b);
throw new IllegalArgumentException("ill-formed array descriptor " + b, e);
}
}
@ -468,7 +468,7 @@ public class StringStuff {
}
return new ImmutableByteArray(b.b, i, length - (i - start));
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid element desciptor: " + b);
throw new IllegalArgumentException("invalid element desciptor: " + b, e);
}
}
@ -506,7 +506,7 @@ public class StringStuff {
return name.b[start] != 'L';
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException(name.toString());
throw new IllegalArgumentException(name.toString(), e);
}
}

View File

@ -100,7 +100,7 @@ public class AndroidAnalysisScope {
scope.addClassFileToScope(loader, f);
} catch (InvalidClassFileException e) {
throw new IllegalArgumentException(
"Invalid class file");
"Invalid class file", e);
}
}
}

View File

@ -370,7 +370,7 @@ public class JdtUtil {
return result;
}
} catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid selector: " + selector);
throw new IllegalArgumentException("invalid selector: " + selector, e);
}
}
@ -455,7 +455,7 @@ public class JdtUtil {
}
}
} catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("error parsing selector " + selector);
throw new IllegalArgumentException("error parsing selector " + selector, e);
}
}

View File

@ -148,7 +148,7 @@ public class EclipseFileProvider extends FileProvider {
url = fixupFileURLSpaces(url);
return url;
} catch (ExceptionInInitializerError e) {
throw new IOException("failure to get file URL for " + fileName);
throw new IOException("failure to get file URL for " + fileName, e);
}
}

View File

@ -168,7 +168,7 @@ public class DexDotUtil extends DotUtil {
return f;
} catch (Exception e) {
throw new WalaException("Error writing dot file " + dotfile);
throw new WalaException("Error writing dot file " + dotfile, e);
}
}

View File

@ -415,7 +415,7 @@ public final class MethodEditor {
}
patchCount++;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid i");
throw new IllegalArgumentException("invalid i", e);
}
}
@ -454,7 +454,7 @@ public final class MethodEditor {
instructionHandlerPatches[i] = new HandlerPatch(instructionHandlerPatches[i], catchClass, allocateLabel(), p);
patchCount++;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid i: " + i);
throw new IllegalArgumentException("invalid i: " + i, e);
}
}

View File

@ -219,7 +219,7 @@ public final class Util {
}
return count;
} catch (StringIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid type: " + type);
throw new IllegalArgumentException("invalid type: " + type, e);
}
}

View File

@ -952,7 +952,7 @@ public class ClassWriter implements ClassConstants {
try {
buf[offset] = (byte) v;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid offset: " + offset);
throw new IllegalArgumentException("invalid offset: " + offset, e);
}
}
@ -971,7 +971,7 @@ public class ClassWriter implements ClassConstants {
buf[offset + 2] = (byte) (v >> 8);
buf[offset + 3] = (byte) v;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("illegal offset " + offset);
throw new IllegalArgumentException("illegal offset " + offset, e);
}
}
@ -1013,7 +1013,7 @@ public class ClassWriter implements ClassConstants {
buf[offset] = (byte) (v >> 8);
buf[offset + 1] = (byte) v;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid offset: " + offset);
throw new IllegalArgumentException("invalid offset: " + offset, e);
}
}
}

View File

@ -151,7 +151,7 @@ public final class LocalVariableTableWriter extends ClassWriter.Element {
return r;
}
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("malformed varMap");
throw new IllegalArgumentException("malformed varMap", e);
}
}
}

View File

@ -202,7 +202,7 @@ public class ArraySet<T> extends AbstractSet<T> {
_curIndex--;
return true;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid ind: " + ind);
throw new IllegalArgumentException("invalid ind: " + ind, e);
}
}

View File

@ -161,7 +161,7 @@ public class ImmutableStack<T> implements Iterable<T> {
try {
return entries[i];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid i: " + i);
throw new IllegalArgumentException("invalid i: " + i, e);
}
}

View File

@ -45,7 +45,7 @@ public class ObjectArrayMapping<T> implements OrdinalSetMapping<T> {
try {
return array[n];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid n: " + n);
throw new IllegalArgumentException("invalid n: " + n, e);
}
}

View File

@ -57,7 +57,7 @@ public class SmallMap<K, V> implements Map<K, V> {
try {
return (K) keysAndValues[i];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid i: " + i);
throw new IllegalArgumentException("invalid i: " + i, e);
}
}
@ -73,7 +73,7 @@ public class SmallMap<K, V> implements Map<K, V> {
try {
return keysAndValues[size() + i];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("illegal i: " + i);
throw new IllegalArgumentException("illegal i: " + i, e);
}
}

View File

@ -50,7 +50,7 @@ public class DelegatingNumberedNodeManager<T extends INodeWithNumber> implements
try {
return (T) nodes[number];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("Invalid number " + number);
throw new IllegalArgumentException("Invalid number " + number, e);
}
}

View File

@ -79,7 +79,7 @@ public final class FixedSizeBitVector implements Cloneable, java.io.Serializable
int shiftBits = bit & LOW_MASK;
bits[subscript(bit)] |= (1 << shiftBits);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid bit " + bit);
throw new IllegalArgumentException("invalid bit " + bit, e);
}
}
@ -102,7 +102,7 @@ public final class FixedSizeBitVector implements Cloneable, java.io.Serializable
int shiftBits = bit & LOW_MASK;
bits[subscript(bit)] &= ~(1 << shiftBits);
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("invalid bit: " + bit);
throw new IllegalArgumentException("invalid bit: " + bit, e);
}
}

View File

@ -67,7 +67,7 @@ public class MutableMapping<T> implements OrdinalSetMapping<T>, Serializable {
try {
return (T) array[n];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException("n out of range " + n);
throw new IllegalArgumentException("n out of range " + n, e);
}
}

View File

@ -91,7 +91,7 @@ public class Table<T> {
SimpleVector<T> r = rows.get(row);
return r.get(column);
} catch (IndexOutOfBoundsException e) {
throw new IllegalArgumentException("row: " + row + " column: " + column);
throw new IllegalArgumentException("row: " + row + " column: " + column, e);
}
}

View File

@ -174,7 +174,7 @@ public class DotUtil {
return f;
} catch (Exception e) {
throw new WalaException("Error writing dot file " + dotfile);
throw new WalaException("Error writing dot file " + dotfile, e);
}
}