Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * fb-contrib - Auxiliary detectors for Java programs
   * Copyright (C) 2005-2015 Dave Brosius
   *
   * 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 com.mebigfatguy.fbcontrib.detect;
 
 import java.util.Set;
 
 
 
looks for exceptions that are thrown with static strings as messages. Using static strings doesn't differentiate one use of this method versus another, and so it may be difficult to determine how this exception occurred without showing context.
 
 
 	private static JavaClass exceptionClass;
 	private static final Set<StringignorableExceptionTypes = new HashSet<String>();
 
 	static {
 		try {
 			 = Repository.lookupClass("java/lang/Exception");
 		} catch (ClassNotFoundException cnfe) {
 			 = null;
 		}
 
 		.add("java.lang.UnsupportedOperationException");
 	}
 
 	private final BugReporter bugReporter;
 	private OpcodeStack stack;

constructs a WEM detector given the reporter to report bugs on

Parameters:
bugReporter the sync of bug reports
 
 	public WeakExceptionMessaging(BugReporter bugReporter) {
 		this. = bugReporter;
 	}

overrides the visitor to initialize and tear down the opcode stack

Parameters:
classContext the context object of the currently parsed class
 
 	public void visitClassContext(ClassContext classContext) {
 		try {
 			if ( != null) {
 				 = new OpcodeStack();
 				super.visitClassContext(classContext);
 			}
 		} finally {
 			 = null;
 		}
 	}

looks for methods that contain a ATHROW opcodes

Parameters:
method the context object of the current method
Returns:
if the class uses throws
 
 	public boolean prescreen(Method method) {
		BitSet bytecodeSet = getClassContext().getBytecodeSet(method);
		return (bytecodeSet != null) && (bytecodeSet.get(.));
	}

overrides the visitor to prescreen the method to look for throws calls and only forward onto bytecode scanning if there

Parameters:
obj the context object of the currently parsed code block
	public void visitCode(Code obj) {
		Method method = getMethod();
		if (!method.getSignature().startsWith("()")) {
			if (prescreen(method)) {
				super.visitCode(obj);
			}
		}
	}

overrides the visitor to look for throws instructions using exceptions with static messages

Parameters:
seen the opcode of the currently visited instruction
	public void sawOpcode(int seen) {
		boolean allConstantStrings = false;
		boolean sawConstant = false;
		try {
	        .precomputation(this);
	        
			if (seen == ) {
				if (.getStackDepth() > 0) {
					if (item.getUserValue() != null) {
						JavaClass exClass = item.getJavaClass();
						if ((exClass == null) || !.contains(exClass.getClassName())) {
									   .addClass(this)
									   .addMethod(this)
									   .addSourceLine(this));
						}
					}
				}
else if ((seen == ) || (seen == )) {
					sawConstant = true;
else if (seen == ) {
					if (clsName.indexOf("Exception") >= 0) {
						JavaClass exCls = Repository.lookupClass(clsName);
						if (exCls.instanceOf()) {
							Type[] argTypes = Type.getArgumentTypes(sig);
							int stringParms = 0;
							for (int t = 0; t < argTypes.lengtht++) {
								if ("Ljava/lang/String;".equals(argTypes[t].getSignature())) {
									stringParms++;
									int stackOffset = argTypes.length - t - 1;
									if (.getStackDepth() > stackOffset) {
										OpcodeStack.Item item = .getStackItem(stackOffset);
										if (item.getUserValue() == null)
											return;
									}
								}
							}
							allConstantStrings = stringParms > 0;
						}
					}
				}
			}
catch (ClassNotFoundException cnfe) {
finally {
			TernaryPatcher.pre(seen);
			.sawOpcode(thisseen);
			TernaryPatcher.post(seen);
			if ((sawConstant || allConstantStrings) && (.getStackDepth() > 0)) {
			}
		}
	}
New to GrepCode? Check out our FAQ X