| 1 19 20 package edu.umd.cs.findbugs.ba.npe2; 21 22 import org.apache.bcel.Constants; 23 24 import edu.umd.cs.findbugs.ba.DataflowAnalysisException; 25 import edu.umd.cs.findbugs.ba.Edge; 26 import edu.umd.cs.findbugs.ba.EdgeTypes; 27 import edu.umd.cs.findbugs.ba.Location; 28 import edu.umd.cs.findbugs.ba.vna.ValueNumber; 29 import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame; 30 31 34 public class IfNullCondition extends Condition { 35 private ValueNumber valueNumber; 36 private Decision ifcmpDecision; 37 private Decision fallThroughDecision; 38 39 public IfNullCondition(Location location) { 40 super(location); 41 } 42 43 46 @Override  47 public Decision getDecision(Edge edge) { 48 return edge.getType() == EdgeTypes.IFCMP_EDGE ? ifcmpDecision : fallThroughDecision; 49 } 50 51 54 @Override  55 public ValueNumber getValueNumber() { 56 return valueNumber; 57 } 58 59 62 @Override  63 public void refresh(ValueNumberFrame vnaFrame, DefinitelyNullSet definitelyNullSet) throws DataflowAnalysisException { 64 valueNumber = vnaFrame.getTopValue(); 65 66 NullnessValue nullnessValue = definitelyNullSet.getNulllessValue(valueNumber); 67 short opcode = getLocation().getHandle().getInstruction().getOpcode(); 68 69 if (nullnessValue.isDefinitelyNull() || nullnessValue.isDefinitelyNotNull()) { 70 72 boolean ifcmpFeasible = nullnessValue.isDefinitelyNull() == (opcode == Constants.IFNULL); 73 ifcmpDecision = new Decision( 74 ifcmpFeasible, 75 ifcmpFeasible ? nullnessValue.toCheckedValue() : null 76 ); 77 78 boolean fallThroughFeasible = nullnessValue.isDefinitelyNull() != (opcode == Constants.IFNONNULL); 79 fallThroughDecision = new Decision( 80 fallThroughFeasible, 81 fallThroughFeasible ? nullnessValue.toCheckedValue() : null 82 ); 83 84 return; 85 } 86 87 NullnessValue definitelyNull = NullnessValue.definitelyNullValue().toCheckedValue(); 88 NullnessValue definitelyNotNull = NullnessValue.definitelyNotNullValue().toCheckedValue(); 89 90 ifcmpDecision = new Decision( 92 true, 93 (opcode == Constants.IFNULL) ? definitelyNull : definitelyNotNull 94 ); 95 fallThroughDecision = new Decision( 96 true, 97 (opcode == Constants.IFNULL) ? definitelyNotNull : definitelyNull 98 ); 99 } 100 } 101 | Popular Tags |