本文整理汇总了Java中org.apache.bcel.Constants.IF_ACMPNE属性的典型用法代码示例。如果您正苦于以下问题:Java Constants.IF_ACMPNE属性的具体用法?Java Constants.IF_ACMPNE怎么用?Java Constants.IF_ACMPNE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.bcel.Constants
的用法示例。
在下文中一共展示了Constants.IF_ACMPNE属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: analyzeMethod
private void analyzeMethod(ClassContext classContext, Method method)
throws CFGBuilderException, DataflowAnalysisException {
boolean sawCallToEquals = false;
JavaClass jclass = classContext.getJavaClass();
ConstantPoolGen cpg = classContext.getConstantPoolGen();
MethodGen methodGen = classContext.getMethodGen(method);
// Report at most one String comparison per method.
// We report the first highest priority warning.
stringComparison = null;
refComparison = null;
CFG cfg = classContext.getCFG(method);
DepthFirstSearch dfs = classContext.getDepthFirstSearch(method);
ExceptionSetFactory exceptionSetFactory =
classContext.getExceptionSetFactory(method);
// Perform type analysis using our special type merger
// (which handles String types specially, keeping track of
// which ones appear to be dynamically created)
RefComparisonTypeMerger typeMerger =
new RefComparisonTypeMerger(bugReporter, exceptionSetFactory);
TypeFrameModelingVisitor visitor =
new RefComparisonTypeFrameModelingVisitor(methodGen.getConstantPool(), bugReporter);
TypeAnalysis typeAnalysis =
new TypeAnalysis(methodGen, cfg, dfs, typeMerger, visitor, bugReporter, exceptionSetFactory);
TypeDataflow typeDataflow = new TypeDataflow(cfg, typeAnalysis);
typeDataflow.execute();
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location location = i.next();
Instruction ins = location.getHandle().getInstruction();
short opcode = ins.getOpcode();
if (opcode == Constants.IF_ACMPEQ || opcode == Constants.IF_ACMPNE) {
checkRefComparison(location, jclass, methodGen, typeDataflow);
} else if (invokeInstanceSet.get(opcode)) {
InvokeInstruction inv = (InvokeInstruction) ins;
String methodName = inv.getMethodName(cpg);
String methodSig = inv.getSignature(cpg);
if ((methodName.equals("equals") && methodSig.equals("(Ljava/lang/Object;)Z"))
|| (methodName.equals("equalIgnoreCases") && methodSig.equals("(Ljava/lang/String;)Z"))) {
sawCallToEquals = true;
checkEqualsComparison(location, jclass, methodGen, typeDataflow);
}
}
}
// If a String reference comparison was found in the method,
// report it
if (stringComparison != null) {
if (sawCallToEquals &&
stringComparison.getPriority() >= NORMAL_PRIORITY) {
// System.out.println("Reducing priority of " + stringComparison);
stringComparison.setPriority(1 + stringComparison.getPriority());
}
if (stringComparison.getPriority() >= NORMAL_PRIORITY
&& !(method.isPublic() ||
method.isProtected())) {
// System.out.print("private/packed");
stringComparison.setPriority(1 + stringComparison.getPriority());
}
if (stringComparison.getPriority() <= LOW_PRIORITY) {
bugReporter.reportBug(stringComparison);
}
}
if (refComparison != null) {
if (false && sawCallToEquals) {
// System.out.println("Reducing priority of " + refComparison);
refComparison.setPriority(1 + refComparison.getPriority());
}
if (refComparison.getPriority() <= LOW_PRIORITY)
bugReporter.reportBug(refComparison);
}
}
示例2: analyzeMethod
private void analyzeMethod(ClassContext classContext, Method method)
throws CFGBuilderException, DataflowAnalysisException {
if (DEBUG) System.out.println("Clearing redundant branch information");
redundantBranchList.clear();
definitelySameBranchSet.clear();
definitelyDifferentBranchSet.clear();
undeterminedBranchSet.clear();
if (DEBUG)
System.out.println(SignatureConverter.convertMethodSignature(classContext.getMethodGen(method)));
// Get the IsNullValueAnalysis for the method from the ClassContext
IsNullValueDataflow invDataflow = classContext.getIsNullValueDataflow(method);
// Look for null check blocks where the reference being checked
// is definitely null, or null on some path
Iterator<BasicBlock> bbIter = invDataflow.getCFG().blockIterator();
while (bbIter.hasNext()) {
BasicBlock basicBlock = bbIter.next();
if (basicBlock.isNullCheck()) {
analyzeNullCheck(classContext, method, invDataflow, basicBlock);
} else if (!basicBlock.isEmpty()) {
// Look for all reference comparisons where
// - both values compared are definitely null, or
// - one value is definitely null and one is definitely not null
// These cases are not null dereferences,
// but they are quite likely to indicate an error, so while we've got
// information about null values, we may as well report them.
InstructionHandle lastHandle = basicBlock.getLastInstruction();
Instruction last = lastHandle.getInstruction();
switch (last.getOpcode()) {
case Constants.IF_ACMPEQ:
case Constants.IF_ACMPNE:
analyzeRefComparisonBranch(method, invDataflow, basicBlock, lastHandle);
break;
case Constants.IFNULL:
case Constants.IFNONNULL:
analyzeIfNullBranch(method, invDataflow, basicBlock, lastHandle);
break;
}
}
}
Iterator<RedundantBranch> i = redundantBranchList.iterator();
while (i.hasNext()) {
RedundantBranch redundantBranch = i.next();
if (DEBUG) System.out.println("Redundant branch: " + redundantBranch);
InstructionHandle handle = redundantBranch.handle;
int lineNumber = redundantBranch.lineNumber;
// The source to bytecode compiler may sometimes duplicate blocks of
// code along different control paths. So, to report the bug,
// we check to ensure that the branch is REALLY determined each
// place it is duplicated, and that it is determined in the same way.
if (!undeterminedBranchSet.get(lineNumber) &&
!(definitelySameBranchSet.get(lineNumber) && definitelyDifferentBranchSet.get(lineNumber))) {
reportRedundantNullCheck(classContext, method, handle, redundantBranch);
}
}
}