[Fb-contrib-commit] SF.net SVN: fb-contrib:[1431] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/d
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-01-05 05:11:56
|
Revision: 1431
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1431&view=rev
Author: dbrosius
Date: 2010-01-05 05:11:45 +0000 (Tue, 05 Jan 2010)
Log Message:
-----------
customize priority of bug based on pattern
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-01-04 04:26:03 UTC (rev 1430)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MoreDumbMethods.java 2010-01-05 05:11:45 UTC (rev 1431)
@@ -30,66 +30,84 @@
*/
public class MoreDumbMethods extends BytecodeScanningDetector
{
- private final static Map<String,String> dumbMethods = new HashMap<String,String>();
+ private static class ReportInfo {
+ private String bugPattern;
+ private int bugPriority;
+
+ ReportInfo(String pattern, int priority) {
+ bugPattern = pattern;
+ bugPriority = priority;
+ }
+
+ String getPattern() {
+ return bugPattern;
+ }
+
+ int getPriority() {
+ return bugPriority;
+ }
+ }
+
+ private final static Map<String,ReportInfo> dumbMethods = new HashMap<String,ReportInfo>();
static {
- dumbMethods.put("java/lang/Runtime.exit(I)V", "MDM_RUNTIME_EXIT_OR_HALT");
- dumbMethods.put("java/lang/Runtime.halt(I)V", "MDM_RUNTIME_EXIT_OR_HALT");
+ dumbMethods.put("java/lang/Runtime.exit(I)V", new ReportInfo("MDM_RUNTIME_EXIT_OR_HALT", LOW_PRIORITY));
+ dumbMethods.put("java/lang/Runtime.halt(I)V", new ReportInfo("MDM_RUNTIME_EXIT_OR_HALT", HIGH_PRIORITY));
- dumbMethods.put("java/lang/Runtime.runFinalization()V", "MDM_RUNFINALIZATION");
- dumbMethods.put("java/lang/System.runFinalization()V", "MDM_RUNFINALIZATION");
+ dumbMethods.put("java/lang/Runtime.runFinalization()V", new ReportInfo("MDM_RUNFINALIZATION", NORMAL_PRIORITY));
+ dumbMethods.put("java/lang/System.runFinalization()V", new ReportInfo("MDM_RUNFINALIZATION", NORMAL_PRIORITY));
- dumbMethods.put("java/math/BigDecimal.equals(Ljava/lang/Object;)Z", "MDM_BIGDECIMAL_EQUALS");
+ dumbMethods.put("java/math/BigDecimal.equals(Ljava/lang/Object;)Z", new ReportInfo("MDM_BIGDECIMAL_EQUALS", NORMAL_PRIORITY));
//
// Network checks
//
- dumbMethods.put("java/net/InetAddress.getLocalHost()Ljava/net/InetAddress;", "MDM_INETADDRESS_GETLOCALHOST");
+ dumbMethods.put("java/net/InetAddress.getLocalHost()Ljava/net/InetAddress;", new ReportInfo("MDM_INETADDRESS_GETLOCALHOST", NORMAL_PRIORITY));
- dumbMethods.put("java/net/ServerSocket.<init>(I)V", "MDM_PROMISCUOUS_SERVERSOCKET");
- dumbMethods.put("java/net/ServerSocket.<init>(II)V", "MDM_PROMISCUOUS_SERVERSOCKET");
- dumbMethods.put("javax/net/ServerSocketFactory.createServerSocket(I)Ljava/net/ServerSocket;", "MDM_PROMISCUOUS_SERVERSOCKET");
- dumbMethods.put("javax/net/ServerSocketFactory.createServerSocket(II)Ljava/net/ServerSocket;", "MDM_PROMISCUOUS_SERVERSOCKET");
+ dumbMethods.put("java/net/ServerSocket.<init>(I)V", new ReportInfo("MDM_PROMISCUOUS_SERVERSOCKET", NORMAL_PRIORITY));
+ dumbMethods.put("java/net/ServerSocket.<init>(II)V", new ReportInfo("MDM_PROMISCUOUS_SERVERSOCKET", NORMAL_PRIORITY));
+ dumbMethods.put("javax/net/ServerSocketFactory.createServerSocket(I)Ljava/net/ServerSocket;", new ReportInfo("MDM_PROMISCUOUS_SERVERSOCKET", LOW_PRIORITY));
+ dumbMethods.put("javax/net/ServerSocketFactory.createServerSocket(II)Ljava/net/ServerSocket;", new ReportInfo("MDM_PROMISCUOUS_SERVERSOCKET", LOW_PRIORITY));
//
// Random Number Generator checks
//
- dumbMethods.put("java/util/Random.<init>()V", "MDM_RANDOM_SEED");
- dumbMethods.put("java/security/SecureRandom.<init>()V", "MDM_SECURERANDOM");
- dumbMethods.put("java/security/SecureRandom.<init>([B)V", "MDM_SECURERANDOM");
- dumbMethods.put("java/security/SecureRandom.getSeed(I)[B", "MDM_SECURERANDOM");
+ dumbMethods.put("java/util/Random.<init>()V", new ReportInfo("MDM_RANDOM_SEED", LOW_PRIORITY));
+ dumbMethods.put("java/security/SecureRandom.<init>()V", new ReportInfo("MDM_SECURERANDOM", LOW_PRIORITY));
+ dumbMethods.put("java/security/SecureRandom.<init>([B)V", new ReportInfo("MDM_SECURERANDOM", LOW_PRIORITY));
+ dumbMethods.put("java/security/SecureRandom.getSeed(I)[B", new ReportInfo("MDM_SECURERANDOM", LOW_PRIORITY));
//
// Thread checks
//
- dumbMethods.put("java/lang/Thread.getPriority()I", "MDM_THREAD_PRIORITIES");
- dumbMethods.put("java/lang/Thread.setPriority(I)V", "MDM_THREAD_PRIORITIES");
+ dumbMethods.put("java/lang/Thread.getPriority()I", new ReportInfo("MDM_THREAD_PRIORITIES", LOW_PRIORITY));
+ dumbMethods.put("java/lang/Thread.setPriority(I)V", new ReportInfo("MDM_THREAD_PRIORITIES", LOW_PRIORITY));
- dumbMethods.put("java/lang/Thread.sleep(J)V", "MDM_THREAD_YIELD");
- dumbMethods.put("java/lang/Thread.sleep(JI)V", "MDM_THREAD_YIELD");
- dumbMethods.put("java/lang/Thread.yield()V", "MDM_THREAD_YIELD");
+ dumbMethods.put("java/lang/Thread.sleep(J)V", new ReportInfo("MDM_THREAD_YIELD", LOW_PRIORITY));
+ dumbMethods.put("java/lang/Thread.sleep(JI)V", new ReportInfo("MDM_THREAD_YIELD", LOW_PRIORITY));
+ dumbMethods.put("java/lang/Thread.yield()V", new ReportInfo("MDM_THREAD_YIELD", NORMAL_PRIORITY));
- dumbMethods.put("java/lang/Thread.join()V", "MDM_WAIT_WITHOUT_TIMEOUT");
- dumbMethods.put("java/lang/Object.wait()V", "MDM_WAIT_WITHOUT_TIMEOUT");
- dumbMethods.put("java/util/concurrent/locks/Condition.await()V", "MDM_WAIT_WITHOUT_TIMEOUT");
- dumbMethods.put("java/util/concurrent/locks/Lock.lock()V", "MDM_WAIT_WITHOUT_TIMEOUT");
- dumbMethods.put("java/util/concurrent/locks/Lock.lockInterruptibly()V", "MDM_WAIT_WITHOUT_TIMEOUT");
- dumbMethods.put("java/util/concurrent/locks/ReentrantLock.lock()V", "MDM_WAIT_WITHOUT_TIMEOUT");
- dumbMethods.put("java/util/concurrent/locks/ReentrantLock.lockInterruptibly()V", "MDM_WAIT_WITHOUT_TIMEOUT");
+ dumbMethods.put("java/lang/Thread.join()V", new ReportInfo("MDM_WAIT_WITHOUT_TIMEOUT", LOW_PRIORITY));
+ dumbMethods.put("java/lang/Object.wait()V", new ReportInfo("MDM_WAIT_WITHOUT_TIMEOUT", LOW_PRIORITY));
+ dumbMethods.put("java/util/concurrent/locks/Condition.await()V", new ReportInfo("MDM_WAIT_WITHOUT_TIMEOUT", LOW_PRIORITY));
+ dumbMethods.put("java/util/concurrent/locks/Lock.lock()V", new ReportInfo("MDM_WAIT_WITHOUT_TIMEOUT", LOW_PRIORITY));
+ dumbMethods.put("java/util/concurrent/locks/Lock.lockInterruptibly()V", new ReportInfo("MDM_WAIT_WITHOUT_TIMEOUT", LOW_PRIORITY));
+ dumbMethods.put("java/util/concurrent/locks/ReentrantLock.lock()V", new ReportInfo("MDM_WAIT_WITHOUT_TIMEOUT", LOW_PRIORITY));
+ dumbMethods.put("java/util/concurrent/locks/ReentrantLock.lockInterruptibly()V", new ReportInfo("MDM_WAIT_WITHOUT_TIMEOUT", LOW_PRIORITY));
- dumbMethods.put("java/util/concurrent/locks/Condition.signal()V", "MDM_SIGNAL_NOT_SIGNALALL");
+ dumbMethods.put("java/util/concurrent/locks/Condition.signal()V", new ReportInfo("MDM_SIGNAL_NOT_SIGNALALL", NORMAL_PRIORITY));
- dumbMethods.put("java/util/concurrent/locks/Lock.tryLock()Z", "MDM_THREAD_FAIRNESS");
- dumbMethods.put("java/util/concurrent/locks/ReentrantLock.tryLock()Z", "MDM_THREAD_FAIRNESS");
+ dumbMethods.put("java/util/concurrent/locks/Lock.tryLock()Z", new ReportInfo("MDM_THREAD_FAIRNESS", LOW_PRIORITY));
+ dumbMethods.put("java/util/concurrent/locks/ReentrantLock.tryLock()Z", new ReportInfo("MDM_THREAD_FAIRNESS", LOW_PRIORITY));
- dumbMethods.put("java/util/concurrent/locks/ReentrantLock.isHeldByCurrentThread()Z", "MDM_LOCK_ISLOCKED");
- dumbMethods.put("java/util/concurrent/locks/ReentrantLock.isLocked()Z", "MDM_LOCK_ISLOCKED");
+ dumbMethods.put("java/util/concurrent/locks/ReentrantLock.isHeldByCurrentThread()Z", new ReportInfo("MDM_LOCK_ISLOCKED", LOW_PRIORITY));
+ dumbMethods.put("java/util/concurrent/locks/ReentrantLock.isLocked()Z", new ReportInfo("MDM_LOCK_ISLOCKED", LOW_PRIORITY));
//
// String checks
//
- dumbMethods.put("java/lang/String.<init>([B)V", "MDM_STRING_BYTES_ENCODING");
- dumbMethods.put("java/lang/String.getBytes()[B", "MDM_STRING_BYTES_ENCODING");
- dumbMethods.put("java/util/Locale.setDefault(Ljava/util/Locale;)V", "MDM_SETDEFAULTLOCALE");
+ dumbMethods.put("java/lang/String.<init>([B)V", new ReportInfo("MDM_STRING_BYTES_ENCODING", NORMAL_PRIORITY));
+ 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;
@@ -107,9 +125,9 @@
|| seen == INVOKEINTERFACE
|| seen == INVOKESPECIAL
|| seen == INVOKESTATIC) {
- final String bugType = dumbMethods.get(getMethodSignature());
- if (bugType != null) {
- reportBug(bugType);
+ final ReportInfo info = dumbMethods.get(getMethodSignature());
+ if (info != null) {
+ reportBug(info);
}
}
}
@@ -121,8 +139,8 @@
return String.format("%s.%s%s", className, methodName, methodSig);
}
- private void reportBug(String bugType) {
- bugReporter.reportBug(new BugInstance(this, bugType, LOW_PRIORITY)
+ private void reportBug(ReportInfo info) {
+ bugReporter.reportBug(new BugInstance(this, info.getPattern(), info.getPriority())
.addClass(this)
.addMethod(this)
.addCalledMethod(this)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|