BugInstance bugInstance = new BugInstance(this, "DLS_DEAD_LOCAL_STORE", priority) .addClassAndMethod(methodGen, javaClass.getSourceFileName()) .addSourceLine(methodGen, javaClass.getSourceFileName(), location.getHandle()); if (DEBUG) System.out.println("Reporting " + bugInstance);  bugReporter.reportBug(bugInstance);
if (reportWarning()) {   BugInstance bugInstance = new BugInstance(this, "DLS_DEAD_LOCAL_STORE", priority) .addClassAndMethod(methodGen, javaClass.getSourceFileName()) .addSourceLine(methodGen, javaClass.getSourceFileName(), location.getHandle()); if (DEBUG) System.out.println("Reporting " + bugInstance);  bugReporter.reportBug(bugInstance); }
	private void analyzeMethod(ClassContext classContext, Method method)		throws DataflowAnalysisException, CFGBuilderException {		JavaClass javaClass = classContext.getJavaClass();		Dataflow<BitSet, LiveLocalStoreAnalysis> llsaDataflow =			classContext.getLiveLocalStoreDataflow(method);		int numLocals = method.getCode().getMaxLocals();		int [] localUpdateCount = new int[numLocals];		int [] localLoadCount = new int[numLocals];		int [] localIncrementCount = new int[numLocals];		MethodGen methodGen = classContext.getMethodGen(method);		CFG cfg = classContext.getCFG(method);		BitSet liveStoreSetAtEntry = llsaDataflow.getAnalysis().getResultFact(cfg.getEntry());		BitSet complainedAbout = new BitSet();        // Get the local variable table from the method...        LocalVariableTable lvt = method.getLocalVariableTable();        		// Get number of locals that are parameters.		int localsThatAreParameters = method.getArgumentTypes().length;		if (!method.isStatic()) localsThatAreParameters++;				// Map to store properties used for false-positive heuristics		TreeMap<String, String> propertyMap = new TreeMap<String, String>();        		// Scan method to determine number of loads, stores, and increments		// of local variables.		for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {			Location location = i.next();						// Skip exception handlers, as the exception value is			// often a dead store.			if (location.getBasicBlock().isExceptionHandler())				continue;			boolean isStore = isStore(location);			boolean isLoad = isLoad(location);			if (!isStore && !isLoad)				continue;						IndexedInstruction ins = (IndexedInstruction) location.getHandle().getInstruction();			int local = ins.getIndex();			if (ins instanceof IINC) {				localUpdateCount[local]++;				localLoadCount[local]++;				localIncrementCount[local]++;			} else if (isStore) 				localUpdateCount[local]++;			else 				localLoadCount[local]++;		}		// Scan method for		// - dead stores		// - stores to parameters that are dead upon entry to the method		for (Iterator<Location> i = cfg.locationIterator(); i.hasNext(); ) {			Location location = i.next();					// Skip any instruction which is not a store			if (!isStore(location))				continue;			// Ignore exception handler blocks:			// javac always stores caught exceptions in			// a local, even if the value is not used.			if (location.getBasicBlock().isExceptionHandler())				continue;						// Clear properties for false-positive heuristics			propertyMap.clear();			InstructionHandle handle = location.getHandle();			IndexedInstruction ins = (IndexedInstruction) handle.getInstruction();			int pc = handle.getPosition();			int local = ins.getIndex();     			// Get local variable name.			// This may serve as a heuristic to avoid false warnings.            if (lvt != null) {            	LocalVariable lv = lvt.getLocalVariable(local, pc);            	if (lv != null) {					String localName = lv.getName();					propertyMap.put(BugProperty.LOCAL_NAME, localName);   	                // Is it in our set of excluded names?	                if (DO_EXCLUDE_LOCALS && EXCLUDED_LOCALS.contains(localName)) {	                    continue;	                }            	}            }			// Is this a store to a parameter which was dead on entry to the method?			boolean parameterThatIsDeadAtEntry = local < localsThatAreParameters			    && !llsaDataflow.getAnalysis().isStoreAlive(liveStoreSetAtEntry, local);			if (parameterThatIsDeadAtEntry && !complainedAbout.get(local)) {				BugInstance bugInstance = new BugInstance(this, "IP_PARAMETER_IS_DEAD_BUT_OVERWRITTEN", NORMAL_PRIORITY)					.addClassAndMethod(methodGen, javaClass.getSourceFileName())					.addSourceLine(methodGen, javaClass.getSourceFileName(), location.getHandle());//				if (localName != null)//					bugInstance.setProperty(BugProperty.LOCAL_NAME, localName);				bugReporter.reportBug(bugInstance);				complainedAbout.set(local);			}			// Get live stores at this instruction.			// Note that the analysis also computes which stores were			// killed by a subsequent unconditional store.			BitSet liveStoreSet = llsaDataflow.getAnalysis().getFactAtLocation(location);			// Is store alive?			if (llsaDataflow.getAnalysis().isStoreAlive(liveStoreSet, local))				continue;			// Store is dead			// Ignore assignments that were killed by a subsequent assignment.			if (llsaDataflow.getAnalysis().killedByStore(liveStoreSet, local)) {				if (DEBUG) {					System.out.println("Store at " + location.getHandle() +						" killed by subsequent store");				}				propertyMap.put(BugProperty.KILLED_BY_SUBSEQUENT_STORE, "true");				continue; // FIXME - bail early, or collect all props and report? Need to think about			} else {				propertyMap.put(BugProperty.KILLED_BY_SUBSEQUENT_STORE, "false");			}			// Ignore dead assignments of null and 0.			// These often indicate defensive programming.			InstructionHandle prev = location.getBasicBlock().getPredecessorOf(location.getHandle());			if (prev != null && defensiveConstantValueOpcodes.get(prev.getInstruction().getOpcode())) {				propertyMap.put(BugProperty.DEFENSIVE_CONSTANT_OPCODE, "true");				continue; // FIXME - bail early, or collect all props and report? Need to think about			} else {				propertyMap.put(BugProperty.DEFENSIVE_CONSTANT_OPCODE, "false");			}			int priority = LOW_PRIORITY;			// special handling of IINC			if (ins instanceof IINC) {								 if (localIncrementCount[local] == 1) 					priority = NORMAL_PRIORITY;				else continue;				}			else if (ins instanceof ASTORE				&& prev != null) { 				Instruction prevIns = prev.getInstruction();				if ((prevIns instanceof INVOKESPECIAL &&					((INVOKESPECIAL)prevIns).getMethodName(methodGen.getConstantPool()).equals("<init>"))				    || prevIns instanceof ANEWARRAY				    || prevIns instanceof NEWARRAY				    || prevIns instanceof MULTIANEWARRAY)					priority--;			}			else if (localUpdateCount[local] == 2				&& localLoadCount[local] > 0) priority--; // raise priority			else if (localUpdateCount[local] == 1)				priority++;			else if (localLoadCount[local] == 0) priority++; // lower priority			if (parameterThatIsDeadAtEntry) {				if (DEBUG) System.out.println("Raising priority");				priority--;				}			if (priority < HIGH_PRIORITY)				priority =  HIGH_PRIORITY;			if (DEBUG) System.out.println(" considering reporting bug:" + priority);			if (priority != LOW_PRIORITY 				|| classesAlreadyReportedOn.add(javaClass.getClassName())) {			// Report the bug			BugInstance bugInstance = new BugInstance(this, "DLS_DEAD_LOCAL_STORE", priority)				.addClassAndMethod(methodGen, javaClass.getSourceFileName())				.addSourceLine(methodGen, javaClass.getSourceFileName(), location.getHandle());			if (DEBUG) System.out.println("Reporting " + bugInstance);			bugReporter.reportBug(bugInstance);			}		}	}