/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003, University of Maryland
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs.detect;

import java.util.*;
import org.apache.bcel.Constants;
import org.apache.bcel.classfile.*;
import org.apache.bcel.generic.*;
import edu.umd.cs.findbugs.*;
import edu.umd.cs.daveho.ba.*;
import edu.umd.cs.daveho.ba.bcp.*;

public class BCPMethodReturnCheck extends ByteCodePatternDetector {
	private BugReporter bugReporter;

	private static final ByteCodePattern pattern = new ByteCodePattern()
		.add(new MatchAny(new PatternElement[] {
			new Invoke("+java.io.InputStream", "read", "/^\\((\\[B|\\[BII)\\)I$", Invoke.INSTANCE),
			new Invoke("/^java.lang.(String|Byte|Boolean|Character|Short|Integer|Long|Float|Double)$", "/.*", "/.*", Invoke.ANY),
			new Invoke("+java.security.MessageDigest", "digest", "([B)[B", Invoke.INSTANCE)
		}).label("call"))
		.add(new Opcode(Constants.POP));

	public BCPMethodReturnCheck(BugReporter bugReporter) {
		this.bugReporter = bugReporter;
	}

	public ByteCodePattern getPattern() { return pattern; }

	public boolean prescreen(Method method, ClassContext classContext) {
		// Pre-screen for methods with a POP bytecode.
		// This gives us a 4X speedup.
		BitSet bytecodeSet = classContext.getBytecodeSet(method);
		return bytecodeSet.get(Constants.POP);
	}

	public void reportMatch(MethodGen methodGen, ByteCodePatternMatch match) {
		InstructionHandle call = match.getLabeledInstruction("call");

		bugReporter.reportBug(new BugInstance("RV_RETURN_VALUE_IGNORED", NORMAL_PRIORITY)
			.addClassAndMethod(methodGen)
			.addCalledMethod(methodGen, (InvokeInstruction) call.getInstruction())
			.addSourceLine(methodGen, call));
	}

}

// vim:ts=4

@@ -1420,13 +1420,17 @@
 java
+%5C%5C
 .lang
+%5C%5C
 .(St

Quote '.' characters in regexp for immutable java.lang classes.