本文整理汇总了Java中edu.umd.cs.findbugs.ba.ClassContext.getMethodGen方法的典型用法代码示例。如果您正苦于以下问题:Java ClassContext.getMethodGen方法的具体用法?Java ClassContext.getMethodGen怎么用?Java ClassContext.getMethodGen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类edu.umd.cs.findbugs.ba.ClassContext
的用法示例。
在下文中一共展示了ClassContext.getMethodGen方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reportMatch
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
public void reportMatch(ClassContext classContext, Method method, ByteCodePatternMatch match) {
MethodGen methodGen = classContext.getMethodGen(method);
JavaClass javaClass = classContext.getJavaClass();
BindingSet bindingSet = match.getBindingSet();
// Note that the lookup of "h" cannot fail, and
// it is guaranteed to be bound to a FieldVariable.
Binding binding = bindingSet.lookup("h");
FieldVariable field = (FieldVariable) binding.getVariable();
// Ignore fields generated for accesses to Foo.class
if (field.getFieldName().startsWith("class$"))
return;
// Find start and end instructions (for reporting source lines)
InstructionHandle start = match.getLabeledInstruction("startDC");
InstructionHandle end = match.getLabeledInstruction("endDC");
String sourceFile = javaClass.getSourceFileName();
bugReporter.reportBug(new BugInstance(this, "BCPDC_DOUBLECHECK", NORMAL_PRIORITY)
.addClassAndMethod(methodGen, sourceFile)
.addField(field).describe("FIELD_ON")
.addSourceLine(methodGen, sourceFile, start, end));
}
示例2: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(m);
ConstantPoolGen cpg = classContext.getConstantPoolGen();
CFG cfg = classContext.getCFG(m);
if (methodGen == null || methodGen.getInstructionList() == null) {
return; //No instruction .. nothing to do
}
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
Location location = i.next();
Instruction inst = location.getHandle().getInstruction();
if (inst instanceof InvokeInstruction) {
InvokeInstruction invoke = (InvokeInstruction) inst;
String methodName = invoke.getMethodName(cpg);
if ("enableDefaultTyping".equals(methodName)) {
JavaClass clz = classContext.getJavaClass();
bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY)
.addClass(clz)
.addMethod(clz, m)
.addCalledMethod(cpg, invoke)
.addSourceLine(classContext, m, location)
);
}
}
}
}
示例3: visitClassContext
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
public void visitClassContext(ClassContext cc) {
JavaClass jc = cc.getJavaClass();
Method[] methods = jc.getMethods();
for (Method m : methods) {
MethodGen mg = cc.getMethodGen(m);
if (mg == null) {
continue;
}
try {
analyzeMethod(cc, m);
} catch (Exception e) {
// There was a problem,
// report it. Probably
// isn't going to
// be a big deal.
e.printStackTrace();
}
}
}
示例4: visitClassContext
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass javaClass = classContext.getJavaClass();
boolean keyStringField = false;
for (Field f : javaClass.getFields()) {
if (f.getName().equals("keyString")) { //The expected field name
keyStringField = true;
break;
}
}
if (!keyStringField) { //No key field identify
return;
}
//Class name left unchanged
if (javaClass.getClassName().contains("UrlSigner")) {
bugReporter.reportBug(new BugInstance(this, HARD_CODE_PASSWORD_TYPE, Priorities.NORMAL_PRIORITY) //
.addClass(javaClass).addField(new FieldVariable(javaClass.getClassName(), "keyString", "Ljava/lang/String;")));
return;
}
//Event if the class name was refactor, the method "signRequest" would probably be left.
for (Method m : javaClass.getMethods()) {
MethodGen methodGen = classContext.getMethodGen(m);
if (methodGen.getName().equals("signRequest")) {
bugReporter.reportBug(new BugInstance(this, HARD_CODE_PASSWORD_TYPE, Priorities.NORMAL_PRIORITY) //
.addClass(javaClass).addField(new FieldVariable(javaClass.getClassName(), "keyString", "")));
}
}
}
示例5: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(Method m, ClassContext classContext) throws CFGBuilderException, DataflowAnalysisException
{
MethodGen methodGen = classContext.getMethodGen(m);
ConstantPoolGen cpg = classContext.getConstantPoolGen();
CFG cfg = classContext.getCFG(m);
if (methodGen == null || methodGen.getInstructionList() == null) {
return; //No instruction .. nothing to do
}
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
Location location = i.next();
Instruction inst = location.getHandle().getInstruction();
//
if (inst instanceof InvokeInstruction) {
// System.out.println(inst.getName());
InvokeInstruction invoke = (InvokeInstruction) inst;
String className = invoke.getClassName(cpg);
if ("java.io.ObjectInputStream".equals(className) || className.contains("InputStream") || InterfaceUtils.isSubtype(className, "java.io.ObjectInputStream")) {
String methodName = invoke.getMethodName(cpg);
if (OBJECT_INPUTSTREAM_READ_METHODS.contains(methodName)) {
JavaClass clz = classContext.getJavaClass();
bugReporter.reportBug(new BugInstance(this, OBJECT_DESERIALIZATION_TYPE, HIGH_PRIORITY) //
.addClass(clz).addMethod(clz, m).addSourceLine(classContext,m,location));
}
}
}
}
}
示例6: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(JavaClass javaClass, Method m, ClassContext classContext) throws CFGBuilderException {
MethodGen methodGen = classContext.getMethodGen(m);
ConstantPoolGen cpg = classContext.getConstantPoolGen();
CFG cfg = classContext.getCFG(m);
if (methodGen == null || methodGen.getInstructionList() == null) {
bugReporter.reportBug(new BugInstance(this, WEBVIEW_RECEIVE_SSL_ERROR_TYPE, HIGH_PRIORITY)
.addClass(javaClass)
.addMethod(javaClass, m)
);
}
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {
Location location = i.next();
Instruction inst = location.getHandle().getInstruction();
if (inst instanceof INVOKEVIRTUAL) {
INVOKEVIRTUAL invoke = (INVOKEVIRTUAL) inst;
String methodName = invoke.getMethodName(cpg);
if ("proceed".equals(methodName)) {
bugReporter.reportBug(new BugInstance(this, WEBVIEW_RECEIVE_SSL_ERROR_TYPE, HIGH_PRIORITY)
.addClass(javaClass)
.addMethod(javaClass, m)
.addCalledMethod(cpg, invoke)
.addSourceLine(classContext, m, location)
);
}
break;
}
}
}
示例7: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws DataflowAnalysisException, CFGBuilderException
{
if (DEBUG || DEBUG_NULLARG)
System.out.println("Pre FND ");
MethodGen methodGen = classContext.getMethodGen(method);
if (methodGen == null)
return;
// UsagesRequiringNonNullValues uses =
// classContext.getUsagesRequiringNonNullValues(method);
this.method = method;
if (DEBUG || DEBUG_NULLARG)
System.out.println("FND: " + SignatureConverter.convertMethodSignature(methodGen));
findPreviouslyDeadBlocks();
vnaDataflow = classContext.getValueNumberDataflow(method);
// Create a NullDerefAndRedundantComparisonFinder object to do the
// actual
// work. It will call back to report null derefs and redundant null
// comparisons
// through the NullDerefAndRedundantComparisonCollector interface we
// implement.
NullDerefAndRedundantComparisonFinder worker = new NullDerefAndRedundantComparisonFinder(classContext, method, this);
worker.execute();
}
示例8: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(method);
CFG cfg = classContext.getCFG(method);
LockDataflow dataflow = classContext.getLockDataflow(method);
for (Iterator<Location> j = cfg.locationIterator(); j.hasNext();) {
Location location = j.next();
visitLocation(classContext, location, methodGen, dataflow);
}
}
示例9: considerMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void considerMethod(ClassContext classContext, Method method) {
if ((method.getReturnType() instanceof ReferenceType) && classContext.getMethodGen(method) != null) {
if (VERBOSE_DEBUG)
System.out.println("Check " + method);
analyzeMethod(classContext, method);
}
}
示例10: prescreen
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
@Override
public boolean prescreen(ClassContext classContext, Method method, boolean mightClose) {
if (!mightClose)
return false;
BitSet bytecodeSet = classContext.getBytecodeSet(method);
if (bytecodeSet == null)
return false;
MethodGen methodGen = classContext.getMethodGen(method);
return methodGen != null && methodGen.getName().toLowerCase().indexOf("lock") == -1
&& (bytecodeSet.get(Constants.INVOKEVIRTUAL) || bytecodeSet.get(Constants.INVOKEINTERFACE));
}
示例11: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
public void analyzeMethod(ClassContext classContext, Method method, ResourceTrackerType resourceTracker,
ResourceCollection<Resource> resourceCollection) throws CFGBuilderException, DataflowAnalysisException {
MethodGen methodGen = classContext.getMethodGen(method);
if (methodGen == null)
return;
try {
CFG cfg = classContext.getCFG(method);
DepthFirstSearch dfs = classContext.getDepthFirstSearch(method);
if (DEBUG)
System.out.println(SignatureConverter.convertMethodSignature(methodGen));
for (Iterator<Resource> i = resourceCollection.resourceIterator(); i.hasNext();) {
Resource resource = i.next();
ResourceValueAnalysis<Resource> analysis = new ResourceValueAnalysis<Resource>(methodGen, cfg, dfs,
resourceTracker, resource);
Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>> dataflow = new Dataflow<ResourceValueFrame, ResourceValueAnalysis<Resource>>(
cfg, analysis);
Profiler profiler = Global.getAnalysisCache().getProfiler();
profiler.start(resourceTracker.getClass());
try {
dataflow.execute();
} finally {
profiler.end(resourceTracker.getClass());
}
inspectResult(classContext, methodGen, cfg, dataflow, resource);
}
} catch (RuntimeException e) {
AnalysisContext.logError("Exception while analyzing " + methodGen.getClassName() + "." + methodGen.getName() + ":"
+ methodGen.getSignature(), e);
}
}
示例12: considerMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void considerMethod(ClassContext classContext, Method method) {
boolean hasReferenceParameters = false;
for (Type argument : method.getArgumentTypes())
if (argument instanceof ReferenceType) {
hasReferenceParameters = true;
}
if (hasReferenceParameters && classContext.getMethodGen(method) != null) {
if (VERBOSE_DEBUG)
System.out.println("Check " + method);
analyzeMethod(classContext, method);
}
}
示例13: reportMatch
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
public void reportMatch(ClassContext classContext, Method method, ByteCodePatternMatch match) {
MethodGen methodGen = classContext.getMethodGen(method);
JavaClass javaClass = classContext.getJavaClass();
InstructionHandle call = match.getLabeledInstruction("call");
// Ignore inner-class access methods
InvokeInstruction inv = (InvokeInstruction) call.getInstruction();
ConstantPoolGen cp = methodGen.getConstantPool();
String calledMethodName = inv.getMethodName(cp);
if (calledMethodName.startsWith("access$")
|| calledMethodName.startsWith("access+"))
return;
/*
System.out.println("Found " + calledMethodName);
System.out.println(inv.getSignature(cp));
System.out.println(inv.getClassName(cp));
*/
String calledMethodClass = inv.getClassName(cp);
if (inv.getSignature(cp).endsWith("V") && !calledMethodName.equals("<init>"))
return;
/*
if (calledMethodClass.equals(javaClass.getClassName()))
return;
*/
String sourceFile = javaClass.getSourceFileName();
/*
System.out.println("CalledMethodClass: " + calledMethodClass);
System.out.println("CalledMethodName: " + calledMethodName);
*/
int priority = NORMAL_PRIORITY;
if (calledMethodName.equals("createNewFile"))
priority = LOW_PRIORITY;
else if (calledMethodClass.startsWith("java.lang")
|| calledMethodClass.endsWith("Error")
|| calledMethodClass.endsWith("Exception"))
priority = HIGH_PRIORITY;
/*
String calledPackage = extractPackageName(calledMethodClass);
String callingPackage = extractPackageName(javaClass.getClassName());
if (calledPackage.length() > 0
&& callingPackage.length() > 0
&& (calledPackage.startsWith(callingPackage)
|| callingPackage.startsWith(calledPackage)))
priority++;
*/
// System.out.println("priority: " + priority);
bugReporter.reportBug(new BugInstance(this, "RV_RETURN_VALUE_IGNORED",
priority)
.addClassAndMethod(methodGen, sourceFile)
.addCalledMethod(methodGen, inv)
.addSourceLine(methodGen, sourceFile, call));
}
示例14: visitClassContext
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass javaClass = classContext.getJavaClass();
//The class extends X509TrustManager
boolean isTrustManager = InterfaceUtils.isSubtype(javaClass, "javax.net.ssl.X509TrustManager");
boolean isHostnameVerifier = InterfaceUtils.isSubtype(javaClass, "javax.net.ssl.HostnameVerifier");
//Not the target of this detector
// if (!isTrustManager && !isHostnameVerifier) return;
// if (!isTrustManager && !isHostnameVerifier){
// for (Method m : javaClass.getMethods()) {
// allow_All_Hostname_Verify(classContext, javaClass, m);
// }
// }
Method[] methodList = javaClass.getMethods();
for (Method m : methodList) {
MethodGen methodGen = classContext.getMethodGen(m);
if (DEBUG) System.out.println(">>> Method: " + m.getName());
if (isTrustManager &&
(m.getName().equals("checkClientTrusted") ||
m.getName().equals("checkServerTrusted"))){ //||
// m.getName().equals("getAcceptedIssuers"))) {
if(isEmptyImplementation(methodGen)) {
bugReporter.reportBug(new BugInstance(this, WEAK_TRUST_MANAGER_TYPE, Priorities.HIGH_PRIORITY) //
.addClassAndMethod(javaClass, m));
}
}
else if (isHostnameVerifier && m.getName().equals("verify")) {
if(isEmptyImplementation(methodGen)) {
bugReporter.reportBug(new BugInstance(this, WEAK_HOSTNAME_VERIFIER_TYPE, Priorities.NORMAL_PRIORITY) //
.addClassAndMethod(javaClass, m));
}
}else{
allow_All_Hostname_Verify(classContext, javaClass, m);
}
}
}
示例15: analyzeMethod
import edu.umd.cs.findbugs.ba.ClassContext; //导入方法依赖的package包/类
private void analyzeMethod(ClassContext cc, Method m) throws CFGBuilderException, DataflowAnalysisException {
JavaClass jc = cc.getJavaClass();
MethodGen mg = cc.getMethodGen(m);
if (mg == null) {
return;
}
ConstantPoolGen cpg = mg.getConstantPool();
CFG cfg = cc.getCFG(m);
ConstantDataflow df = cc.getConstantDataflow(m);
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location l = i.next();
Instruction ins = l.getHandle().getInstruction();
if (!(ins instanceof InvokeInstruction)) {
continue;
}
InvokeInstruction ii = (InvokeInstruction) ins;
MethodDescriptor md = new MethodDescriptor(ii, cpg);
// Skip this method if it's not on the list
if (!methodsToWatch.contains(md.toString()))
{
continue;
}
ConstantFrame cf = df.getFactAtLocation(l);
int numArgs = cf.getNumArguments(ii, cpg);
// If the function has 1 argument passed to it:
// This should always be true since the methods in the list
// only have one argument.
if (numArgs == 1) {
// Get the only constant value passed to the function
Constant val = cf.getStackValue(0);
// If the value is not a constant string
// (I know it is a String because the methodsToWatch list specifies argument type)
if (!val.isConstantString())
{
// Log and report
BugInstance bug = new BugInstance(this, "POSSIBLE_COMMAND_INJECTION", HIGH_PRIORITY);
bug.addClassAndMethod(mg, jc.getSourceFileName());
bugAccumulator.accumulateBug(bug, SourceLineAnnotation.fromVisitedInstruction(cc, mg, jc.getSourceFileName(), l.getHandle()));
}
}
}
bugAccumulator.reportAccumulatedBugs();
}