misc. bug fixes and annotations
git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@578 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
parent
f9634add14
commit
08e6f673ba
|
@ -36,7 +36,10 @@ public class ExtractMatchingClasses {
|
|||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
public static void main(String[] args) throws Exception, IllegalArgumentException {
|
||||
if (args.length < 2) {
|
||||
throw new IllegalArgumentException("Invalid command line");
|
||||
}
|
||||
String in = args[0];
|
||||
String out = args[1];
|
||||
String[] match = new String[args.length - 2];
|
||||
|
|
|
@ -29,7 +29,7 @@ final public class ArrayStoreInstruction extends Instruction {
|
|||
return r;
|
||||
}
|
||||
|
||||
public static ArrayStoreInstruction make(String type) {
|
||||
public static ArrayStoreInstruction make(String type) throws IllegalArgumentException {
|
||||
int i = Util.getTypeIndex(type);
|
||||
if (i < 0 || i > TYPE_boolean_index) {
|
||||
throw new IllegalArgumentException("Invalid type " + type + " for ArrayStoreInstruction");
|
||||
|
|
|
@ -45,7 +45,7 @@ public final class ConversionInstruction extends Instruction {
|
|||
return r;
|
||||
}
|
||||
|
||||
public static ConversionInstruction make(String fromType, String toType) {
|
||||
public static ConversionInstruction make(String fromType, String toType) throws IllegalArgumentException {
|
||||
int from = Util.getTypeIndex(fromType);
|
||||
int to = Util.getTypeIndex(toType);
|
||||
if (from < 0 || from > TYPE_double_index) {
|
||||
|
|
|
@ -36,7 +36,7 @@ public final class LoadInstruction extends Instruction {
|
|||
return r;
|
||||
}
|
||||
|
||||
public static LoadInstruction make(String type, int index) {
|
||||
public static LoadInstruction make(String type, int index) throws IllegalArgumentException {
|
||||
int t = Util.getTypeIndex(type);
|
||||
if (t < 0 || t > TYPE_Object_index) {
|
||||
throw new IllegalArgumentException("Cannot load local of type " + type);
|
||||
|
|
|
@ -12,6 +12,7 @@ package com.ibm.wala.shrikeBT;
|
|||
|
||||
public final class NewInstruction extends Instruction {
|
||||
private String type;
|
||||
|
||||
private short arrayBoundsCount;
|
||||
|
||||
protected NewInstruction(short opcode, String type, short arrayBoundsCount) {
|
||||
|
@ -28,7 +29,7 @@ public final class NewInstruction extends Instruction {
|
|||
* the number of array dimensions to preconstruct (equal to the
|
||||
* number of integer parameters this instruction expects)
|
||||
*/
|
||||
public static NewInstruction make(String type, int arrayBoundsCount) {
|
||||
public static NewInstruction make(String type, int arrayBoundsCount) throws IllegalArgumentException {
|
||||
if (arrayBoundsCount < 0 || arrayBoundsCount > 255) {
|
||||
throw new IllegalArgumentException("Too many array bounds: " + arrayBoundsCount);
|
||||
} else {
|
||||
|
@ -100,7 +101,10 @@ public final class NewInstruction extends Instruction {
|
|||
public void visit(Visitor v) {
|
||||
v.visitNew(this);
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see com.ibm.domo.cfg.IInstruction#isPEI()
|
||||
*/
|
||||
public boolean isPEI() {
|
||||
|
|
|
@ -29,7 +29,7 @@ public final class ReturnInstruction extends Instruction {
|
|||
return r;
|
||||
}
|
||||
|
||||
public static ReturnInstruction make(String type) {
|
||||
public static ReturnInstruction make(String type) throws IllegalArgumentException {
|
||||
if (type.equals(TYPE_void)) {
|
||||
return preallocatedVoid;
|
||||
} else {
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2002,2006 IBM Corporation.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.ibm.wala.shrikeBT;
|
||||
|
||||
/**
|
||||
* Settings for the whole ShrikeBT package.
|
||||
*/
|
||||
public class Settings {
|
||||
/**
|
||||
* Used to enable various checks if in DEBUG mode.
|
||||
*/
|
||||
public static final boolean DEBUG = false;
|
||||
|
||||
public int hashCode() {
|
||||
throw new Error("Settings.hashCode(): define a custom hash code to avoid non-determinancy");
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ public final class StoreInstruction extends Instruction {
|
|||
return r;
|
||||
}
|
||||
|
||||
public static StoreInstruction make(String type, int index) {
|
||||
public static StoreInstruction make(String type, int index) throws IllegalArgumentException {
|
||||
int t = Util.getTypeIndex(type);
|
||||
if (t < 0 || t > TYPE_Object_index) {
|
||||
throw new IllegalArgumentException("Cannot store local of type " + type);
|
||||
|
|
|
@ -122,7 +122,7 @@ public final class Util {
|
|||
/**
|
||||
* Convert a JVM type name back into a Java class name.
|
||||
*/
|
||||
public static String makeClass(String t) {
|
||||
public static String makeClass(String t) throws IllegalArgumentException {
|
||||
if (t.startsWith("[")) {
|
||||
return t;
|
||||
} else if (!t.startsWith("L")) {
|
||||
|
|
|
@ -59,9 +59,9 @@ public final class ClassHierarchyStore implements ClassHierarchyProvider {
|
|||
* @param superInterfaces
|
||||
* the JVM types of its implemented interfaces
|
||||
*/
|
||||
public void setClassInfo(String cl, boolean isInterface, boolean isFinal, String superClass, String[] superInterfaces) {
|
||||
public void setClassInfo(String cl, boolean isInterface, boolean isFinal, String superClass, String[] superInterfaces) throws IllegalArgumentException {
|
||||
if (superClass != null && superClass.equals(cl)) {
|
||||
throw new Error("Class " + cl + " cannot be its own superclass");
|
||||
throw new IllegalArgumentException("Class " + cl + " cannot be its own superclass");
|
||||
}
|
||||
contents.put(cl, new ClassInfo(isInterface, isFinal, superClass, superInterfaces));
|
||||
}
|
||||
|
|
|
@ -413,7 +413,7 @@ public abstract class OfflineInstrumenterBase {
|
|||
/**
|
||||
* Set the JAR Comment for the output JAR.
|
||||
*/
|
||||
final public void setJARComment(String comment) throws IOException {
|
||||
final public void setJARComment(String comment) throws IOException, IllegalArgumentException {
|
||||
makeOutputJar();
|
||||
outputJar.setComment(comment);
|
||||
}
|
||||
|
|
|
@ -401,7 +401,7 @@ public final class ClassWriter implements ClassConstants {
|
|||
/**
|
||||
* Set the constant pool index for the name of the class.
|
||||
*/
|
||||
public void setNameIndex(int c) {
|
||||
public void setNameIndex(int c) throws IllegalArgumentException {
|
||||
if (c < 1 || c > 0xFFFF) {
|
||||
throw new IllegalArgumentException("Class name index out of range: " + c);
|
||||
}
|
||||
|
@ -812,7 +812,7 @@ public final class ClassWriter implements ClassConstants {
|
|||
* After you've added everything you need to the class, call this method to
|
||||
* generate the actual class file data. This can only be called once.
|
||||
*/
|
||||
public byte[] makeBytes() {
|
||||
public byte[] makeBytes() throws IllegalArgumentException {
|
||||
if (buf != null) {
|
||||
throw new IllegalArgumentException("Can't call makeBytes() twice");
|
||||
}
|
||||
|
@ -882,7 +882,10 @@ public final class ClassWriter implements ClassConstants {
|
|||
/**
|
||||
* Set the byte at offset 'offset' in 'buf' to the unsigned 8-bit value in v.
|
||||
*/
|
||||
public static void setUByte(byte[] buf, int offset, int v) {
|
||||
public static void setUByte(byte[] buf, int offset, int v) throws IllegalArgumentException {
|
||||
if (offset >= buf.length) {
|
||||
throw new IllegalArgumentException("illegal offset " + offset);
|
||||
}
|
||||
buf[offset] = (byte) v;
|
||||
}
|
||||
|
||||
|
@ -890,7 +893,10 @@ public final class ClassWriter implements ClassConstants {
|
|||
* Set the 4 bytes at offset 'offset' in 'buf' to the signed 32-bit value in
|
||||
* v.
|
||||
*/
|
||||
public static void setInt(byte[] buf, int offset, int v) {
|
||||
public static void setInt(byte[] buf, int offset, int v) throws IllegalArgumentException {
|
||||
if (offset >= buf.length) {
|
||||
throw new IllegalArgumentException("illegal offset " + offset);
|
||||
}
|
||||
buf[offset] = (byte) (v >> 24);
|
||||
buf[offset + 1] = (byte) (v >> 16);
|
||||
buf[offset + 2] = (byte) (v >> 8);
|
||||
|
@ -901,7 +907,7 @@ public final class ClassWriter implements ClassConstants {
|
|||
* Set the 8 bytes at offset 'offset' in 'buf' to the signed 64-bit value in
|
||||
* v.
|
||||
*/
|
||||
public static void setLong(byte[] buf, int offset, long v) {
|
||||
public static void setLong(byte[] buf, int offset, long v) throws IllegalArgumentException {
|
||||
setInt(buf, offset, (int) (v >> 32));
|
||||
setInt(buf, offset + 4, (int) v);
|
||||
}
|
||||
|
@ -909,14 +915,14 @@ public final class ClassWriter implements ClassConstants {
|
|||
/**
|
||||
* Set the 4 bytes at offset 'offset' in 'buf' to the float value in v.
|
||||
*/
|
||||
public static void setFloat(byte[] buf, int offset, float v) {
|
||||
public static void setFloat(byte[] buf, int offset, float v) throws IllegalArgumentException{
|
||||
setInt(buf, offset, Float.floatToIntBits(v));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the 8 bytes at offset 'offset' in 'buf' to the double value in v.
|
||||
*/
|
||||
public static void setDouble(byte[] buf, int offset, double v) {
|
||||
public static void setDouble(byte[] buf, int offset, double v) throws IllegalArgumentException{
|
||||
setLong(buf, offset, Double.doubleToRawLongBits(v));
|
||||
}
|
||||
|
||||
|
@ -924,7 +930,7 @@ public final class ClassWriter implements ClassConstants {
|
|||
* Set the 2 bytes at offset 'offset' in 'buf' to the unsigned 16-bit value in
|
||||
* v.
|
||||
*/
|
||||
public static void setUShort(byte[] buf, int offset, int v) {
|
||||
public static void setUShort(byte[] buf, int offset, int v) throws IllegalArgumentException {
|
||||
if (offset + 1 >= buf.length) {
|
||||
throw new IllegalArgumentException("buf is too short " + buf.length + " " + offset);
|
||||
}
|
||||
|
|
|
@ -43,12 +43,11 @@ public final class CodeWriter extends ClassWriter.Element {
|
|||
}
|
||||
}
|
||||
|
||||
//By Xiangyu
|
||||
public int getCodeLength() {
|
||||
return code.length;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
public int getSize() throws IllegalArgumentException {
|
||||
verify();
|
||||
|
||||
int size = 14 + code.length + 2 + (exnHandlers == null ? 0 : exnHandlers.length) * 2 + 2;
|
||||
|
@ -60,7 +59,7 @@ public final class CodeWriter extends ClassWriter.Element {
|
|||
return size;
|
||||
}
|
||||
|
||||
public int copyInto(byte[] buf, int offset) {
|
||||
public int copyInto(byte[] buf, int offset) throws IllegalArgumentException {
|
||||
verify();
|
||||
|
||||
int start = offset;
|
||||
|
|
|
@ -28,7 +28,7 @@ public final class ExceptionsWriter extends ClassWriter.Element {
|
|||
return table == null ? 8 : 8 + table.length * 2;
|
||||
}
|
||||
|
||||
public int copyInto(byte[] buf, int offset) {
|
||||
public int copyInto(byte[] buf, int offset) throws IllegalArgumentException {
|
||||
ClassWriter.setUShort(buf, offset, attrID);
|
||||
ClassWriter.setInt(buf, offset + 2, getSize() - 6);
|
||||
ClassWriter.setUShort(buf, offset + 6, table == null ? 0 : table.length);
|
||||
|
|
|
@ -58,7 +58,7 @@ public final class LineNumberTableWriter extends ClassWriter.Element {
|
|||
return 8 + rawTable.length * 2;
|
||||
}
|
||||
|
||||
public int copyInto(byte[] buf, int offset) {
|
||||
public int copyInto(byte[] buf, int offset) throws IllegalArgumentException {
|
||||
ClassWriter.setUShort(buf, offset, attrID);
|
||||
ClassWriter.setInt(buf, offset + 2, 2 + rawTable.length * 2);
|
||||
ClassWriter.setUShort(buf, offset + 6, rawTable.length / 2);
|
||||
|
|
|
@ -61,7 +61,7 @@ public final class LocalVariableTableWriter extends ClassWriter.Element {
|
|||
return 8 + rawTable.length * 2;
|
||||
}
|
||||
|
||||
public int copyInto(byte[] buf, int offset) {
|
||||
public int copyInto(byte[] buf, int offset) throws IllegalArgumentException {
|
||||
ClassWriter.setUShort(buf, offset, attrID);
|
||||
ClassWriter.setInt(buf, offset + 2, 2 + rawTable.length * 2);
|
||||
ClassWriter.setUShort(buf, offset + 6, rawTable.length / 5);
|
||||
|
|
|
@ -15,45 +15,46 @@ import java.io.UnsupportedEncodingException;
|
|||
import com.ibm.wala.shrikeCT.ClassWriter;
|
||||
|
||||
public class SourceDebugExtensionWriter extends ClassWriter.Element {
|
||||
private int attrID;
|
||||
private byte[] table;
|
||||
|
||||
public SourceDebugExtensionWriter(ClassWriter w){
|
||||
attrID = w.addCPUtf8("SourceDebugExtension");
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return table == null ? 6 : 6 + table.length;
|
||||
}
|
||||
private int attrID;
|
||||
|
||||
public int copyInto(byte[] buf, int offset) {
|
||||
ClassWriter.setUShort(buf, offset, attrID);
|
||||
ClassWriter.setInt(buf, offset + 2, getSize() - 6);
|
||||
offset += 6;
|
||||
if (table != null) {
|
||||
for (int i = 0; i < table.length; i++) {
|
||||
ClassWriter.setUByte(buf, offset, table[i]);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setRawTable(byte[] sourceDebug){
|
||||
for(int i = 0; i < sourceDebug.length ; i++){
|
||||
if (sourceDebug[i] < 1 || sourceDebug[i] > 0xFFFF) {
|
||||
throw new IllegalArgumentException("Invalid CP index: " + sourceDebug[i]);
|
||||
}
|
||||
}
|
||||
this.table = sourceDebug;
|
||||
}
|
||||
private byte[] table;
|
||||
|
||||
public void setDebugInfo(String sourceDebug){
|
||||
try {
|
||||
byte[] bytes = sourceDebug.getBytes("UTF8");
|
||||
setRawTable(bytes);
|
||||
} catch (UnsupportedEncodingException e){
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
public SourceDebugExtensionWriter(ClassWriter w) {
|
||||
attrID = w.addCPUtf8("SourceDebugExtension");
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return table == null ? 6 : 6 + table.length;
|
||||
}
|
||||
|
||||
public int copyInto(byte[] buf, int offset) throws IllegalArgumentException {
|
||||
ClassWriter.setUShort(buf, offset, attrID);
|
||||
ClassWriter.setInt(buf, offset + 2, getSize() - 6);
|
||||
offset += 6;
|
||||
if (table != null) {
|
||||
for (int i = 0; i < table.length; i++) {
|
||||
ClassWriter.setUByte(buf, offset, table[i]);
|
||||
offset++;
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
public void setRawTable(byte[] sourceDebug) {
|
||||
for (int i = 0; i < sourceDebug.length; i++) {
|
||||
if (sourceDebug[i] < 1 || sourceDebug[i] > 0xFFFF) {
|
||||
throw new IllegalArgumentException("Invalid CP index: " + sourceDebug[i]);
|
||||
}
|
||||
}
|
||||
this.table = sourceDebug;
|
||||
}
|
||||
|
||||
public void setDebugInfo(String sourceDebug) {
|
||||
try {
|
||||
byte[] bytes = sourceDebug.getBytes("UTF8");
|
||||
setRawTable(bytes);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
System.err.println(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ public final class SourceFileWriter extends ClassWriter.Element {
|
|||
}
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
public int getSize() throws IllegalArgumentException {
|
||||
verify();
|
||||
return 8;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue