本文整理汇总了Java中edu.umd.cs.findbugs.ba.Location.getHandle方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getHandle方法的具体用法?Java Location.getHandle怎么用?Java Location.getHandle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.findbugs.ba.Location
的用法示例。
在下文中一共展示了Location.getHandle方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateStringAppendState
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
private StringAppendState updateStringAppendState(Location location, ConstantPoolGen cpg, StringAppendState stringAppendState)
{
InstructionHandle handle = location.getHandle();
Instruction ins = handle.getInstruction();
if (!isConstantStringLoad(location, cpg)) {
throw new IllegalArgumentException("instruction must be LDC");
}
LDC load = (LDC) ins;
Object value = load.getValue(cpg);
String stringValue = ((String) value).trim();
if (stringValue.startsWith(",") || stringValue.endsWith(","))
stringAppendState.setSawComma(handle);
if (isCloseQuote(stringValue) && stringAppendState.getSawOpenQuote(handle))
stringAppendState.setSawCloseQuote(handle);
if (isOpenQuote(stringValue))
stringAppendState.setSawOpenQuote(handle);
return stringAppendState;
}
示例2: findLocalAnnotationFromValueNumber
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
public static LocalVariableAnnotation findLocalAnnotationFromValueNumber(Method method, Location location,
ValueNumber valueNumber, ValueNumberFrame vnaFrame) {
if (vnaFrame == null || vnaFrame.isBottom() || vnaFrame.isTop())
return null;
LocalVariableAnnotation localAnnotation = null;
for (int i = 0; i < vnaFrame.getNumLocals(); i++) {
if (valueNumber.equals(vnaFrame.getValue(i))) {
InstructionHandle handle = location.getHandle();
InstructionHandle prev = handle.getPrev();
if (prev == null)
continue;
int position1 = prev.getPosition();
int position2 = handle.getPosition();
localAnnotation = LocalVariableAnnotation.getLocalVariableAnnotation(method, i, position1, position2);
if (localAnnotation != null)
return localAnnotation;
}
}
return null;
}
示例3: matchLocation
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
private MatchResult matchLocation(Location location) throws DataflowAnalysisException {
// Get the ValueNumberFrames before and after the instruction
ValueNumberFrame before = vnaDataflow.getFactAtLocation(location);
ValueNumberFrame after = vnaDataflow.getFactAfterLocation(location);
// Try to match the instruction against the pattern element.
boolean debug = DEBUG && (!(patternElement instanceof Wild) || SHOW_WILD);
if (debug) {
debug((parentPath >= 0 ? parentPath + "->" : "") + path + ": Match " + patternElement + " against "
+ location.getHandle() + " " + (bindingSet != null ? bindingSet.toString() : "[]") + "...");
}
MatchResult matchResult = patternElement.match(location.getHandle(), cpg, before, after, bindingSet);
if (debug)
debug("\t" + ((matchResult != null) ? " ==> MATCH" : " ==> NOT A MATCH"));
if (matchResult != null) {
// Successful match!
// Update state to reflect that the match has occurred.
++matchCount;
canFork = true;
currentMatch = new PatternElementMatch(matchResult.getPatternElement(), location.getHandle(),
location.getBasicBlock(), matchCount, currentMatch);
bindingSet = matchResult.getBindingSet();
}
return matchResult;
}
示例4: getCookieInstructionLocation
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
/**
* This method is used to track calls made on a specific object. For instance, this could be used to track if "setHttpOnly(true)"
* was executed on a specific cookie object.
*
* This allows the detector to find interchanged calls like this
*
* Cookie cookie1 = new Cookie("f", "foo"); <- This cookie is unsafe
* Cookie cookie2 = new Cookie("b", "bar"); <- This cookie is safe
* cookie1.setHttpOnly(false);
* cookie2.setHttpOnly(true);
*
* @param cpg ConstantPoolGen
* @param startLocation The Location of the cookie initialization call.
* @param objectStackLocation The index of the cookie on the stack.
* @param invokeInstruction The instruction we want to detect.s
* @return The location of the invoke instruction provided for the cookie at a specific index on the stack.
*/
private Location getCookieInstructionLocation(ConstantPoolGen cpg, Location startLocation, int objectStackLocation, String invokeInstruction) {
Location location = startLocation;
InstructionHandle handle = location.getHandle();
int loadedStackValue = 0;
// Loop until we find the setSecure call for this cookie
while (handle.getNext() != null) {
handle = handle.getNext();
Instruction nextInst = handle.getInstruction();
// We check if the index of the cookie used for this invoke is the same as the one provided
if (nextInst instanceof ALOAD) {
ALOAD loadInst = (ALOAD)nextInst;
loadedStackValue = loadInst.getIndex();
}
if (nextInst instanceof INVOKEVIRTUAL
&& loadedStackValue == objectStackLocation) {
INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) nextInst;
String methodNameWithSignature = invoke.getClassName(cpg) + "." + invoke.getMethodName(cpg);
if (methodNameWithSignature.equals(invokeInstruction)) {
Integer val = ByteCode.getConstantInt(handle.getPrev());
if (val != null && val == TRUE_INT_VALUE) {
return new Location(handle, location.getBasicBlock());
}
}
}
}
return null;
}
示例5: getLocalVariableAnnotation
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
public static LocalVariableAnnotation getLocalVariableAnnotation(Method method, Location location, IndexedInstruction ins) {
int local = ins.getIndex();
InstructionHandle handle = location.getHandle();
int position1 = handle.getNext().getPosition();
int position2 = handle.getPosition();
return getLocalVariableAnnotation(method, local, position1, position2);
}
示例6: findLocation
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
@CheckForNull
Location findLocation(CFG cfg, InstructionHandle handle) {
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location loc = i.next();
if (loc.getHandle() == handle)
return loc;
}
return null;
}
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:10,代码来源:FindNullDerefsInvolvingNonShortCircuitEvaluation.java
示例7: inspectResult
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
@Override
public void inspectResult(ClassContext classContext, MethodGen methodGen, CFG cfg,
Dataflow<ResourceValueFrame, ResourceValueAnalysis<Lock>> dataflow, Lock resource) {
JavaClass javaClass = classContext.getJavaClass();
ResourceValueFrame exitFrame = dataflow.getResultFact(cfg.getExit());
if (DEBUG) {
System.out.println("Resource value at exit: " + exitFrame);
}
int exitStatus = exitFrame.getStatus();
if (exitStatus == ResourceValueFrame.OPEN || exitStatus == ResourceValueFrame.OPEN_ON_EXCEPTION_PATH) {
String bugType;
int priority;
if (exitStatus == ResourceValueFrame.OPEN) {
bugType = "UL_UNRELEASED_LOCK";
priority = HIGH_PRIORITY;
} else {
bugType = "UL_UNRELEASED_LOCK_EXCEPTION_PATH";
priority = NORMAL_PRIORITY;
}
String sourceFile = javaClass.getSourceFileName();
Location location = resource.getLocation();
InstructionHandle handle = location.getHandle();
InstructionHandle nextInstruction = handle.getNext();
if (nextInstruction.getInstruction() instanceof RETURN)
return; // don't report as error; intentional
bugAccumulator.accumulateBug(new BugInstance(this, bugType, priority).addClassAndMethod(methodGen, sourceFile),
SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle));
}
}
示例8: callToAssertionMethod
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
boolean callToAssertionMethod(Location loc) {
InstructionHandle h = loc.getHandle();
int firstPos = h.getPosition();
LineNumberTable ln = method.getLineNumberTable();
int firstLine = ln == null ? -1 : ln.getSourceLine(firstPos);
while (h != null) {
int pos = h.getPosition();
if (ln == null) {
if (pos > firstPos + 15)
break;
} else {
int line = ln.getSourceLine(pos);
if (line != firstLine)
break;
}
Instruction i = h.getInstruction();
if (i instanceof InvokeInstruction) {
InvokeInstruction ii = (InvokeInstruction) i;
String name = ii.getMethodName(classContext.getConstantPoolGen());
if (name.startsWith("check") || name.startsWith("assert"))
return true;
}
h = h.getNext();
}
return false;
}
示例9: analyzeMethod
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(method);
if (methodGen == null)
return;
ConstantPoolGen cpg = methodGen.getConstantPool();
CFG cfg = classContext.getCFG(method);
ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method);
LockDataflow dataflow = classContext.getLockDataflow(method);
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location location = i.next();
InstructionHandle handle = location.getHandle();
Instruction ins = handle.getInstruction();
if (!(ins instanceof INVOKEVIRTUAL))
continue;
INVOKEVIRTUAL inv = (INVOKEVIRTUAL) ins;
String methodName = inv.getName(cpg);
String methodSig = inv.getSignature(cpg);
if (Hierarchy.isMonitorWait(methodName, methodSig) || Hierarchy.isMonitorNotify(methodName, methodSig)) {
int numConsumed = inv.consumeStack(cpg);
if (numConsumed == Constants.UNPREDICTABLE)
throw new DataflowAnalysisException("Unpredictable stack consumption", methodGen, handle);
ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location);
if (!frame.isValid())
// Probably dead code
continue;
if (frame.getStackDepth() - numConsumed < 0)
throw new DataflowAnalysisException("Stack underflow", methodGen, handle);
ValueNumber ref = frame.getValue(frame.getNumSlots() - numConsumed);
LockSet lockSet = dataflow.getFactAtLocation(location);
int lockCount = lockSet.getLockCount(ref.getNumber());
if (lockCount == 0) {
Collection<ValueNumber> lockedValueNumbers = lockSet.getLockedValueNumbers(frame);
boolean foundMatch = false;
for (ValueNumber v : lockedValueNumbers)
if (frame.veryFuzzyMatch(ref, v)) {
foundMatch = true;
break;
}
if (!foundMatch) {
String type = methodName.equals("wait") ? "MWN_MISMATCHED_WAIT" : "MWN_MISMATCHED_NOTIFY";
String sourceFile = classContext.getJavaClass().getSourceFileName();
// Report as medium priority only if the method is
// public.
// Non-public methods may be properly locked in a
// calling context.
int priority = method.isPublic() ? NORMAL_PRIORITY : LOW_PRIORITY;
bugAccumulator.accumulateBug(
new BugInstance(this, type, priority).addClassAndMethod(methodGen, sourceFile),
SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle));
}
}
}
}
bugAccumulator.reportAccumulatedBugs();
}
示例10: transferInstruction
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
@Override
public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock) throws DataflowAnalysisException {
final Instruction ins = handle.getInstruction();
final ConstantPoolGen cpg = getCPG();
final ResourceValueFrame frame = getFrame();
int status = -1;
if (DEBUG)
System.out.println("PC : " + handle.getPosition() + " " + ins);
if (DEBUG && ins instanceof InvokeInstruction) {
InvokeInstruction iins = (InvokeInstruction) ins;
System.out.println(" " + ins.toString(cpg.getConstantPool()));
}
if (DEBUG)
System.out.println("resource frame before instruction: " + frame.toString());
// Is a lock acquired or released by this instruction?
Location creationPoint = lock.getLocation();
if (handle == creationPoint.getHandle() && basicBlock == creationPoint.getBasicBlock()) {
status = ResourceValueFrame.OPEN;
if (DEBUG)
System.out.println("OPEN");
} else if (resourceTracker.isResourceClose(basicBlock, handle, cpg, lock, frame)) {
status = ResourceValueFrame.CLOSED;
if (DEBUG)
System.out.println("CLOSE");
}
// Model use of instance values in frame slots
analyzeInstruction(ins);
final int updatedNumSlots = frame.getNumSlots();
// Mark any appearances of the lock value in the ResourceValueFrame.
ValueNumberFrame vnaFrame = vnaDataflow.getFactAfterLocation(new Location(handle, basicBlock));
if (DEBUG) {
System.out.println("vna frame after instruction: " + vnaFrame.toString());
System.out.println("Lock value number: " + lock.getLockValue());
if (lock.getLockValue().hasFlag(ValueNumber.RETURN_VALUE))
System.out.println("is return value");
}
for (int i = 0; i < updatedNumSlots; ++i) {
if (DEBUG) {
System.out.println("Slot " + i);
System.out.println(" Lock value number: " + vnaFrame.getValue(i));
if (vnaFrame.getValue(i).hasFlag(ValueNumber.RETURN_VALUE))
System.out.println(" is return value");
}
if (vnaFrame.fuzzyMatch(lock.getLockValue(), vnaFrame.getValue(i))) {
if (DEBUG)
System.out.println("Saw lock value!");
frame.setValue(i, ResourceValue.instance());
}
}
// If needed, update frame status
if (status != -1) {
frame.setStatus(status);
}
if (DEBUG)
System.out.println("resource frame after instruction: " + frame.toString());
}
示例11: analyzeMethod
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(method);
if (methodGen == null)
return;
BitSet bytecodeSet = classContext.getBytecodeSet(method);
if (bytecodeSet == null)
return;
// We don't adequately model instanceof interfaces yet
if (bytecodeSet.get(Constants.INSTANCEOF) || bytecodeSet.get(Constants.CHECKCAST))
return;
CFG cfg = classContext.getCFG(method);
TypeDataflow typeDataflow = classContext.getTypeDataflow(method);
ConstantPoolGen cpg = classContext.getConstantPoolGen();
String sourceFile = classContext.getJavaClass().getSourceFileName();
if (DEBUG) {
String methodName = methodGen.getClassName() + "." + methodGen.getName();
System.out.println("Checking " + methodName);
}
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location location = i.next();
InstructionHandle handle = location.getHandle();
Instruction ins = handle.getInstruction();
if (!(ins instanceof INVOKEINTERFACE))
continue;
INVOKEINTERFACE invoke = (INVOKEINTERFACE) ins;
String mName = invoke.getMethodName(cpg);
if (!mName.equals("setAttribute"))
continue;
String cName = invoke.getClassName(cpg);
if (!cName.equals("javax.servlet.http.HttpSession"))
continue;
TypeFrame frame = typeDataflow.getFactAtLocation(location);
if (!frame.isValid()) {
// This basic block is probably dead
continue;
}
Type operandType = frame.getTopValue();
if (operandType.equals(TopType.instance())) {
// unreachable
continue;
}
if (!(operandType instanceof ReferenceType)) {
// Shouldn't happen - illegal bytecode
continue;
}
ReferenceType refType = (ReferenceType) operandType;
if (refType.equals(NullType.instance())) {
continue;
}
try {
double isSerializable = DeepSubtypeAnalysis.isDeepSerializable(refType);
if (isSerializable < 0.9) {
SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.fromVisitedInstruction(classContext,
methodGen, sourceFile, handle);
ReferenceType problem = DeepSubtypeAnalysis.getLeastSerializableTypeComponent(refType);
bugAccumulator.accumulateBug(new BugInstance(this, "J2EE_STORE_OF_NON_SERIALIZABLE_OBJECT_INTO_SESSION",
isSerializable < 0.15 ? HIGH_PRIORITY : isSerializable > 0.5 ? LOW_PRIORITY : NORMAL_PRIORITY)
.addClassAndMethod(methodGen, sourceFile).addType(problem).describe(TypeAnnotation.FOUND_ROLE),
sourceLineAnnotation);
}
} catch (ClassNotFoundException e) {
// ignore
}
}
}
示例12: checkRefComparison
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
private void checkRefComparison(Location location, JavaClass jclass, Method method, MethodGen methodGen,
RefComparisonTypeFrameModelingVisitor visitor, TypeDataflow typeDataflow,
List<WarningWithProperties> stringComparisonList, List<WarningWithProperties> refComparisonList)
throws DataflowAnalysisException {
InstructionHandle handle = location.getHandle();
TypeFrame frame = typeDataflow.getFactAtLocation(location);
if (frame.getStackDepth() < 2) {
throw new DataflowAnalysisException("Stack underflow", methodGen, handle);
}
int numSlots = frame.getNumSlots();
Type lhsType = frame.getValue(numSlots - 2);
Type rhsType = frame.getValue(numSlots - 1);
if (lhsType instanceof NullType || rhsType instanceof NullType) {
return;
}
if (lhsType instanceof ReferenceType && rhsType instanceof ReferenceType) {
IncompatibleTypes result = IncompatibleTypes.getPriorityForAssumingCompatible(lhsType, rhsType, true);
if (result != IncompatibleTypes.SEEMS_OK && result != IncompatibleTypes.UNCHECKED) {
String sourceFile = jclass.getSourceFileName();
boolean isAssertSame = handle.getInstruction() instanceof INVOKESTATIC;
if (isAssertSame)
bugAccumulator.accumulateBug(
new BugInstance(this, "TESTING", result.getPriority())
.addClassAndMethod(methodGen, sourceFile)
.addString("Calling assertSame with two distinct objects")
.addFoundAndExpectedType(rhsType, lhsType)
.addSomeSourceForTopTwoStackValues(classContext, method, location),
SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle));
else
bugAccumulator.accumulateBug(
new BugInstance(this, "EC_UNRELATED_TYPES_USING_POINTER_EQUALITY", result.getPriority())
.addClassAndMethod(methodGen, sourceFile).addFoundAndExpectedType(rhsType, lhsType)
.addSomeSourceForTopTwoStackValues(classContext, method, location),
SourceLineAnnotation.fromVisitedInstruction(classContext, methodGen, sourceFile, handle));
return;
}
if (lhsType.equals(Type.OBJECT) && rhsType.equals(Type.OBJECT))
return;
String lhs = SignatureConverter.convert(lhsType.getSignature());
String rhs = SignatureConverter.convert(rhsType.getSignature());
if (lhs.equals("java.lang.String") || rhs.equals("java.lang.String")) {
handleStringComparison(jclass, method, methodGen, visitor, stringComparisonList, location, lhsType, rhsType);
} else if (suspiciousSet.contains(lhs)) {
handleSuspiciousRefComparison(jclass, method, methodGen, refComparisonList, location, lhs,
(ReferenceType) lhsType, (ReferenceType) rhsType);
} else if (suspiciousSet.contains(rhs)) {
handleSuspiciousRefComparison(jclass, method, methodGen, refComparisonList, location, rhs,
(ReferenceType) lhsType, (ReferenceType) rhsType);
}
}
}
示例13: transferInstruction
import edu.umd.cs.findbugs.ba.Location; //导入方法依赖的package包/类
@Override
public void transferInstruction(InstructionHandle handle, BasicBlock basicBlock) throws DataflowAnalysisException {
// Record what Location we are analyzing
this.location = new Location(handle, basicBlock);
final Instruction ins = handle.getInstruction();
final ResourceValueFrame frame = getFrame();
int status = -1;
boolean created = false;
// Is a resource created, opened, or closed by this instruction?
Location creationPoint = stream.getLocation();
if (handle == creationPoint.getHandle() && basicBlock == creationPoint.getBasicBlock()) {
// Resource creation
if (stream.isOpenOnCreation()) {
status = ResourceValueFrame.OPEN;
stream.setOpenLocation(location);
resourceTracker.addStreamOpenLocation(location, stream);
} else {
status = ResourceValueFrame.CREATED;
}
created = true;
} else if (resourceTracker.isResourceOpen(basicBlock, handle, cpg, stream, frame)) {
// Resource opened
status = ResourceValueFrame.OPEN;
stream.setOpenLocation(location);
resourceTracker.addStreamOpenLocation(location, stream);
} else if (resourceTracker.isResourceClose(basicBlock, handle, cpg, stream, frame)) {
// Resource closed
status = ResourceValueFrame.CLOSED;
}
// Model use of instance values in frame slots
analyzeInstruction(ins);
// If needed, update frame status
if (status != -1) {
frame.setStatus(status);
if (created)
frame.setValue(frame.getNumSlots() - 1, ResourceValue.instance());
}
}