[Fb-contrib-commit] SF.net SVN: fb-contrib:[1533] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/d
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-04-04 07:59:46
|
Revision: 1533
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1533&view=rev
Author: dbrosius
Date: 2010-04-04 07:59:40 +0000 (Sun, 04 Apr 2010)
Log Message:
-----------
updates to MDM by Jean-Noel Rouvignac, Thanks!
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MoreDumbMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MoreDumbMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MoreDumbMethods.java 2010-04-04 07:05:42 UTC (rev 1532)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MoreDumbMethods.java 2010-04-04 07:59:40 UTC (rev 1533)
@@ -1,6 +1,7 @@
/*
* fb-contrib - Auxiliary detectors for Java programs
* Copyright (C) 2005-2010 Chris Peterson
+ * Copyright (C) 2005-2010 Jean-Noel Rouvignac
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -21,9 +22,12 @@
import java.util.HashMap;
import java.util.Map;
+import com.mebigfatguy.fbcontrib.utils.XClassUtils;
+
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.ba.XMethod;
/**
* looks for method calls that are unsafe or might indicate bugs.
@@ -109,7 +113,9 @@
dumbMethods.put("java/lang/String.getBytes()[B", new ReportInfo("MDM_STRING_BYTES_ENCODING", NORMAL_PRIORITY));
dumbMethods.put("java/util/Locale.setDefault(Ljava/util/Locale;)V", new ReportInfo("MDM_SETDEFAULTLOCALE", NORMAL_PRIORITY));
}
+
private final BugReporter bugReporter;
+ private final XClassUtils classUtil = new XClassUtils();
/**
* constructs an MDM detector given the reporter to report bugs on
@@ -121,14 +127,17 @@
@Override
public void sawOpcode(int seen) {
- if (seen == INVOKEVIRTUAL
- || seen == INVOKEINTERFACE
- || seen == INVOKESPECIAL
- || seen == INVOKESTATIC) {
- final ReportInfo info = dumbMethods.get(getMethodSignature());
- if (info != null) {
- reportBug(info);
- }
+
+ ReportInfo info = null;
+ if (seen == INVOKESPECIAL || seen == INVOKESTATIC) {
+ // static method invocation: no dispatch, straight call
+ info = dumbMethods.get(getMethodSignature());
+ } else if (seen == INVOKEVIRTUAL || seen == INVOKEINTERFACE) {
+ // virtual method invocation: dispatch is based on the class
+ info = dumbMethods.get(getVirtualMethodSignature());
+ }
+ if (info != null) {
+ reportBug(info);
}
}
@@ -138,7 +147,20 @@
final String methodSig = getSigConstantOperand();
return String.format("%s.%s%s", className, methodName, methodSig);
}
+
+ private String getVirtualMethodSignature() {
+ final XMethod declaredMethod = classUtil.getXMethod(
+ getClassConstantOperand(), getNameConstantOperand(),
+ getSigConstantOperand());
+ final String className = declaredMethod.getClassDescriptor()
+ .getClassName();
+ final String methodName = declaredMethod.getName();
+ final String methodSig = declaredMethod.getSignature();
+ return String.format("%s.%s%s", className, methodName, methodSig);
+ }
+
+
private void reportBug(ReportInfo info) {
bugReporter.reportBug(new BugInstance(this, info.getPattern(), info.getPriority())
.addClass(this)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|