use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class PartiallyConstructedObjectAccess method sawOpcode.
@Override
public void sawOpcode(int seen) {
try {
stack.precomputation(this);
if ((seen == Const.INVOKEVIRTUAL) || (seen == Const.INVOKEINTERFACE) || (seen == Const.INVOKESPECIAL)) {
int parmCount = SignatureUtils.getNumParameters(getSigConstantOperand());
if (stack.getStackDepth() > parmCount) {
OpcodeStack.Item itm = stack.getStackItem(parmCount);
if (itm.getRegisterNumber() == 0) {
JavaClass cls = itm.getJavaClass();
if (cls != null) {
Method m = findMethod(cls, getNameConstantOperand(), getSigConstantOperand());
if ((m != null) && (!m.isFinal())) {
if (isCtor && (seen != Const.INVOKESPECIAL)) {
bugReporter.reportBug(new BugInstance(this, BugType.PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, getPC()));
throw new StopOpcodeParsingException();
} else {
if (!Values.CONSTRUCTOR.equals(m.getName())) {
Map<Method, SourceLineAnnotation> calledMethods = methodToCalledMethods.get(getMethod());
calledMethods.put(m, SourceLineAnnotation.fromVisitedInstruction(this));
}
}
}
}
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
stack.sawOpcode(this, seen);
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class ModifyingUnmodifiableCollection method sawOpcode.
/**
* overrides the visitor to find method mutations on collections that have previously been determined to have been created as immutable collections
*
* @param seen
* the currently parsed opcode
*/
@Override
public void sawOpcode(int seen) {
ImmutabilityType imType = null;
try {
stack.precomputation(this);
switch(seen) {
case INVOKESTATIC:
case INVOKEINTERFACE:
case INVOKESPECIAL:
case INVOKEVIRTUAL:
{
String className = getClassConstantOperand();
String methodName = getNameConstantOperand();
String signature = getSigConstantOperand();
MethodInfo mi = Statistics.getStatistics().getMethodStatistics(className, methodName, signature);
imType = mi.getImmutabilityType();
if (seen == INVOKEINTERFACE) {
Integer collectionOffset = MODIFYING_METHODS.get(new QMethod(methodName, signature));
if ((collectionOffset != null) && CollectionUtils.isListSetMap(className) && (stack.getStackDepth() > collectionOffset.intValue())) {
OpcodeStack.Item item = stack.getStackItem(collectionOffset.intValue());
ImmutabilityType type = (ImmutabilityType) item.getUserValue();
if ((type == ImmutabilityType.IMMUTABLE) || ((type == ImmutabilityType.POSSIBLY_IMMUTABLE) && (reportedType != ImmutabilityType.POSSIBLY_IMMUTABLE))) {
bugReporter.reportBug(new BugInstance(this, BugType.MUC_MODIFYING_UNMODIFIABLE_COLLECTION.name(), (type == ImmutabilityType.IMMUTABLE) ? HIGH_PRIORITY : NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
if (type == ImmutabilityType.IMMUTABLE) {
throw new StopOpcodeParsingException();
}
reportedType = type;
}
}
}
}
break;
default:
break;
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
stack.sawOpcode(this, seen);
if ((imType != null) && (stack.getStackDepth() > 0)) {
OpcodeStack.Item item = stack.getStackItem(0);
item.setUserValue(imType);
}
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class UnusedParameter method visitCode.
/**
* implements the visitor to clear the parm set, and check for potential methods
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
unusedParms.clear();
regToParm.clear();
stack.resetForMethodEntry(this);
Method m = getMethod();
String methodName = m.getName();
if (IGNORE_METHODS.contains(methodName)) {
return;
}
int accessFlags = m.getAccessFlags();
if (((accessFlags & (Const.ACC_STATIC | Const.ACC_PRIVATE)) == 0) || ((accessFlags & Const.ACC_SYNTHETIC) != 0)) {
return;
}
List<String> parmTypes = SignatureUtils.getParameterSignatures(m.getSignature());
if (parmTypes.isEmpty()) {
return;
}
int firstReg = 0;
if ((accessFlags & Const.ACC_STATIC) == 0) {
++firstReg;
}
int reg = firstReg;
for (int i = 0; i < parmTypes.size(); ++i) {
unusedParms.set(reg);
regToParm.put(Integer.valueOf(reg), Integer.valueOf(i + 1));
String parmSig = parmTypes.get(i);
reg += SignatureUtils.getSignatureSize(parmSig);
}
try {
super.visitCode(obj);
if (!unusedParms.isEmpty()) {
LocalVariableTable lvt = m.getLocalVariableTable();
reg = unusedParms.nextSetBit(firstReg);
while (reg >= 0) {
LocalVariable lv = (lvt == null) ? null : lvt.getLocalVariable(reg, 0);
if (lv != null) {
String parmName = lv.getName();
bugReporter.reportBug(new BugInstance(this, BugType.UP_UNUSED_PARAMETER.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addString("Parameter " + regToParm.get(Integer.valueOf(reg)) + ": " + parmName));
}
reg = unusedParms.nextSetBit(reg + 1);
}
}
} catch (StopOpcodeParsingException e) {
// no unusedParms left
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class DubiousMapCollection method sawOpcode.
@Override
public void sawOpcode(int seen) {
try {
if (getPC() >= ternaryTarget) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item itm = stack.getStackItem(0);
XField xf = itm.getXField();
if (xf != null) {
itm.setUserValue(ternaryAccessedField);
}
}
ternaryAccessedField = null;
ternaryTarget = -1;
}
if ((seen == Const.INVOKEINTERFACE) || (seen == Const.INVOKEVIRTUAL)) {
processNormalInvoke();
processMethodCall();
} else if ((seen == Const.INVOKESPECIAL) || (seen == Const.INVOKESTATIC) || (seen == Const.INVOKEDYNAMIC)) {
processMethodCall();
} else if ((seen == Const.ARETURN) || (OpcodeUtils.isAStore(seen))) {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
removeField(item);
}
} else if ((seen == Const.PUTFIELD) || (seen == Const.PUTSTATIC)) {
XField xf = getXFieldOperand();
if (xf != null) {
if (!isInSpecial) {
mapFields.remove(xf.getName());
} else {
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
if (item.getRegisterNumber() >= 0) {
removeField(item);
}
}
}
if (mapFields.isEmpty()) {
throw new StopOpcodeParsingException();
}
}
} else if ((seen == Const.GOTO) || (seen == Const.GOTO_W)) {
if ((getBranchOffset() > 0) && (stack.getStackDepth() > 0)) {
OpcodeStack.Item itm = stack.getStackItem(0);
ternaryAccessedField = itm.getXField();
if (ternaryAccessedField != null) {
ternaryTarget = getBranchTarget();
}
}
}
} finally {
stack.sawOpcode(this, seen);
}
}
use of com.mebigfatguy.fbcontrib.utils.StopOpcodeParsingException in project fb-contrib by mebigfatguy.
the class DubiousMapCollection method removeField.
/*
* removes a potential field that was accessed from the map fields if this field
* was retrieved from a ternary, the user value will hold the first variable,
* and that will be removed too.
*
* @param itm the stack item that may potentially be a map field to remove as it
* is used like a map
*/
private void removeField(OpcodeStack.Item itm) {
XField xf = itm.getXField();
if (xf != null) {
mapFields.remove(xf.getName());
xf = (XField) itm.getUserValue();
if (xf != null) {
mapFields.remove(xf.getName());
}
if (mapFields.isEmpty()) {
throw new StopOpcodeParsingException();
}
}
}
Aggregations