.getUnconditionalDerefParamDatabase();
Iterator<BasicBlock> bbIter = cfg.blockIterator();
ConstantPoolGen cpg = classContext.getConstantPoolGen();
ValueNumber valueNumberForThis = null;
if (!method.isStatic()) {
ValueNumberFrame frameAtEntry = vna.getStartFact(cfg.getEntry());
valueNumberForThis = frameAtEntry.getValue(0);
}
NullnessAnnotation methodAnnotation = getMethodNullnessAnnotation(classContext, method);
while (bbIter.hasNext()) {
BasicBlock basicBlock = bbIter.next();
if (basicBlock.isNullCheck()) {
InstructionHandle exceptionThrowerHandle = basicBlock.getExceptionThrower();
Instruction exceptionThrower = exceptionThrowerHandle.getInstruction();
ValueNumberFrame vnaFrame = vna.getStartFact(basicBlock);
if (!vnaFrame.isValid()) {
continue;
}
ValueNumber valueNumber = vnaFrame.getInstance(exceptionThrower, cpg);
Location location = new Location(exceptionThrowerHandle, basicBlock);
if (valueNumberForThis != valueNumber) {
derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getPointerDereference());
}
}
}
for (Iterator<Location> i = cfg.locationIterator(); i.hasNext();) {
Location location = i.next();
InstructionHandle handle = location.getHandle();
Instruction ins = handle.getInstruction();
ValueNumberFrame valueNumberFrame = vna.getFactAtLocation(location);
TypeFrame typeFrame = typeDataflow.getFactAtLocation(location);
if (ins instanceof InvokeInstruction) {
InvokeInstruction inv = (InvokeInstruction) ins;
XMethod m = XFactory.createXMethod(inv, cpg);
SignatureParser sigParser = new SignatureParser(m.getSignature());
int numParams = sigParser.getNumParameters();
// Check nonnull annotations
for (int j = 0; j < numParams; j++) {
if (db.parameterMustBeNonNull(m, j)) {
int slot = sigParser.getSlotsFromTopOfStackForParameter(j);
ValueNumber valueNumber = valueNumberFrame.getStackValue(slot);
if (valueNumberForThis != valueNumber) {
derefs.add(location, valueNumber,
PointerUsageRequiringNonNullValue.getPassedAsNonNullParameter(m, j));
}
}
}
// Check actual targets
try {
Set<JavaClassAndMethod> targetMethodSet = Hierarchy.resolveMethodCallTargets(inv, typeFrame, cpg);
BitSet unconditionallyDereferencedNullArgSet = null;
for (JavaClassAndMethod targetMethod : targetMethodSet) {
ParameterProperty property = unconditionalDerefParamDatabase.getProperty(targetMethod
.toMethodDescriptor());
if (property == null) {
unconditionallyDereferencedNullArgSet = null;
break;
}
BitSet foo = property.getAsBitSet();
if (unconditionallyDereferencedNullArgSet == null) {
unconditionallyDereferencedNullArgSet = foo;
} else {
unconditionallyDereferencedNullArgSet.intersects(foo);
}
if (unconditionallyDereferencedNullArgSet.isEmpty()) {
break;
}
}
if (unconditionallyDereferencedNullArgSet != null && !unconditionallyDereferencedNullArgSet.isEmpty()
&& valueNumberFrame.isValid()) {
for (int j = unconditionallyDereferencedNullArgSet.nextSetBit(0); j >= 0; j = unconditionallyDereferencedNullArgSet
.nextSetBit(j + 1)) {
int slot = sigParser.getSlotsFromTopOfStackForParameter(j);
ValueNumber valueNumber = valueNumberFrame.getStackValue(slot);
if (valueNumberForThis != valueNumber) {
derefs.add(location, valueNumber,
PointerUsageRequiringNonNullValue.getPassedAsNonNullParameter(m, j));
}
}
}
} catch (ClassNotFoundException e) {
AnalysisContext.reportMissingClass(e);
}
} else if (ins instanceof IFNONNULL && UnconditionalValueDerefAnalysis.isNullCheck(handle, cpg)) {
ValueNumber valueNumber = valueNumberFrame.getTopValue();
derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getPointerNullChecked());
} else if (ins instanceof ARETURN && methodAnnotation == NullnessAnnotation.NONNULL) {
ValueNumber valueNumber = valueNumberFrame.getTopValue();
if (valueNumberForThis != valueNumber) {
derefs.add(location, valueNumber,
PointerUsageRequiringNonNullValue.getReturnFromNonNullMethod(thisMethod));
}
} else if (ins instanceof PUTFIELD || ins instanceof PUTSTATIC) {
FieldInstruction inf = (FieldInstruction) ins;
XField field = XFactory.createXField(inf, cpg);
NullnessAnnotation annotation = AnalysisContext.currentAnalysisContext().getNullnessAnnotationDatabase()
.getResolvedAnnotation(field, false);
if (annotation == NullnessAnnotation.NONNULL) {
ValueNumber valueNumber = valueNumberFrame.getTopValue();
if (valueNumberForThis != valueNumber) {
derefs.add(location, valueNumber, PointerUsageRequiringNonNullValue.getStoredIntoNonNullField(field));
}
}