@Override public LockResourceTracker getResourceTracker(ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException { return new LockResourceTracker(bugReporter, classContext.getCFG(method), classContext.getValueNumberDataflow(method), classContext.getIsNullValueDataflow(method)); }
private Set<ValueNumber> getParameterValueNumbers(ClassContext classContext, Method method, CFG cfg) throws DataflowAnalysisException, CFGBuilderException { ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method); ValueNumberFrame vnaFrameAtEntry = vnaDataflow.getStartFact(cfg.getEntry()); Set<ValueNumber> paramValueNumberSet = new HashSet<>(); int firstParam = method.isStatic() ? 0 : 1; for (int i = firstParam; i < vnaFrameAtEntry.getNumLocals(); ++i) { paramValueNumberSet.add(vnaFrameAtEntry.getValue(i)); } return paramValueNumberSet; }
/** * Find set of blocks which were known to be dead before doing the null * pointer analysis. * * @return set of previously dead blocks, indexed by block id * @throws CFGBuilderException * @throws DataflowAnalysisException */ private BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderException { BitSet deadBlocks = new BitSet(); ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method); for (Iterator<BasicBlock> i = vnaDataflow.getCFG().blockIterator(); i.hasNext();) { BasicBlock block = i.next(); ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(block); if (vnaFrame.isTop()) { deadBlocks.set(block.getLabel()); } } return deadBlocks; }
/** * Constructor. * * @param pattern * the ByteCodePattern to look for examples of * @param classContext * ClassContext for the class to analyze * @param method * the Method to analyze */ public PatternMatcher(ByteCodePattern pattern, ClassContext classContext, Method method) throws CFGBuilderException, DataflowAnalysisException { this.pattern = pattern; this.cfg = classContext.getCFG(method); this.cpg = classContext.getConstantPoolGen(); this.dfs = classContext.getDepthFirstSearch(method); this.vnaDataflow = classContext.getValueNumberDataflow(method); this.domAnalysis = classContext.getNonExceptionDominatorsAnalysis(method); this.workList = new LinkedList<>(); this.visitedBlockMap = new IdentityHashMap<>(); this.resultList = new LinkedList<>(); }
/** * Find set of blocks which were known to be dead before doing the null * pointer analysis. * * @return set of previously dead blocks, indexed by block id * @throws CFGBuilderException * @throws DataflowAnalysisException */ private BitSet findPreviouslyDeadBlocks() throws DataflowAnalysisException, CFGBuilderException { BitSet deadBlocks = new BitSet(); ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method); for (Iterator<BasicBlock> i = vnaDataflow.getCFG().blockIterator(); i.hasNext();) { BasicBlock block = i.next(); ValueNumberFrame vnaFrame = vnaDataflow.getStartFact(block); if (vnaFrame.isTop()) { deadBlocks.set(block.getLabel()); } } return deadBlocks; }
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(); }
/** * @param classContext * @param method * @param location * @param stackPos * @throws DataflowAnalysisException * @throws CFGBuilderException */ static @CheckForNull public BugAnnotation getFromValueNumber(ClassContext classContext, Method method, Location location, int stackPos) throws DataflowAnalysisException, CFGBuilderException { ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); if (!vnaFrame.isValid()) { return null; } ValueNumber valueNumber = vnaFrame.getStackValue(stackPos); if (valueNumber.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT)) { return null; } BugAnnotation variableAnnotation = findAnnotationFromValueNumber(method, location, valueNumber, vnaFrame, "VALUE_OF"); return variableAnnotation; }
UselessValuesContext(ClassContext classContext, Method method) throws CheckedAnalysisException { this.classContext = classContext; this.method = method; cfg = classContext.getCFG(method); cpg = cfg.getMethodGen().getConstantPool(); ta = classContext.getTypeDataflow(method).getAnalysis(); vna = classContext.getValueNumberDataflow(method).getAnalysis(); }
/** * Execute dataflow analyses (only if required). * * @throws CheckedAnalysisException */ public void execute() throws CheckedAnalysisException { method = Global.getAnalysisCache().getMethodAnalysis(Method.class, methodDescriptor); ClassContext classContext = Global.getAnalysisCache().getClassAnalysis(ClassContext.class, methodDescriptor.getClassDescriptor()); BitSet bytecodeSet = classContext.getBytecodeSet(method); if (bytecodeSet == null) { return; } if (bytecodeSet.get(Const.MONITORENTER) || bytecodeSet.get(Const.MONITOREXIT)) { this.lockDataflow = classContext.getLockDataflow(method); } else if (method.isSynchronized()) { this.vnaDataflow = classContext.getValueNumberDataflow(method); // will // need // this // later } }
vnaDataflow = classContext.getValueNumberDataflow(method);
ValueNumberFrame vnaFrame = null; try { vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); } catch (DataflowAnalysisException e) { AnalysisContext.logError("error", e);
BugAnnotation getVariableAnnotation(Location location) { BugAnnotation variableAnnotation = null; try { // Get the value number ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); if (vnaFrame.isValid()) { Instruction ins = location.getHandle().getInstruction(); ValueNumber valueNumber = vnaFrame.getInstance(ins, classContext.getConstantPoolGen()); if (valueNumber.hasFlag(ValueNumber.CONSTANT_CLASS_OBJECT)) { return null; } variableAnnotation = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber, vnaFrame, "VALUE_OF"); } } catch (DataflowAnalysisException e) { // ignore } catch (CFGBuilderException e) { // ignore } return variableAnnotation; }
ValueNumberDataflow vnaDataflow = classContext.getValueNumberDataflow(method); ValueNumberFrame frame = vnaDataflow.getFactAtLocation(location);
public void dumpSimpleDataflowInformation(Method method) { try { dumpDataflowInformation(method, getCFG(method), getValueNumberDataflow(method), getIsNullValueDataflow(method), null, null); } catch (DataflowAnalysisException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } catch (CFGBuilderException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } }
ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); if (!vnaFrame.isValid()) { return;
this.vnaDataflow = classContext.getValueNumberDataflow(method); if (findGuaranteedDerefs) { if (DEBUG_DEREFS) {
public void dumpDataflowInformation(Method method) { try { dumpDataflowInformation(method, getCFG(method), getValueNumberDataflow(method), getIsNullValueDataflow(method), getUnconditionalValueDerefDataflow(method), getTypeDataflow(method)); } catch (DataflowAnalysisException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } catch (CFGBuilderException e) { AnalysisContext.logError( "Could not dump data information for " + getJavaClass().getClassName() + "." + method.getName(), e); } }
Instruction ins = location.getHandle().getInstruction(); try { ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); if (!vnaFrame.isValid()) { continue;
private void analyzeMethod(ClassContext classContext, Method method) throws DataflowAnalysisException, CFGBuilderException { JavaClass javaClass = classContext.getJavaClass(); ValueNumberDataflow vnd = classContext.getValueNumberDataflow(method);
private void examinePutfieldInstruction(Location location, PUTFIELD ins, ConstantPoolGen cpg) throws DataflowAnalysisException { IsNullValueFrame frame = invDataflow.getFactAtLocation(location); if (!frame.isValid()) { return; } IsNullValue tos = frame.getTopValue(); if (tos.isDefinitelyNull()) { XField field = XFactory.createXField(ins, cpg); NullnessAnnotation annotation = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase() .getResolvedAnnotation(field, false); if (annotation == NullnessAnnotation.NONNULL) { BugAnnotation variableAnnotation = null; try { ValueNumberFrame vnaFrame = classContext.getValueNumberDataflow(method).getFactAtLocation(location); ValueNumber valueNumber = vnaFrame.getTopValue(); variableAnnotation = ValueNumberSourceInfo.findAnnotationFromValueNumber(method, location, valueNumber, vnaFrame, "VALUE_OF"); } catch (DataflowAnalysisException e) { AnalysisContext.logError("error", e); } catch (CFGBuilderException e) { AnalysisContext.logError("error", e); } BugInstance warning = new BugInstance(this, "NP_STORE_INTO_NONNULL_FIELD", tos.isDefinitelyNull() ? HIGH_PRIORITY : NORMAL_PRIORITY).addClassAndMethod(classContext.getJavaClass(), method).addField(field) .addOptionalAnnotation(variableAnnotation).addSourceLine(classContext, method, location); bugReporter.reportBug(warning); } } }