Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib:[1457] trunk/fb-contrib (Page 2)
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-01-10 16:52:03
|
Revision: 1457
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1457&view=rev
Author: dbrosius
Date: 2010-01-10 16:51:57 +0000 (Sun, 10 Jan 2010)
Log Message:
-----------
rename WrongNullGuard to SuspiciousNullGuard
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/SNG_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
Removed Paths:
-------------
trunk/fb-contrib/samples/WNG_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-01-10 02:14:08 UTC (rev 1456)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-01-10 16:51:57 UTC (rev 1457)
@@ -313,8 +313,8 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField"
speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.WrongNullGuard"
- speed="fast" hidden="true" reports="WNG_WRONG_NULL_FIELD_GUARD,WNG_WRONG_NULL_LOCAL_GUARD" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard"
+ speed="fast" reports="SNG_WRONG_NULL_FIELD_GUARD,SNG_WRONG_NULL_LOCAL_GUARD" />
<Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods"
speed="fast"
@@ -570,9 +570,9 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="NFF" type="NFF_NON_FUNCTIONAL_FIELD"
category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="WNG" type="WNG_WRONG_NULL_FIELD_GUARD"
+ <BugPattern abbrev="SNG" type="SNG_WRONG_NULL_FIELD_GUARD"
category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="WNG" type="WNG_WRONG_NULL_LOCAL_GUARD"
+ <BugPattern abbrev="SNG" type="SNG_WRONG_NULL_LOCAL_GUARD"
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="MDM" type="MDM_RUNTIME_EXIT_OR_HALT"
category="CORRECTNESS" experimental="true" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-01-10 02:14:08 UTC (rev 1456)
+++ trunk/fb-contrib/etc/messages.xml 2010-01-10 16:51:57 UTC (rev 1457)
@@ -1078,7 +1078,7 @@
</Details>
</Detector>
- <Detector class="com.mebigfatguy.fbcontrib.detect.WrongNullGuard">
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard">
<Details>
<![CDATA[
<p>looks for code that checks to see if a field or local variable is not null,
@@ -2822,7 +2822,7 @@
</Details>
</BugPattern>
- <BugPattern type="WNG_WRONG_NULL_FIELD_GUARD">
+ <BugPattern type="SNG_WRONG_NULL_FIELD_GUARD">
<ShortDescription>method tests a field for null as guard for code that doesn't use it</ShortDescription>
<LongDescription>method {1} tests a field for null as guard for code that doesn't use it</LongDescription>
<Details>
@@ -2835,7 +2835,7 @@
</Details>
</BugPattern>
- <BugPattern type="WNG_WRONG_NULL_LOCAL_GUARD">
+ <BugPattern type="SNG_WRONG_NULL_LOCAL_GUARD">
<ShortDescription>method tests a local variable for null as guard for code that doesn't use it</ShortDescription>
<LongDescription>method {1} tests a local variable for null as guard for code that doesn't use it</LongDescription>
<Details>
@@ -3087,6 +3087,6 @@
<BugCode abbrev="NSE">Non Symmetric Equals</BugCode>
<BugCode abbrev="CVAA">Contravariant Array Assignment</BugCode>
<BugCode abbrev="NFF">Non Functional Field</BugCode>
- <BugCode abbrev="WNG">Wrong Null Guard</BugCode>
+ <BugCode abbrev="SNG">Wrong Null Guard</BugCode>
<BugCode abbrev="MDM">More Dumb Methods</BugCode>
</MessageCollection>
Copied: trunk/fb-contrib/samples/SNG_Sample.java (from rev 1453, trunk/fb-contrib/samples/WNG_Sample.java)
===================================================================
--- trunk/fb-contrib/samples/SNG_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/SNG_Sample.java 2010-01-10 16:51:57 UTC (rev 1457)
@@ -0,0 +1,73 @@
+import java.io.File;
+
+
+public class SNG_Sample
+{
+ private static byte[] EMPTY_BYTE_ARRAY = new byte[0];
+ private Object f1 = null;
+ private Object f2 = null;
+ private File file = null;
+ private byte[] buffer = null;
+
+ public String badSNGFields()
+ {
+ if (f1 != null)
+ return f2.toString();
+
+ return null;
+ }
+
+ public String badSNGLocals(Object l1, Object l2)
+ {
+ if (l1 != null)
+ return l2.toString();
+
+ return null;
+ }
+
+ public boolean fpReturn(Object o) {
+ return o != null;
+ }
+
+ public boolean fpAssign(Object o) {
+ boolean b = o != null;
+ return b;
+ }
+
+ public boolean fpField() {
+ if (f1 != null)
+ return true;
+
+ return false;
+ }
+
+ public void fpAssert() {
+ assert f1 != null && f1.equals(f2);
+ }
+
+ public Object fpSetNull(Object o) {
+ if (o != null)
+ o = null;
+
+ return o;
+ }
+
+ public void fpSetMemberNull() {
+ if (f1 != null)
+ f1 = null;
+ }
+
+ public void fpDual(Object o1, Object o2) {
+ if (o1 == null || o2 == null) {
+ throw new IllegalArgumentException("o1/o2 can not be null");
+ }
+ }
+
+ public void discard() {
+ if (file != null) {
+ file.delete();
+ } else if (buffer != null) {
+ buffer = EMPTY_BYTE_ARRAY;
+ }
+ }
+}
Deleted: trunk/fb-contrib/samples/WNG_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WNG_Sample.java 2010-01-10 02:14:08 UTC (rev 1456)
+++ trunk/fb-contrib/samples/WNG_Sample.java 2010-01-10 16:51:57 UTC (rev 1457)
@@ -1,73 +0,0 @@
-import java.io.File;
-
-
-public class WNG_Sample
-{
- private static byte[] EMPTY_BYTE_ARRAY = new byte[0];
- private Object f1 = null;
- private Object f2 = null;
- private File file = null;
- private byte[] buffer = null;
-
- public String badWNGFields()
- {
- if (f1 != null)
- return f2.toString();
-
- return null;
- }
-
- public String badWNGLocals(Object l1, Object l2)
- {
- if (l1 != null)
- return l2.toString();
-
- return null;
- }
-
- public boolean fpReturn(Object o) {
- return o != null;
- }
-
- public boolean fpAssign(Object o) {
- boolean b = o != null;
- return b;
- }
-
- public boolean fpField() {
- if (f1 != null)
- return true;
-
- return false;
- }
-
- public void fpAssert() {
- assert f1 != null && f1.equals(f2);
- }
-
- public Object fpSetNull(Object o) {
- if (o != null)
- o = null;
-
- return o;
- }
-
- public void fpSetMemberNull() {
- if (f1 != null)
- f1 = null;
- }
-
- public void fpDual(Object o1, Object o2) {
- if (o1 == null || o2 == null) {
- throw new IllegalArgumentException("o1/o2 can not be null");
- }
- }
-
- public void discard() {
- if (file != null) {
- file.delete();
- } else if (buffer != null) {
- buffer = EMPTY_BYTE_ARRAY;
- }
- }
-}
Copied: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java (from rev 1451, trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java)
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-01-10 16:51:57 UTC (rev 1457)
@@ -0,0 +1,279 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.LocalVariable;
+import org.apache.bcel.classfile.LocalVariableTable;
+
+import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.ba.XField;
+
+/**
+ * looks for code that checks to see if a field or local variable is not null,
+ * before entering a code block either an if, or while statement, and then doesn't
+ * reference that field or local in the block of code that is guarded by the null
+ * check. It is likely that null check is being done on the wrong variable, either
+ * because of a copy/paste error, or a change in implementation.
+ */
+public class SuspiciousNullGuard extends BytecodeScanningDetector {
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ private LocalVariableTable lvt;
+ private Map<Integer, NullGuard> nullGuards;
+
+ /**
+ * constructs a SNG detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public SuspiciousNullGuard(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ /**
+ * overrides the visitor to initialize and tear down the opcode stack
+ *
+ * @param classContext the context object of the currently parsed class
+ */
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ nullGuards = new HashMap<Integer, NullGuard>();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ }
+ }
+
+ /**
+ * overrides the visitor to reset the stack
+ *
+ * @param obj the context object of the currently parsed code block
+ */
+ @Override
+ public void visitCode(Code obj) {
+ try {
+ stack.resetForMethodEntry(this);
+ lvt = getMethod().getLocalVariableTable();
+ nullGuards.clear();
+ super.visitCode(obj);
+ } finally {
+ lvt = null;
+ }
+ }
+
+ /**
+ * overrides the visitor to look for bad null guards
+ *
+ * @param seen the opcode of the currently visited instruction
+ */
+ @Override
+ public void sawOpcode(int seen) {
+ try {
+ Integer pc = Integer.valueOf(getPC());
+ NullGuard guard = nullGuards.remove(pc);
+ if ((guard != null) && guard.sawSignatureOfGuard()) {
+ boolean localBug = guard.getRegister() >= 0;
+ bugReporter.reportBug(new BugInstance(this, localBug ? "SNG_WRONG_NULL_LOCAL_GUARD" : "SNG_WRONG_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this, guard.getLocation()));
+ }
+
+ switch (seen) {
+ case IFNULL: {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ int reg = item.getRegisterNumber();
+ Integer target = Integer.valueOf(getBranchTarget());
+ if (reg >= 0) {
+ nullGuards.put(target, new NullGuard(reg, pc.intValue(), item.getSignature()));
+ } else {
+ XField xf = item.getXField();
+ if (xf != null) {
+ nullGuards.put(target, new NullGuard(xf, pc.intValue(), item.getSignature()));
+ }
+ }
+ }
+ }
+ break;
+
+ case ALOAD:
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3: {
+ if (lvt != null) {
+ LocalVariable lv = lvt.getLocalVariable(RegisterUtils.getALoadReg(this, seen), getNextPC());
+ if (lv != null) {
+ markNullGuards(lv.getSignature());
+ }
+ }
+ }
+ break;
+
+ case ASTORE:
+ case ASTORE_0:
+ case ASTORE_1:
+ case ASTORE_2:
+ case ASTORE_3: {
+ removeGuardForRegister(RegisterUtils.getAStoreReg(this, seen));
+ }
+ break;
+
+ case GETFIELD: {
+ markNullGuards(getSigConstantOperand());
+ }
+ break;
+
+ case PUTFIELD: {
+ removeGuardForField(getXField());
+ }
+ break;
+
+ case INVOKEVIRTUAL:
+ case INVOKEINTERFACE: {
+ if (nullGuards.size() > 0) {
+ String clsName = getClassConstantOperand();
+ String methodName = getNameConstantOperand();
+ if ("java/io/PrintStream".equals(clsName) && methodName.startsWith("print")) {
+ nullGuards.clear();
+ }
+ }
+ }
+ break;
+
+ case IFNONNULL:
+ case ATHROW: {
+ nullGuards.clear();
+ }
+ break;
+
+ case GOTO: {
+ if (stack.getStackDepth() > 0) {
+ nullGuards.clear();
+ }
+ }
+ break;
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ int reg = item.getRegisterNumber();
+ if (reg >= 0) {
+ removeGuardForRegister(reg);
+ } else {
+ XField field = item.getXField();
+ if (field != null)
+ removeGuardForField(field);
+ }
+ }
+ }
+ }
+
+ private void markNullGuards(String signature) {
+ for (NullGuard ng : nullGuards.values()) {
+ if (ng.getSignature().equals(signature)) {
+ ng.markSignatureOfGuard();
+ }
+ }
+ }
+
+ private void removeGuardForRegister(int reg) {
+ Iterator<NullGuard> it = nullGuards.values().iterator();
+ while (it.hasNext()) {
+ NullGuard guard = it.next();
+ if (reg == guard.getRegister()) {
+ it.remove();
+ }
+ }
+ }
+
+ private void removeGuardForField(XField field) {
+ Iterator<NullGuard> it = nullGuards.values().iterator();
+ while (it.hasNext()) {
+ NullGuard guard = it.next();
+ if (field != null) {
+ if (field.equals(guard.getField())) {
+ it.remove();
+ }
+ }
+ }
+ }
+
+ static class NullGuard {
+ int register;
+ XField field;
+ int location;
+ String signature;
+ boolean sawSignature = false;
+
+ public NullGuard(int reg, int start, String guardSignature) {
+ register = reg;
+ field = null;
+ location = start;
+ signature = guardSignature;
+ }
+
+
+ public NullGuard(XField xf, int start, String guardSignature) {
+ register = -1;
+ field = xf;
+ location = start;
+ signature = guardSignature;
+ }
+
+ public int getRegister() {
+ return register;
+ }
+
+ public XField getField() {
+ return field;
+ }
+
+ public int getLocation() {
+ return location;
+ }
+
+ public String getSignature() {
+ return signature;
+ }
+
+ public void markSignatureOfGuard() {
+ sawSignature = true;
+ }
+
+ public boolean sawSignatureOfGuard() {
+ return sawSignature;
+ }
+ }
+}
Deleted: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java 2010-01-10 02:14:08 UTC (rev 1456)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WrongNullGuard.java 2010-01-10 16:51:57 UTC (rev 1457)
@@ -1,279 +0,0 @@
-/*
- * fb-contrib - Auxiliary detectors for Java programs
- * Copyright (C) 2005-2010 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.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.bcel.classfile.Code;
-import org.apache.bcel.classfile.LocalVariable;
-import org.apache.bcel.classfile.LocalVariableTable;
-
-import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
-
-import edu.umd.cs.findbugs.BugInstance;
-import edu.umd.cs.findbugs.BugReporter;
-import edu.umd.cs.findbugs.BytecodeScanningDetector;
-import edu.umd.cs.findbugs.OpcodeStack;
-import edu.umd.cs.findbugs.ba.ClassContext;
-import edu.umd.cs.findbugs.ba.XField;
-
-/**
- * looks for code that checks to see if a field or local variable is not null,
- * before entering a code block either an if, or while statement, and then doesn't
- * reference that field or local in the block of code that is guarded by the null
- * check. It is likely that null check is being done on the wrong variable, either
- * because of a copy/paste error, or a change in implementation.
- */
-public class WrongNullGuard extends BytecodeScanningDetector {
-
- private BugReporter bugReporter;
- private OpcodeStack stack;
- private LocalVariableTable lvt;
- private Map<Integer, NullGuard> nullGuards;
-
- /**
- * constructs a WNG detector given the reporter to report bugs on
- * @param bugReporter the sync of bug reports
- */
- public WrongNullGuard(BugReporter bugReporter) {
- this.bugReporter = bugReporter;
- }
-
- /**
- * overrides the visitor to initialize and tear down the opcode stack
- *
- * @param classContext the context object of the currently parsed class
- */
- @Override
- public void visitClassContext(ClassContext classContext) {
- try {
- stack = new OpcodeStack();
- nullGuards = new HashMap<Integer, NullGuard>();
- super.visitClassContext(classContext);
- } finally {
- stack = null;
- }
- }
-
- /**
- * overrides the visitor to reset the stack
- *
- * @param obj the context object of the currently parsed code block
- */
- @Override
- public void visitCode(Code obj) {
- try {
- stack.resetForMethodEntry(this);
- lvt = getMethod().getLocalVariableTable();
- nullGuards.clear();
- super.visitCode(obj);
- } finally {
- lvt = null;
- }
- }
-
- /**
- * overrides the visitor to look for bad null guards
- *
- * @param seen the opcode of the currently visited instruction
- */
- @Override
- public void sawOpcode(int seen) {
- try {
- Integer pc = Integer.valueOf(getPC());
- NullGuard guard = nullGuards.remove(pc);
- if ((guard != null) && guard.sawSignatureOfGuard()) {
- boolean localBug = guard.getRegister() >= 0;
- bugReporter.reportBug(new BugInstance(this, localBug ? "WNG_WRONG_NULL_LOCAL_GUARD" : "WNG_WRONG_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this, guard.getLocation()));
- }
-
- switch (seen) {
- case IFNULL: {
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item item = stack.getStackItem(0);
- int reg = item.getRegisterNumber();
- Integer target = Integer.valueOf(getBranchTarget());
- if (reg >= 0) {
- nullGuards.put(target, new NullGuard(reg, pc.intValue(), item.getSignature()));
- } else {
- XField xf = item.getXField();
- if (xf != null) {
- nullGuards.put(target, new NullGuard(xf, pc.intValue(), item.getSignature()));
- }
- }
- }
- }
- break;
-
- case ALOAD:
- case ALOAD_0:
- case ALOAD_1:
- case ALOAD_2:
- case ALOAD_3: {
- if (lvt != null) {
- LocalVariable lv = lvt.getLocalVariable(RegisterUtils.getALoadReg(this, seen), getNextPC());
- if (lv != null) {
- markNullGuards(lv.getSignature());
- }
- }
- }
- break;
-
- case ASTORE:
- case ASTORE_0:
- case ASTORE_1:
- case ASTORE_2:
- case ASTORE_3: {
- removeGuardForRegister(RegisterUtils.getAStoreReg(this, seen));
- }
- break;
-
- case GETFIELD: {
- markNullGuards(getSigConstantOperand());
- }
- break;
-
- case PUTFIELD: {
- removeGuardForField(getXField());
- }
- break;
-
- case INVOKEVIRTUAL:
- case INVOKEINTERFACE: {
- if (nullGuards.size() > 0) {
- String clsName = getClassConstantOperand();
- String methodName = getNameConstantOperand();
- if ("java/io/PrintStream".equals(clsName) && methodName.startsWith("print")) {
- nullGuards.clear();
- }
- }
- }
- break;
-
- case IFNONNULL:
- case ATHROW: {
- nullGuards.clear();
- }
- break;
-
- case GOTO: {
- if (stack.getStackDepth() > 0) {
- nullGuards.clear();
- }
- }
- break;
- }
- } finally {
- stack.sawOpcode(this, seen);
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item item = stack.getStackItem(0);
- int reg = item.getRegisterNumber();
- if (reg >= 0) {
- removeGuardForRegister(reg);
- } else {
- XField field = item.getXField();
- if (field != null)
- removeGuardForField(field);
- }
- }
- }
- }
-
- private void markNullGuards(String signature) {
- for (NullGuard ng : nullGuards.values()) {
- if (ng.getSignature().equals(signature)) {
- ng.markSignatureOfGuard();
- }
- }
- }
-
- private void removeGuardForRegister(int reg) {
- Iterator<NullGuard> it = nullGuards.values().iterator();
- while (it.hasNext()) {
- NullGuard guard = it.next();
- if (reg == guard.getRegister()) {
- it.remove();
- }
- }
- }
-
- private void removeGuardForField(XField field) {
- Iterator<NullGuard> it = nullGuards.values().iterator();
- while (it.hasNext()) {
- NullGuard guard = it.next();
- if (field != null) {
- if (field.equals(guard.getField())) {
- it.remove();
- }
- }
- }
- }
-
- static class NullGuard {
- int register;
- XField field;
- int location;
- String signature;
- boolean sawSignature = false;
-
- public NullGuard(int reg, int start, String guardSignature) {
- register = reg;
- field = null;
- location = start;
- signature = guardSignature;
- }
-
-
- public NullGuard(XField xf, int start, String guardSignature) {
- register = -1;
- field = xf;
- location = start;
- signature = guardSignature;
- }
-
- public int getRegister() {
- return register;
- }
-
- public XField getField() {
- return field;
- }
-
- public int getLocation() {
- return location;
- }
-
- public String getSignature() {
- return signature;
- }
-
- public void markSignatureOfGuard() {
- sawSignature = true;
- }
-
- public boolean sawSignatureOfGuard() {
- return sawSignature;
- }
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-12 06:07:41
|
Revision: 1478
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1478&view=rev
Author: dbrosius
Date: 2010-01-12 06:07:30 +0000 (Tue, 12 Jan 2010)
Log Message:
-----------
soften the language of wrong null guard to suspicious null guard
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-01-12 06:00:17 UTC (rev 1477)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-01-12 06:07:30 UTC (rev 1478)
@@ -314,7 +314,7 @@
speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard"
- speed="fast" reports="SNG_WRONG_NULL_FIELD_GUARD,SNG_WRONG_NULL_LOCAL_GUARD" />
+ speed="fast" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
<Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods"
speed="fast"
@@ -570,9 +570,9 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="NFF" type="NFF_NON_FUNCTIONAL_FIELD"
category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="SNG" type="SNG_WRONG_NULL_FIELD_GUARD"
+ <BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_FIELD_GUARD"
category="CORRECTNESS" experimental="true" />
- <BugPattern abbrev="SNG" type="SNG_WRONG_NULL_LOCAL_GUARD"
+ <BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_LOCAL_GUARD"
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="MDM" type="MDM_RUNTIME_EXIT_OR_HALT"
category="CORRECTNESS" experimental="true" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-01-12 06:00:17 UTC (rev 1477)
+++ trunk/fb-contrib/etc/messages.xml 2010-01-12 06:07:30 UTC (rev 1478)
@@ -2822,7 +2822,7 @@
</Details>
</BugPattern>
- <BugPattern type="SNG_WRONG_NULL_FIELD_GUARD">
+ <BugPattern type="SNG_SUSPICIOUS_NULL_FIELD_GUARD">
<ShortDescription>method tests a field for null as guard for code that doesn't use it</ShortDescription>
<LongDescription>method {1} tests a field for null as guard for code that doesn't use it</LongDescription>
<Details>
@@ -2835,7 +2835,7 @@
</Details>
</BugPattern>
- <BugPattern type="SNG_WRONG_NULL_LOCAL_GUARD">
+ <BugPattern type="SNG_SUSPICIOUS_NULL_LOCAL_GUARD">
<ShortDescription>method tests a local variable for null as guard for code that doesn't use it</ShortDescription>
<LongDescription>method {1} tests a local variable for null as guard for code that doesn't use it</LongDescription>
<Details>
@@ -3087,6 +3087,6 @@
<BugCode abbrev="NSE">Non Symmetric Equals</BugCode>
<BugCode abbrev="CVAA">Contravariant Array Assignment</BugCode>
<BugCode abbrev="NFF">Non Functional Field</BugCode>
- <BugCode abbrev="SNG">Wrong Null Guard</BugCode>
+ <BugCode abbrev="SNG">SUSPICIOUS Null Guard</BugCode>
<BugCode abbrev="MDM">More Dumb Methods</BugCode>
</MessageCollection>
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-01-12 06:00:17 UTC (rev 1477)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-01-12 06:07:30 UTC (rev 1478)
@@ -102,7 +102,7 @@
NullGuard guard = nullGuards.remove(pc);
if ((guard != null) && guard.sawSignatureOfGuard()) {
boolean localBug = guard.getRegister() >= 0;
- bugReporter.reportBug(new BugInstance(this, localBug ? "SNG_WRONG_NULL_LOCAL_GUARD" : "SNG_WRONG_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY)
+ bugReporter.reportBug(new BugInstance(this, localBug ? "SNG_SUSPICIOUS_NULL_LOCAL_GUARD" : "SNG_SUSPICIOUS_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY)
.addClass(this)
.addMethod(this)
.addSourceLine(this, guard.getLocation()));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-14 05:31:43
|
Revision: 1481
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1481&view=rev
Author: dbrosius
Date: 2010-01-14 05:31:35 +0000 (Thu, 14 Jan 2010)
Log Message:
-----------
get ready for the 4.2.0 release
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/pom.xml
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2010-01-12 06:15:01 UTC (rev 1480)
+++ trunk/fb-contrib/build.xml 2010-01-14 05:31:35 UTC (rev 1481)
@@ -20,7 +20,7 @@
<property name="javac.deprecation" value="on"/>
<property name="javac.debug" value="on"/>
- <property name="fb-contrib.version" value="4.1.0"/>
+ <property name="fb-contrib.version" value="4.2.0"/>
<target name="clean" description="removes all generated collateral">
<delete dir="${classes.dir}"/>
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-01-12 06:15:01 UTC (rev 1480)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-01-14 05:31:35 UTC (rev 1481)
@@ -308,13 +308,13 @@
<Detector
class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment"
- speed="fast" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" />
+ speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" />
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField"
speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard"
- speed="fast" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
+ speed="fast" hidden="true" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
<Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods"
speed="fast"
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-01-12 06:15:01 UTC (rev 1480)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-01-14 05:31:35 UTC (rev 1481)
@@ -51,10 +51,28 @@
<a href="bugdescriptions.html">Bug Descriptions</a>
<!--#include virtual="mbfg_menu.shtml" -->
<hr/>
- <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
+ <img id="svn_image" src="flip1.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
Detectors added in svn<br/>
- <div id="svn" style="display:block;">
+ <div id="svn" style="display:none;">
<ul>
+ <li><b>[CVAA] ContraVariant Array Assignment</b><br/>
+ Looks for contravariant array assignments. Since arrays are mutable data structures, their use
+ must be restricted to covariant or invariant usage.
+ <span style="color: #0000FF;">--contributed by Bhaskar Maddala - THANKS!</span></li>
+ <li><b>[SNG] Suspicious Null Guard</b><br/>
+ Looks for code that checks to see if a field or local variable is not null,
+ before entering a code block (either an if, or while statement) and then doesn't
+ reference that field or local in the block of code that is guarded by the null
+ check. Instead it references another object of the same type. It is likely that null
+ check is being done on the wrong variable, either because of a copy/paste error,
+ or a change in implementation.</li>
+ </ul>
+ </div>
+ <hr/>
+ <img id="v4_2_0_image" src="flip2.gif" onClick="toggleBlock('v4_2_0', 'v4_2_0_image');" align="top"/>
+ Detectors added in v4.2.0<br/>
+ <div id="v4_2_0" style="display:block;">
+ <ul>
<li><b>[PDP] Poorly Defined Parameter</b><br/>
Looks for non derivable methods that declare parameters and then cast those
parameters to more specific types in the method. This is misleading and dangerous
@@ -72,10 +90,6 @@
symmetry. If a equals b, then b equals a. While it is usually wrong to allow
equals to compare different types, at the very least you should make sure that
each class knows about each other and is able to compare themselves with each other.</li>
- <li><b>[CVAA] ContraVariant Array Assignment</b><br/>
- Looks for contravariant array assignments. Since arrays are mutable data structures, their use
- must be restricted to covariant or invariant usage.
- <span style="color: #0000FF;">--contributed by Bhaskar Maddala - THANKS!</span></li>
<li><b>[NFF] Non Functional Field</b><br/>
Looks for fields in serializable classes that are defined as both final and
transient. As a transient field is not initialized when streamed, and is not
@@ -84,18 +98,11 @@
Looks for a variety of questionable method calls that will cause problems, are unsafe
or use practices that might lead to bugs.
<span style="color: #0000FF;">--contributed by Chris Peterson - THANKS!</span></li>
- <li><b>[SNG] Suspicious Null Guard</b><br/>
- Looks for code that checks to see if a field or local variable is not null,
- before entering a code block (either an if, or while statement) and then doesn't
- reference that field or local in the block of code that is guarded by the null
- check. Instead it references another object of the same type. It is likely that null
- check is being done on the wrong variable, either because of a copy/paste error,
- or a change in implementation.</li>
</ul>
<ul>
<li><span style="color: #0000FF;">Maven pom file contributed by Grzegorz Slowikowski - THANKS!</span></li>
<ul>
- </div>
+ </div>
<hr/>
<img id="v4_0_0_image" src="flip1.gif" onClick="toggleBlock('v4_0_0', 'v4_0_0_image');" align="top"/>
Detectors added in v4.0.0<br/>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2010-01-12 06:15:01 UTC (rev 1480)
+++ trunk/fb-contrib/pom.xml 2010-01-14 05:31:35 UTC (rev 1481)
@@ -5,10 +5,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
+ <modelVersion>4.2.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>4.0.0</version>
+ <version>4.2.0</version>
<name>FindBugs Contrib plugin library</name>
<description>An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.</description>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: Grzegorz S. <gsl...@gm...> - 2010-01-14 07:56:49
|
Hi
1. I found a dummy error. Fix it in trunk and in tag. Details below.
2. Change version number to "4.3.0-SNAPSHOT" in trunk:
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
<version>4.3.0-SNAPSHOT</version>
Greetings
Grzegorz Slowikowski
On 2010-01-14 06:31, dbr...@us... wrote:
> Revision: 1481
> http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1481&view=rev
> Author: dbrosius
> Date: 2010-01-14 05:31:35 +0000 (Thu, 14 Jan 2010)
>
> Log Message:
> -----------
> get ready for the 4.2.0 release
>
> Modified Paths:
> --------------
> trunk/fb-contrib/build.xml
> trunk/fb-contrib/etc/findbugs.xml
> trunk/fb-contrib/htdocs/index.shtml
> trunk/fb-contrib/pom.xml
...
> Modified: trunk/fb-contrib/pom.xml
> ===================================================================
> --- trunk/fb-contrib/pom.xml 2010-01-12 06:15:01 UTC (rev 1480)
> +++ trunk/fb-contrib/pom.xml 2010-01-14 05:31:35 UTC (rev 1481)
> @@ -5,10 +5,10 @@
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
>
> -<modelVersion>4.0.0</modelVersion>
> +<modelVersion>4.2.0</modelVersion>
>
This is wrong, don't change model version. :-)
|
|
From: <dbr...@us...> - 2010-01-18 16:54:15
|
Revision: 1489
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1489&view=rev
Author: dbrosius
Date: 2010-01-18 16:54:08 +0000 (Mon, 18 Jan 2010)
Log Message:
-----------
new detector - just starting - ROOM
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/ROOM_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-01-15 05:46:10 UTC (rev 1488)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-01-18 16:54:08 UTC (rev 1489)
@@ -320,6 +320,10 @@
speed="fast"
reports="MDM_RUNTIME_EXIT_OR_HALT,MDM_RUNFINALIZATION,EQ_BIGDECIMAL_EQUALS,MDM_INETADDRESS_GETLOCALHOST,MDM_PROMISCUOUS_SERVERSOCKET,MDM_RANDOM_SEED,MDM_SECURERANDOM_CTOR,MDM_SECURERANDOM_GETSEED,MDM_THREAD_PRIORITIES,MDM_THREAD_YIELD,MDM_WAIT_WITHOUT_TIMEOUT,MDM_THREAD_FAIRNESS,MDM_REENTRANTLOCK_HELDBY,MDM_STRING_BYTES_ENCODING,MDM_SETDEFAULTLOCALE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ReflectionOnObjectMethods"
+ speed="fast"
+ reports="ROOM_REFLECTION_ON_OBJECT_METHODS" />
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING"
@@ -555,53 +559,55 @@
<BugPattern abbrev="ITU" type="ITU_INAPPROPRIATE_TOSTRING_USE"
category="CORRECTNESS" />
<BugPattern abbrev="IKNC" type="IKNC_INCONSISTENT_HTTP_ATTRIBUTE_CASING"
- category="STYLE" experimental="true" />
+ category="STYLE" />
<BugPattern abbrev="IKNC" type="IKNC_INCONSISTENT_HTTP_PARAM_CASING"
- category="STYLE" experimental="true" />
+ category="STYLE" />
<BugPattern abbrev="OC" type="OC_OVERZEALOUS_CASTING"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="PDP" type="PDP_POORLY_DEFINED_PARAMETER"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="NSE" type="NSE_NON_SYMMETRIC_EQUALS"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT"
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="CVAA" type="CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT"
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="NFF" type="NFF_NON_FUNCTIONAL_FIELD"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_FIELD_GUARD"
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="SNG" type="SNG_SUSPICIOUS_NULL_LOCAL_GUARD"
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="MDM" type="MDM_RUNTIME_EXIT_OR_HALT"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_RUNFINALIZATION"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_INETADDRESS_GETLOCALHOST"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_PROMISCUOUS_SERVERSOCKET"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_THREAD_PRIORITIES"
- category="MT_CORRECTNESS" experimental="true" />
+ category="MT_CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_THREAD_YIELD"
- category="MT_CORRECTNESS" experimental="true" />
+ category="MT_CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_WAIT_WITHOUT_TIMEOUT"
- category="MT_CORRECTNESS" experimental="true" />
+ category="MT_CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_SIGNAL_NOT_SIGNALALL"
- category="MT_CORRECTNESS" experimental="true" />
+ category="MT_CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_THREAD_FAIRNESS"
- category="MT_CORRECTNESS" experimental="true" />
+ category="MT_CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_LOCK_ISLOCKED"
- category="MT_CORRECTNESS" experimental="true" />
+ category="MT_CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_STRING_BYTES_ENCODING"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_SETDEFAULTLOCALE"
- category="MT_CORRECTNESS" experimental="true" />
+ category="MT_CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_BIGDECIMAL_EQUALS"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_RANDOM_SEED"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
<BugPattern abbrev="MDM" type="MDM_SECURERANDOM"
- category="CORRECTNESS" experimental="true" />
+ category="CORRECTNESS" />
+ <BugPattern abbrev="ROOM" type="ROOM_REFLECTION_ON_OBJECT_METHODS"
+ category="CORRECTNESS" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-01-15 05:46:10 UTC (rev 1488)
+++ trunk/fb-contrib/etc/messages.xml 2010-01-18 16:54:08 UTC (rev 1489)
@@ -453,7 +453,7 @@
</Details>
</Detector>
- <Detector class="com.mebigfatguy.fbcontrib.detect.DateComparison">
+ <Detector class="com.mebigfatguy.fbcontrib.detect.DateComparison">
<Details>
<![CDATA[
<p> Looks for inefficient comparison of Date objects using two comparisons when one would do.</p>
@@ -1099,6 +1099,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ReflectionOnObjectMethods">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for reflective calls on methods that are found java.lang.Object.
+ As these methods are always available, there is no reason to use reflection to call them.
+ </p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -2996,6 +3007,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="ROOM_REFLECTION_ON_OBJECT_METHODS">
+ <ShortDescription>Method uses reflection to call a method available on java.lang.Object</ShortDescription>
+ <LongDescription>Method {1} uses reflection to call a method available on java.lang.Object</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method uses reflection to call a method that is defined in java.lang.Object.
+ As these methods are always available, it is not necessary to call these methods with
+ reflection.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3089,4 +3112,5 @@
<BugCode abbrev="NFF">Non Functional Field</BugCode>
<BugCode abbrev="SNG">SUSPICIOUS Null Guard</BugCode>
<BugCode abbrev="MDM">More Dumb Methods</BugCode>
+ <BugCode abbrev="ROOM">Reflection on Object Methods</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/ROOM_Sample.java
===================================================================
--- trunk/fb-contrib/samples/ROOM_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/ROOM_Sample.java 2010-01-18 16:54:08 UTC (rev 1489)
@@ -0,0 +1,13 @@
+import java.lang.reflect.Method;
+
+
+public class ROOM_Sample
+{
+ public void testRoomWithLocals() throws Exception
+ {
+ Class c = Class.forName("java.lang.Object");
+ Method m = c.getMethod("equals", Object.class);
+
+ String s = (String)m.invoke(this, new ROOM_Sample());
+ }
+}
Property changes on: trunk/fb-contrib/samples/ROOM_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-18 16:54:08 UTC (rev 1489)
@@ -0,0 +1,202 @@
+package com.mebigfatguy.fbcontrib.detect;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.bcel.classfile.Code;
+
+import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+/**
+ * looks for method calls through reflection on methods found in
+ * java.lang.Object. As these methods are always available, there's no
+ * reason to do this.
+ */
+public class ReflectionOnObjectMethods extends BytecodeScanningDetector {
+
+ private static final Set<String> objectSigs = new HashSet<String>();
+ static {
+ objectSigs.add("clone()");
+ objectSigs.add("equals(Ljava/lang/Object;)");
+ objectSigs.add("finalize()");
+ objectSigs.add("getClass()");
+ objectSigs.add("hashCode()");
+ objectSigs.add("notify()");
+ objectSigs.add("notifyAll()");
+ objectSigs.add("toString()");
+ objectSigs.add("wait");
+ objectSigs.add("wait(J)");
+ objectSigs.add("wait(JI");
+
+
+ }
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ private Map<Integer, String[]> localClassTypes;
+
+ public ReflectionOnObjectMethods(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ localClassTypes = new HashMap<Integer, String[]>();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ localClassTypes = null;
+ }
+ }
+
+ @Override
+ public void visitCode(Code obj) {
+ stack.resetForMethodEntry(this);
+ localClassTypes.clear();
+ super.visitCode(obj);
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+ Integer arraySize = null;
+ String[] loadedTypes = null;
+
+ try {
+ switch (seen) {
+ case ANEWARRAY: {
+ if ("java/lang/Class".equals(getClassConstantOperand())) {
+ if (stack.getStackDepth() >= 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ arraySize = (Integer)item.getConstant();
+ }
+ }
+ }
+ break;
+
+ case AASTORE: {
+ if (stack.getStackDepth() >= 3) {
+ OpcodeStack.Item arrayItem = stack.getStackItem(2);
+ String[] arrayTypes = (String[])arrayItem.getUserValue();
+ if (arrayTypes != null) {
+ OpcodeStack.Item valueItem = stack.getStackItem(0);
+ String type = (String)valueItem.getConstant();
+ if (type != null) {
+ OpcodeStack.Item indexItem = stack.getStackItem(1);
+ Integer index = (Integer)indexItem.getConstant();
+ if (index != null) {
+ arrayTypes[index.intValue()] = type;
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ case ASTORE_0:
+ case ASTORE_1:
+ case ASTORE_2:
+ case ASTORE_3:
+ case ASTORE: {
+ if (stack.getStackDepth() >= 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ String[] arrayTypes = (String[])item.getUserValue();
+ if (arrayTypes != null) {
+ int reg = RegisterUtils.getAStoreReg(this, seen);
+ localClassTypes.put(Integer.valueOf(reg), arrayTypes);
+ }
+ }
+ }
+ break;
+
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3:
+ case ALOAD: {
+ int reg = RegisterUtils.getAStoreReg(this, seen);
+ loadedTypes = localClassTypes.get(Integer.valueOf(reg));
+ }
+ break;
+
+ case INVOKEVIRTUAL: {
+ String cls = getClassConstantOperand();
+ if ("java/lang/Class".equals(cls)) {
+ String method = getNameConstantOperand();
+ if ("getMethod".equals(method)) {
+ String sig = getSigConstantOperand();
+ if ("(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;".equals(sig)) {
+ if (stack.getStackDepth() >= 2) {
+ OpcodeStack.Item clsArgs = stack.getStackItem(0);
+ String[] arrayTypes = (String[])clsArgs.getUserValue();
+ if (arrayTypes != null) {
+ OpcodeStack.Item methodItem = stack.getStackItem(1);
+ String methodName = (String)methodItem.getConstant();
+ if (methodName != null) {
+ String reflectionSig = buildReflectionSignature(methodName, arrayTypes);
+ if (objectSigs.contains(reflectionSig)) {
+ loadedTypes = arrayTypes;
+ }
+ }
+ }
+ }
+ }
+ }
+ } else if ("java/lang/reflect/Method".equals(cls)) {
+ String method = getNameConstantOperand();
+ if ("invoke".equals(method)) {
+ if (stack.getStackDepth() >= 3) {
+ OpcodeStack.Item methodItem = stack.getStackItem(2);
+ String[] arrayTypes = (String[])methodItem.getUserValue();
+ if (arrayTypes != null) {
+ bugReporter.reportBug(new BugInstance(this, "ROOM_REFLECTION_ON_OBJECT_METHODS", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+ }
+ break;
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (arraySize != null) {
+ if (stack.getStackDepth() >= 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(new String[arraySize.intValue()]);
+ }
+ } else if (loadedTypes != null) {
+ if (stack.getStackDepth() >= 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(loadedTypes);
+ }
+ }
+ }
+ }
+
+ private String buildReflectionSignature(String methodName, String[] parmTypes) {
+ StringBuilder sb = new StringBuilder(64);
+ sb.append(methodName);
+ sb.append("(");
+ for (int i = 0; i < parmTypes.length; i++) {
+ sb.append("L");
+ String type = parmTypes[i];
+ sb.append(type);
+ if ((type.length() > 1) || ("IJ".indexOf(type) < 0))
+ sb.append(";");
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-24 00:42:58
|
Revision: 1507
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1507&view=rev
Author: dbrosius
Date: 2010-01-24 00:31:40 +0000 (Sun, 24 Jan 2010)
Log Message:
-----------
new Detector: IPU - Improper Properties use
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.shtml
Added Paths:
-----------
trunk/fb-contrib/samples/IPU_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ImproperPropertiesUse.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-01-23 23:50:15 UTC (rev 1506)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-01-24 00:31:40 UTC (rev 1507)
@@ -324,6 +324,10 @@
speed="fast"
reports="ROOM_REFLECTION_ON_OBJECT_METHODS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ImproperPropertiesUse"
+ speed="fast"
+ reports="IPU_IMPROPER_PROPERTIES_USE,IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY" />
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING"
@@ -610,4 +614,8 @@
category="CORRECTNESS" />
<BugPattern abbrev="ROOM" type="ROOM_REFLECTION_ON_OBJECT_METHODS"
category="CORRECTNESS" />
+ <BugPattern abbrev="IPU" type="IPU_IMPROPER_PROPERTIES_USE"
+ category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="IPU" type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY"
+ category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-01-23 23:50:15 UTC (rev 1506)
+++ trunk/fb-contrib/etc/messages.xml 2010-01-24 00:31:40 UTC (rev 1507)
@@ -1110,6 +1110,19 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ImproperPropertiesUse">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for java.util.Properties use where values other than String
+ are placed in the properties object. As the Properties object was intended to be a
+ String to String only collection, putting other types in the Properties object is
+ incorrect, and takes advantage of a poor design decision by the original Properties class
+ designers to derive from Hashtable, rather than using aggregation.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -3019,6 +3032,32 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="IPU_IMPROPER_PROPERTIES_USE">
+ <ShortDescription>Method puts non-String values into a Properties object</ShortDescription>
+ <LongDescription>Method {1} puts non-String values into a Properties object</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method places non-String objects into a Properties object. As the Properties object
+ is intented to be a String to String map, putting non String objects is wrong, and takes advantage
+ of a design flaw in the Properties class by deriving from Hashtable instead of using aggregation.
+ If you want a collection that holds other types of objects, use a Hashtable, or better still newer collections
+ like HashMap or TreeMap.
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY">
+ <ShortDescription>Method uses Properties.put instead of Properties.setProperty</ShortDescription>
+ <LongDescription>Method {1} uses Properties.put instead of Properties.setProperty</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method uses the inherited method from Hashtable put(String key, Object value) in
+ a Properties object. Since the Properties object was intended to be only a String to String
+ map, use of the derived put method is discouraged. Use the Properties.setProperty method instead.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3113,4 +3152,5 @@
<BugCode abbrev="SNG">Suspicious Null Guard</BugCode>
<BugCode abbrev="MDM">More Dumb Methods</BugCode>
<BugCode abbrev="ROOM">Reflection on Object Methods</BugCode>
+ <BugCode abbrev="IPU">Improper Properties use</BugCode>
</MessageCollection>
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-01-23 23:50:15 UTC (rev 1506)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-01-24 00:31:40 UTC (rev 1507)
@@ -69,6 +69,12 @@
<li><b>[ROOM] Reflection on Object Methods</b><br/>
Looks for method calls through reflection on methods found in java.lang.Object.
As these methods are always available, there's no reason to do this.</li>
+ <li><b>[IPU] Improper Properties Use</b><br/>
+ Looks for java.util.Properties use where values other than String are placed in
+ the properties object. As the Properties object was intended to be a String to
+ String only collection, putting other types in the Properties object is incorrect,
+ and takes advantage of a poor design decision by the original Properties class
+ designers to derive from Hashtable, rather than using aggregation.</li>
</ul>
</div>
<hr/>
Added: trunk/fb-contrib/samples/IPU_Sample.java
===================================================================
--- trunk/fb-contrib/samples/IPU_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/IPU_Sample.java 2010-01-24 00:31:40 UTC (rev 1507)
@@ -0,0 +1,24 @@
+import java.util.Properties;
+
+
+public class IPU_Sample
+{
+
+ public void testIPUSimple()
+ {
+ Properties p = new Properties();
+ p.put("Key", new Integer(0));
+ }
+
+ public void testIPUUseSetProperty(Object o)
+ {
+ Properties p = new Properties();
+ p.put("Key", o);
+ }
+
+ public void testIPUUseMinorSetProperty()
+ {
+ Properties p = new Properties();
+ p.put("Key", "Hello");
+ }
+}
Property changes on: trunk/fb-contrib/samples/IPU_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ImproperPropertiesUse.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ImproperPropertiesUse.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ImproperPropertiesUse.java 2010-01-24 00:31:40 UTC (rev 1507)
@@ -0,0 +1,100 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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 org.apache.bcel.classfile.Code;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+
+/**
+ * looks for java.util.Properties use where values other than String
+ * are placed in the properties object. As the Properties object was intended to be a
+ * String to String only collection, putting other types in the Properties object is
+ * incorrect, and takes advantage of a poor design decision by the original Properties class
+ * designers to derive from Hashtable, rather than using aggregation.
+ */
+public class ImproperPropertiesUse extends BytecodeScanningDetector {
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+
+ /**
+ * constructs a IPU detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public ImproperPropertiesUse(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ }
+ }
+
+ public void visitCode(Code obj) {
+ stack.resetForMethodEntry(this);
+ super.visitCode(obj);
+ }
+
+ public void sawOpcode(int seen) {
+ try {
+ if (seen == INVOKEVIRTUAL) {
+ String clsName = getClassConstantOperand();
+ if ("java/util/Properties".equals(clsName)) {
+ String methodName = getNameConstantOperand();
+ if ("put".equals(methodName)) {
+ String sig = getSigConstantOperand();
+ if ("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;".equals(sig)) {
+ if (stack.getStackDepth() >= 3) {
+ OpcodeStack.Item valueItem = stack.getStackItem(0);
+ String valueSig = valueItem.getSignature();
+ if ("Ljava/lang/String;".equals(valueSig)) {
+ bugReporter.reportBug(new BugInstance(this, "IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY", LOW_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ } else if (!"Ljava/lang/Object;".equals(valueSig)) {
+ bugReporter.reportBug(new BugInstance(this, "IPU_IMPROPER_PROPERTIES_USE", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ } else {
+ bugReporter.reportBug(new BugInstance(this, "IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+ }
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ImproperPropertiesUse.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-25 02:01:36
|
Revision: 1510
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1510&view=rev
Author: dbrosius
Date: 2010-01-25 02:01:27 +0000 (Mon, 25 Jan 2010)
Log Message:
-----------
add S508C_NON_TRANSLATABLE_STRING
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-01-24 16:48:56 UTC (rev 1509)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-01-25 02:01:27 UTC (rev 1510)
@@ -160,7 +160,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance"
speed="fast"
- reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE,S508C_NON_ACCESSIBLE_JCOMPONENT,S508C_SET_COMP_COLOR" />
+ reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE,S508C_NON_ACCESSIBLE_JCOMPONENT,S508C_SET_COMP_COLOR,S508C_NON_TRANSLATABLE_STRING" />
<Detector class="com.mebigfatguy.fbcontrib.detect.UseEnumCollections"
speed="fast" reports="UEC_USE_ENUM_COLLECTIONS" />
@@ -436,6 +436,8 @@
category="CORRECTNESS" />
<BugPattern abbrev="S508C" type="S508C_SET_COMP_COLOR"
category="CORRECTNESS" />
+ <BugPattern abbrev="S508C" type="S508C_NON_TRANSLATABLE_STRING"
+ category="CORRECTNESS" />
<BugPattern abbrev="UEC" type="UEC_USE_ENUM_COLLECTIONS"
category="PERFORMANCE" />
<BugPattern abbrev="SIL" type="SIL_SQL_IN_LOOP" category="PERFORMANCE" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-01-24 16:48:56 UTC (rev 1509)
+++ trunk/fb-contrib/etc/messages.xml 2010-01-25 02:01:27 UTC (rev 1510)
@@ -1870,6 +1870,18 @@
</Details>
</BugPattern>
+ <BugPattern type="S508C_NON_TRANSLATABLE_STRING">
+ <ShortDescription>Method passes constant string to title/label of component</ShortDescription>
+ <LongDescription>Method {1} passes constant string to title/label of component</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates a component and passes a string literal to the title or label
+ of the component. As this string will be shown to users, it should be internationalizable
+ through the use of a resource bundle.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
<BugPattern type="UEC_USE_ENUM_COLLECTIONS">
<ShortDescription>Class uses an ordinary set or map with an enum class as the key</ShortDescription>
<LongDescription>Class {0} uses an ordinary set or map with an enum class as the key</LongDescription>
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-24 16:48:56 UTC (rev 1509)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java 2010-01-25 02:01:27 UTC (rev 1510)
@@ -78,6 +78,18 @@
clsNFException = cnfe;
}
}
+
+ private static final Map<String, Integer> displayTextMethods = new HashMap<String, Integer>();
+ static {
+ displayTextMethods.put("javax/swing/JLabel#<init>(Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JLabel#<init>(Ljava/lang/String;Ljavax/swing/Icon;I)", Integer.valueOf(1));
+ displayTextMethods.put("javax/swing/JLabel#<init>(Ljava/lang/String;I)", Integer.valueOf(2));
+ displayTextMethods.put("javax/swing/JButton#<init>(Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JButton#<init>(Ljava/lang/String;Ljavax/swing/Icon;)", Integer.valueOf(1));
+ displayTextMethods.put("javax/swing/JFrame#<init>(Ljava/lang/String;)", Integer.valueOf(0));
+ displayTextMethods.put("javax/swing/JFrame#<init>(Ljava/lang/String;Ljava/awt/GraphicsConfiguration;)", Integer.valueOf(1));
+ }
+
private final BugReporter bugReporter;
private OpcodeStack stack;
private Set<XField> fieldLabels;
@@ -265,6 +277,28 @@
}
}
}
+
+ if ((seen == INVOKEVIRTUAL) || (seen == INVOKESPECIAL) || (seen == INVOKEINTERFACE)) {
+ StringBuilder methodInfo = new StringBuilder();
+ methodInfo.append(getClassConstantOperand());
+ methodInfo.append("#");
+ methodInfo.append(getNameConstantOperand());
+ String signature = getSigConstantOperand();
+ signature = signature.substring(0, signature.indexOf(')') + 1);
+ methodInfo.append(signature);
+ Integer parmIndex = displayTextMethods.get(methodInfo.toString());
+ if (parmIndex != null) {
+ if (stack.getStackDepth() >= parmIndex.intValue()) {
+ OpcodeStack.Item item = stack.getStackItem(parmIndex.intValue());
+ if (item.getConstant() != null) {
+ bugReporter.reportBug(new BugInstance(this, "S508C_NON_TRANSLATABLE_STRING", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-04-03 15:25:05
|
Revision: 1525
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1525&view=rev
Author: dbrosius
Date: 2010-04-03 15:24:59 +0000 (Sat, 03 Apr 2010)
Log Message:
-----------
add SPP check for calling System.arraycopy with a non array for either array parms
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/SPP_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-04-03 15:24:59 UTC (rev 1525)
@@ -209,7 +209,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri"
speed="fast"
- reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT,SPP_USELESS_TRINARY,SPP_SUSPECT_STRING_TEST,SPP_USE_STRINGBUILDER_LENGTH,SPP_INVALID_CALENDAR_COMPARE,SPP_USE_CONTAINSKEY,SPP_USE_ISEMPTY,SPP_USE_GETPROPERTY,SPP_USELESS_CASING" />
+ reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT,SPP_USELESS_TRINARY,SPP_SUSPECT_STRING_TEST,SPP_USE_STRINGBUILDER_LENGTH,SPP_INVALID_CALENDAR_COMPARE,SPP_USE_CONTAINSKEY,SPP_USE_ISEMPTY,SPP_USE_GETPROPERTY,SPP_USELESS_CASING,SPP_NON_ARRAY_PARM" />
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
@@ -327,7 +327,11 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.ImproperPropertiesUse"
speed="fast"
reports="IPU_IMPROPER_PROPERTIES_USE,IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY" />
-
+<!--
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop"
+ speed="fast"
+ reports="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP" />
+ -->
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING"
@@ -501,6 +505,7 @@
experimental="true" />
<BugPattern abbrev="SPP" type="SPP_SERIALVER_SHOULD_BE_PRIVATE"
category="STYLE" />
+ <BugPattern abbrev="SPP" type="SPP_NON_ARRAY_PARM" category="CORRECTNESS" />
<BugPattern abbrev="BAS" type="BAS_BLOATED_ASSIGNMENT_SCOPE"
category="PERFORMANCE" />
<BugPattern abbrev="SCII"
@@ -620,4 +625,6 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="IPU" type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY"
category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="PCAIL" type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP"
+ category="PERFORMANCE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/etc/messages.xml 2010-04-03 15:24:59 UTC (rev 1525)
@@ -1123,6 +1123,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for allocations of objects using the default constructor in a loop, where
+ the object allocated is never assigned to any object that is used outside the loop.
+ It is possible that this allocation can be done outside the loop to avoid excessive garbage.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -2321,6 +2332,18 @@
concern to case, the toUpperCase or toLowerCase calls are pointless and can be removed.
]]>
</Details>
+ </BugPattern>
+
+ <BugPattern type="SPP_NON_ARRAY_PARM">
+ <ShortDescription>method passes a non array object to a parameter that expects an array</ShortDescription>
+ <LongDescription>method {1} passes a non array object to a parameter that expects an array</LongDescription>
+ <Details>
+ <![CDATA[
+ This method expects an array to be passed as one of its parameters, but unfortunately defines
+ the parameter as Object. This invocation of this method does not pass an array and will throw
+ an exception when run.
+ ]]>
+ </Details>
</BugPattern>
<BugPattern type="BAS_BLOATED_ASSIGNMENT_SCOPE">
@@ -3059,7 +3082,7 @@
</Details>
</BugPattern>
- <BugPattern type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY">
+ <BugPattern type="IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY">
<ShortDescription>Method uses Properties.put instead of Properties.setProperty</ShortDescription>
<LongDescription>Method {1} uses Properties.put instead of Properties.setProperty</LongDescription>
<Details>
@@ -3070,6 +3093,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP">
+ <ShortDescription>Method allocates an object that is used in a constant way in a loop</ShortDescription>
+ <LongDescription>Method {1} allocates an object that is used in a constant way in a loop</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method allocates an object using the default constructor in a loop, and then
+ only uses it in a quasi-static way. It is never assigned to anything that lives outside
+ the loop, and could potentially be allocated once outside the loop.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3165,4 +3200,5 @@
<BugCode abbrev="MDM">More Dumb Methods</BugCode>
<BugCode abbrev="ROOM">Reflection on Object Methods</BugCode>
<BugCode abbrev="IPU">Improper Properties use</BugCode>
+ <BugCode abbrev="PCAIL">Possible Constant Allocation In Loop</BugCode>
</MessageCollection>
Modified: trunk/fb-contrib/samples/SPP_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SPP_Sample.java 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/samples/SPP_Sample.java 2010-04-03 15:24:59 UTC (rev 1525)
@@ -6,6 +6,7 @@
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
@@ -292,4 +293,12 @@
i = (int) r.nextFloat();
}
+
+ public void testSAC(List<String> input)
+ {
+ String[] copy = new String[input.size()];
+ System.arraycopy(input, 0, copy, 0, copy.length);
+
+ System.arraycopy(copy, 0, input, 0, copy.length);
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-03-15 05:46:12 UTC (rev 1524)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2010-04-03 15:24:59 UTC (rev 1525)
@@ -377,9 +377,27 @@
String className = getClassConstantOperand();
String methodName = getNameConstantOperand();
if ("java/lang/System".equals(className)) {
- if ("getProperties".equals(methodName))
- {
+ if ("getProperties".equals(methodName)) {
userValue = "getProperties";
+ } else if ("arraycopy".equals(methodName)) {
+ if (stack.getStackDepth() >= 5) {
+ OpcodeStack.Item item = stack.getStackItem(2);
+ String sig = item.getSignature();
+ if ((sig.charAt(0) != '[') && !"Ljava/lang/Object;".equals(sig)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_NON_ARRAY_PARM", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ item = stack.getStackItem(4);
+ sig = item.getSignature();
+ if ((sig.charAt(0) != '[') && !"Ljava/lang/Object;".equals(sig)) {
+ bugReporter.reportBug(new BugInstance(this, "SPP_NON_ARRAY_PARM", HIGH_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
}
}
} else if (seen == INVOKEVIRTUAL) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-07 08:30:34
|
Revision: 1545
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1545&view=rev
Author: dbrosius
Date: 2010-05-07 08:30:28 +0000 (Fri, 07 May 2010)
Log Message:
-----------
initial checkin, new WOC detector
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/WOC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-04-24 01:53:11 UTC (rev 1544)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-05-07 08:30:28 UTC (rev 1545)
@@ -331,6 +331,10 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop"
speed="fast"
reports="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection"
+ speed="fast"
+ reports="WOC_WRITE_ONLY_COLLECTION" />
<!-- BugPattern -->
@@ -627,4 +631,6 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="PCAIL" type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP"
category="PERFORMANCE" experimental="true" />
+ <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION"
+ category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-04-24 01:53:11 UTC (rev 1544)
+++ trunk/fb-contrib/etc/messages.xml 2010-05-07 08:30:28 UTC (rev 1545)
@@ -1134,6 +1134,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for allocations and initializations of java collections, but that are never
+ read from or accessed to gain information. This represents a collection of no use, and most probably
+ can be removed. It is similar to a dead local store.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -3107,6 +3118,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="WOC_WRITE_ONLY_COLLECTION">
+ <ShortDescription>Method creates and initializes a collection but never reads or gains information from it</ShortDescription>
+ <LongDescription>Method {1} creates and initializes a collection but never reads or gains information from it</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates and initializes a collection but then never access this collection
+ to gain information, or fetch items from the collection. It is likely that this collection
+ is left over from a past effort, and can be removed.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3203,4 +3226,5 @@
<BugCode abbrev="ROOM">Reflection on Object Methods</BugCode>
<BugCode abbrev="IPU">Improper Properties use</BugCode>
<BugCode abbrev="PCAIL">Possible Constant Allocation In Loop</BugCode>
+ <BugCode abbrev="WOC">Write Only Collection</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2010-05-07 08:30:28 UTC (rev 1545)
@@ -0,0 +1,40 @@
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+public class WOC_Sample
+{
+ public void testWOCSimple()
+ {
+ Set<String> s = new HashSet<String>();
+ s.add("Foo");
+ }
+
+ public Map<String, String> testFPWOCReturn()
+ {
+ Map<String, String> m = new HashMap<String, String>();
+ m.put("Foo", "Bar");
+ return m;
+ }
+
+ public void testFPWOCAsParm()
+ {
+ Map<String, String> m = new HashMap<String, String>();
+ m.put("Foo", "Bar");
+ helper(0, m);
+ }
+
+ public void testFPWOCCopy()
+ {
+ Set<String> s = new LinkedHashSet<String>();
+ s.add("foo");
+ Set<String> c = s;
+ }
+
+ private void helper(int i, Map<String, String> x)
+ {
+ }
+}
Property changes on: trunk/fb-contrib/samples/WOC_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-07 08:30:28 UTC (rev 1545)
@@ -0,0 +1,288 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.generic.Type;
+
+import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.OpcodeStack.Item;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.ba.XField;
+
+public class WriteOnlyCollection extends BytecodeScanningDetector {
+
+ private static Set<String> collectionClasses = new HashSet<String>();
+ static
+ {
+ collectionClasses.add(HashSet.class.getName());
+ collectionClasses.add(TreeSet.class.getName());
+ collectionClasses.add(LinkedHashSet.class.getName());
+ collectionClasses.add(HashMap.class.getName());
+ collectionClasses.add(TreeMap.class.getName());
+ collectionClasses.add(Hashtable.class.getName());
+ collectionClasses.add(LinkedHashMap.class.getName());
+ collectionClasses.add(Vector.class.getName());
+ collectionClasses.add(ArrayList.class.getName());
+ collectionClasses.add(LinkedList.class.getName());
+ }
+
+ private static Set<String> writeMethods = new HashSet<String>();
+ static
+ {
+ writeMethods.add("add");
+ writeMethods.add("addAll");
+ writeMethods.add("addElement");
+ writeMethods.add("addFirst");
+ writeMethods.add("addLast");
+ writeMethods.add("clear");
+ writeMethods.add("clone");
+ writeMethods.add("ensureCapacity");
+ writeMethods.add("insertElementAt");
+ writeMethods.add("put");
+ writeMethods.add("putAll");
+ writeMethods.add("remove");
+ writeMethods.add("removeAll");
+ writeMethods.add("removeElement");
+ writeMethods.add("removeElementAt");
+ writeMethods.add("removeRange");
+ writeMethods.add("set");
+ writeMethods.add("setElementAt");
+ writeMethods.add("setSize");
+ writeMethods.add("trimToSize");
+ }
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+ /** register to first allocation PC */
+ private Map<Integer, Integer> localWOCollections;
+ /** field to first allocation PC */
+ private Map<String, Integer> fieldWOCollections;
+
+
+ /**
+ * constructs a WOC detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public WriteOnlyCollection(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+ /**
+ * overrides the visitor to initialize and tear down the opcode stack
+ *
+ * @param classContext the context object of the currently parsed class
+ */
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ localWOCollections = new HashMap<Integer, Integer>();
+ fieldWOCollections = new HashMap<String, Integer>();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ localWOCollections = null;
+ fieldWOCollections = null;
+ }
+ }
+
+ /**
+ * overrides the visitor reset the stack
+ *
+ * @param obj the context object of the currently parsed code block
+ */
+ @Override
+ public void visitCode(Code obj) {
+ stack.resetForMethodEntry(this);
+ localWOCollections.clear();
+ super.visitCode(obj);
+
+ for (Integer pc : localWOCollections.values()) {
+ bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this, pc.intValue()));
+ }
+ }
+
+ /**
+ * overrides the visitor to look for uses of collections where the only access to
+ * to the collection is to write to it
+ *
+ * @param seen the opcode of the currently visited instruction
+ */
+ @Override
+ public void sawOpcode(int seen) {
+ Object userObject = null;
+
+ try {
+ switch (seen) {
+ case INVOKESPECIAL:
+ String methodName = getNameConstantOperand();
+ if ("<init>".equals(methodName)) {
+ String clsName = getClassConstantOperand().replace('/', '.');
+ if (collectionClasses.contains(clsName))
+ userObject = Boolean.TRUE;
+ }
+ processMethodParms();
+ break;
+
+ case INVOKEINTERFACE:
+ case INVOKEVIRTUAL:
+ String sig = getSigConstantOperand();
+ int numParms = Type.getArgumentTypes(sig).length;
+ if (stack.getStackDepth() > numParms) {
+ OpcodeStack.Item item = stack.getStackItem(numParms);
+ Object uo = item.getUserValue();
+ if (uo != null) {
+ String name = getNameConstantOperand();
+ if (!writeMethods.contains(name)) {
+ clearUserValue(item);
+ }
+ }
+ }
+ processMethodParms();
+ break;
+
+ case INVOKESTATIC:
+ processMethodParms();
+ break;
+
+ case ARETURN:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ clearUserValue(item);
+ }
+ break;
+
+ case ASTORE_0:
+ case ASTORE_1:
+ case ASTORE_2:
+ case ASTORE_3:
+ case ASTORE:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ Object uo = item.getUserValue();
+ if (uo != null) {
+ if (uo instanceof Boolean) {
+ int reg = RegisterUtils.getAStoreReg(this, seen);
+ localWOCollections.put(reg, Integer.valueOf(getPC()));
+ } else {
+ clearUserValue(item);
+ }
+ }
+ }
+ break;
+
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3:
+ case ALOAD:
+ int reg = RegisterUtils.getALoadReg(this, seen);
+ if (localWOCollections.containsKey(Integer.valueOf(reg))) {
+ userObject = Integer.valueOf(reg);
+ }
+ break;
+
+ case PUTFIELD:
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ Object uo = item.getUserValue();
+ if (uo != null) {
+ if (uo instanceof Boolean) {
+ Item fieldItem = stack.getStackItem(1);
+ boolean storedInThis = fieldItem.getRegisterNumber() == 0;
+ if (storedInThis) {
+ XField field = getXFieldOperand();
+ if ((field.getAccessFlags() & Constants.ACC_PRIVATE) != 0) {
+ String fieldName = field.getName();
+ fieldWOCollections.put(fieldName, getPC());
+ }
+ }
+ } else {
+ clearUserValue(item);
+ }
+ }
+ }
+ break;
+
+ case GETFIELD:
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (item.getRegisterNumber() == 0) {
+ XField field = getXFieldOperand();
+ String fieldName = field.getName();
+ if (fieldWOCollections.containsKey(fieldName)) {
+ userObject = fieldName;
+ }
+ }
+ }
+ break;
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (userObject != null) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(userObject);
+ }
+ }
+ }
+ }
+
+ private void clearUserValue(OpcodeStack.Item item) {
+ Object uo = item.getUserValue();
+ if (uo instanceof Integer) {
+ localWOCollections.remove(uo);
+ } else if (uo instanceof String) {
+ fieldWOCollections.remove(uo);
+ }
+ item.setUserValue(null);
+ }
+
+ private void processMethodParms() {
+ String sig = getSigConstantOperand();
+ int numParms = Type.getArgumentTypes(sig).length;
+ if (stack.getStackDepth() >= numParms) {
+ for (int i = 0; i < numParms; i++) {
+ clearUserValue(stack.getStackItem(i));
+ }
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-08 21:34:26
|
Revision: 1552
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1552&view=rev
Author: dbrosius
Date: 2010-05-08 21:34:19 +0000 (Sat, 08 May 2010)
Log Message:
-----------
improve WOC handling of collections that are fields
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/WOC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-05-08 21:34:19 UTC (rev 1552)
@@ -334,7 +334,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection"
speed="fast"
- reports="WOC_WRITE_ONLY_COLLECTION" />
+ reports="WOC_WRITE_ONLY_COLLECTION_LOCAL,WOC_WRITE_ONLY_COLLECTION_FIELD" />
<!-- BugPattern -->
@@ -631,6 +631,8 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="PCAIL" type="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP"
category="PERFORMANCE" experimental="true" />
- <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION"
+ <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_LOCAL"
category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_FIELD"
+ category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/etc/messages.xml 2010-05-08 21:34:19 UTC (rev 1552)
@@ -3119,7 +3119,7 @@
</Details>
</BugPattern>
- <BugPattern type="WOC_WRITE_ONLY_COLLECTION">
+ <BugPattern type="WOC_WRITE_ONLY_COLLECTION_LOCAL">
<ShortDescription>Method creates and initializes a collection but never reads or gains information from it</ShortDescription>
<LongDescription>Method {1} creates and initializes a collection but never reads or gains information from it</LongDescription>
<Details>
@@ -3130,6 +3130,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="WOC_WRITE_ONLY_COLLECTION_FIELD">
+ <ShortDescription>Class creates and initializes a collection but never reads or gains information from it</ShortDescription>
+ <LongDescription>Class {0} creates and initializes a collection but never reads or gains information from it</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This class creates and initializes a collection as a field but then never access this collection
+ to gain information, or fetch items from the collection. It is likely that this collection
+ is left over from a past effort, and can be removed.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
Modified: trunk/fb-contrib/samples/WOC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/samples/WOC_Sample.java 2010-05-08 21:34:19 UTC (rev 1552)
@@ -10,12 +10,16 @@
public class WOC_Sample
{
private Set<String> memberSet = new HashSet<String>();
+ private Set<String> fpSet;
public void testWOCSimple()
{
Set<String> s = new HashSet<String>();
s.add("Foo");
memberSet.add("fee");
+ if (fpSet.retainAll(new HashSet<String>())) {
+ System.out.println("woops");
+ }
}
public Map<String, String> testFPWOCReturn()
@@ -23,6 +27,7 @@
Map<String, String> m = new HashMap<String, String>();
m.put("Foo", "Bar");
memberSet.add("fi");
+ fpSet = new HashSet<String>();
return m;
}
@@ -31,6 +36,7 @@
Map<String, String> m = new HashMap<String, String>();
m.put("Foo", "Bar");
memberSet.add("fo");
+ fpSet.add("boo");
helper(0, m);
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 04:30:13 UTC (rev 1551)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WriteOnlyCollection.java 2010-05-08 21:34:19 UTC (rev 1552)
@@ -19,20 +19,24 @@
package com.mebigfatguy.fbcontrib.detect;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.SortedMap;
+import java.util.SortedSet;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.Vector;
-import org.apache.bcel.Constants;
import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.Field;
import org.apache.bcel.generic.Type;
import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
@@ -41,7 +45,6 @@
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
-import edu.umd.cs.findbugs.OpcodeStack.Item;
import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XField;
@@ -50,6 +53,12 @@
private static Set<String> collectionClasses = new HashSet<String>();
static
{
+ collectionClasses.add(Set.class.getName());
+ collectionClasses.add(Map.class.getName());
+ collectionClasses.add(List.class.getName());
+ collectionClasses.add(SortedSet.class.getName());
+ collectionClasses.add(SortedMap.class.getName());
+ collectionClasses.add(Collection.class.getName());
collectionClasses.add(HashSet.class.getName());
collectionClasses.add(TreeSet.class.getName());
collectionClasses.add(LinkedHashSet.class.getName());
@@ -91,8 +100,8 @@
private OpcodeStack stack;
/** register to first allocation PC */
private Map<Integer, Integer> localWOCollections;
- /** field to first allocation PC */
- private Map<String, Integer> fieldWOCollections;
+ /** fieldname to field sig */
+ private Map<String, String> fieldWOCollections;
/**
@@ -112,13 +121,18 @@
try {
stack = new OpcodeStack();
localWOCollections = new HashMap<Integer, Integer>();
- fieldWOCollections = new HashMap<String, Integer>();
+ fieldWOCollections = new HashMap<String, String>();
super.visitClassContext(classContext);
- for (Integer pc : fieldWOCollections.values()) {
- bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
- .addClass(this)
- .addSourceLine(this, pc.intValue()));
+ if (fieldWOCollections.size() > 0) {
+ String clsName = classContext.getJavaClass().getClassName();
+ for (Map.Entry<String, String> entry : fieldWOCollections.entrySet()) {
+ String fieldName = entry.getKey();
+ String signature = entry.getValue();
+ bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION_FIELD", NORMAL_PRIORITY)
+ .addClass(this)
+ .addField(clsName, fieldName, signature, false));
+ }
}
} finally {
stack = null;
@@ -126,6 +140,19 @@
fieldWOCollections = null;
}
}
+
+ @Override
+ public void visitField(Field obj) {
+ if (obj.isPrivate()) {
+ String sig = obj.getSignature();
+ if (sig.startsWith("L")) {
+ String type = sig.substring(1, sig.length() - 1).replace('/', '.');
+ if (collectionClasses.contains(type)) {
+ fieldWOCollections.put(obj.getName(), obj.getSignature());
+ }
+ }
+ }
+ }
/**
* overrides the visitor reset the stack
@@ -139,8 +166,7 @@
super.visitCode(obj);
for (Integer pc : localWOCollections.values()) {
- bugReporter.reportBug(new BugInstance(this,
-"WOC_WRITE_ONLY_COLLECTION", NORMAL_PRIORITY)
+ bugReporter.reportBug(new BugInstance(this, "WOC_WRITE_ONLY_COLLECTION_LOCAL", NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
.addSourceLine(this, pc.intValue()));
@@ -246,20 +272,8 @@
if (stack.getStackDepth() > 1) {
OpcodeStack.Item item = stack.getStackItem(0);
Object uo = item.getUserValue();
- if (uo != null) {
- if (uo instanceof Boolean) {
- Item fieldItem = stack.getStackItem(1);
- boolean storedInThis = fieldItem.getRegisterNumber() == 0;
- if (storedInThis) {
- XField field = getXFieldOperand();
- if ((field.getAccessFlags() & Constants.ACC_PRIVATE) != 0) {
- String fieldName = field.getName();
- fieldWOCollections.put(fieldName, getPC());
- }
- }
- } else {
- clearUserValue(item);
- }
+ if (!(uo instanceof Boolean)) {
+ clearUserValue(item);
}
}
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-19 05:31:20
|
Revision: 1559
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1559&view=rev
Author: dbrosius
Date: 2010-05-19 05:31:14 +0000 (Wed, 19 May 2010)
Log Message:
-----------
new detector UVA
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/UVA_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-05-11 03:50:30 UTC (rev 1558)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-05-19 05:31:14 UTC (rev 1559)
@@ -335,6 +335,10 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection"
speed="fast"
reports="WOC_WRITE_ONLY_COLLECTION_LOCAL,WOC_WRITE_ONLY_COLLECTION_FIELD" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs"
+ speed="fast"
+ reports="UVA_USE_VAR_ARGS" />
<!-- BugPattern -->
@@ -635,4 +639,6 @@
category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_FIELD"
category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="UVA" type="UVA_USE_VAR_ARGS"
+ category="STYLE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-05-11 03:50:30 UTC (rev 1558)
+++ trunk/fb-contrib/etc/messages.xml 2010-05-19 05:31:14 UTC (rev 1559)
@@ -1145,6 +1145,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for definitions of methods that have an array as the last parameter.
+ Since this class is compiled with java 1.5 or better, it would be more flexible for clients of this
+ method to define this parameter as a vararg parameter</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -3142,6 +3153,18 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="UVA_USE_VAR_ARGS">
+ <ShortDescription>Method defines parameter list with array as last argument, rather than vararg</ShortDescription>
+ <LongDescription>Method {1} defines parameter list with array as last argument, rather than vararg</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method defines a parameter list that ends with an array. As this class is compiled with
+ Java 1.5 or better, this parameter could be defined as a vararg parameter instead, which can be
+ more convienent for client developers to use. This is not a bug, per se, just an improvement.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3239,4 +3262,5 @@
<BugCode abbrev="IPU">Improper Properties use</BugCode>
<BugCode abbrev="PCAIL">Possible Constant Allocation In Loop</BugCode>
<BugCode abbrev="WOC">Write Only Collection</BugCode>
+ <BugCode abbrev="UVA">Use Var Args</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/UVA_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UVA_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/UVA_Sample.java 2010-05-19 05:31:14 UTC (rev 1559)
@@ -0,0 +1,36 @@
+import java.util.ArrayList;
+import java.util.Date;
+
+
+public class UVA_Sample<T> extends ArrayList<T>
+{
+ public void testNormalUVA(String[] foo)
+ {}
+
+ public void testLowUVA1(int boo, int[] hoo)
+ {}
+
+ public void testLowUVA2(int boo, String hoo, Date[] woo)
+ {}
+
+ public static void testStaticUVA(Date[] d)
+ {}
+
+ public void fpNoParms()
+ {}
+
+ public void fpHasOtherArrayUVA1(String[] one, int[] two)
+ {}
+
+ public void fpTooManyArgs(int i, char j, long k, String[] moo)
+ {}
+
+ public void fpNotAtEnd(String[] foo, int bar)
+ {}
+
+ @Override
+ public <T> T[] toArray(T[] a)
+ {
+ return null;
+ }
+}
Property changes on: trunk/fb-contrib/samples/UVA_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 05:31:14 UTC (rev 1559)
@@ -0,0 +1,118 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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 org.apache.bcel.Constants;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
+import org.apache.bcel.generic.Type;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.Detector;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.visitclass.PreorderVisitor;
+
+public class UseVarArgs extends PreorderVisitor implements Detector
+{
+ private BugReporter bugReporter;
+ private JavaClass javaClass;
+
+ public UseVarArgs(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ javaClass = classContext.getJavaClass();
+ if (javaClass.getMajor() >= Constants.MAJOR_1_5) {
+ javaClass.accept(this);
+ }
+ } finally {
+ javaClass = null;
+ }
+ }
+
+ public void visitMethod(Method obj) {
+ try {
+ if (obj.isSynthetic()) {
+ return;
+ }
+
+ Type[] types = obj.getArgumentTypes();
+ if ((types.length == 0) || (types.length > 3)) {
+ return;
+ }
+
+ String lastParmSig = types[types.length-1].getSignature();
+ if (!lastParmSig.startsWith("[") || lastParmSig.startsWith("[[")) {
+ return;
+ }
+
+ if (obj.isStatic() && "main".equals(obj.getName()) && "([Ljava/lang/String;)V".equals(obj.getSignature())) {
+ return;
+ }
+
+ if (!obj.isPrivate() && !obj.isStatic() && isInherited(obj)) {
+ return;
+ }
+
+ super.visitMethod(obj);
+ bugReporter.reportBug(new BugInstance(this, "UVA_USE_VAR_ARGS", (types.length == 1) ? NORMAL_PRIORITY : LOW_PRIORITY)
+ .addClass(this)
+ .addMethod(this));
+
+
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
+ }
+ }
+
+ public void report() {
+ }
+
+ private boolean isInherited(Method m) throws ClassNotFoundException {
+ JavaClass[] infs = javaClass.getAllInterfaces();
+ for (JavaClass inf : infs) {
+ if (hasMethod(inf, m))
+ return true;
+ }
+
+ JavaClass[] sups = javaClass.getSuperClasses();
+ for (JavaClass sup : sups) {
+ if (hasMethod(sup, m))
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean hasMethod(JavaClass c, Method candidateMethod) {
+ String name = candidateMethod.getName();
+ String sig = candidateMethod.getSignature();
+
+ for (Method method : c.getMethods()) {
+ if (!method.isStatic() && method.getName().equals(name) && method.getSignature().equals(sig)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-05-20 01:46:19
|
Revision: 1562
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1562&view=rev
Author: dbrosius
Date: 2010-05-20 01:46:12 +0000 (Thu, 20 May 2010)
Log Message:
-----------
don't report if the non var args parm is similar to the would be varargs parm
Modified Paths:
--------------
trunk/fb-contrib/samples/UVA_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
Modified: trunk/fb-contrib/samples/UVA_Sample.java
===================================================================
--- trunk/fb-contrib/samples/UVA_Sample.java 2010-05-19 13:06:39 UTC (rev 1561)
+++ trunk/fb-contrib/samples/UVA_Sample.java 2010-05-20 01:46:12 UTC (rev 1562)
@@ -7,12 +7,9 @@
public void testNormalUVA(String[] foo)
{}
- public void testLowUVA1(int boo, int[] hoo)
+ public void testLowUVA1(int boo, String[] hoo)
{}
- public void testLowUVA2(int boo, String hoo, Date[] woo)
- {}
-
public static void testStaticUVA(Date[] d)
{}
@@ -28,6 +25,12 @@
public void fpNotAtEnd(String[] foo, int bar)
{}
+ public void fpAlreadyVarArg(String...darnit)
+ {}
+
+ public void fpSimilarVarArg(String info, String...data)
+ {}
+
@Override
public <T> T[] toArray(T[] a)
{
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-19 13:06:39 UTC (rev 1561)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2010-05-20 01:46:12 UTC (rev 1562)
@@ -56,7 +56,7 @@
}
Type[] types = obj.getArgumentTypes();
- if ((types.length == 0) || (types.length > 3)) {
+ if ((types.length == 0) || (types.length > 2)) {
return;
}
@@ -69,10 +69,8 @@
return;
}
- for (int i = 0; i < types.length - 1; i++) {
- if (types[i].getSignature().startsWith("[")) {
- return;
- }
+ if (hasSimilarParms(types)) {
+ return;
}
if (obj.isStatic() && "main".equals(obj.getName()) && "([Ljava/lang/String;)V".equals(obj.getSignature())) {
@@ -97,6 +95,28 @@
public void report() {
}
+ private boolean hasSimilarParms(Type[] argTypes) {
+
+ for (int i = 0; i < argTypes.length - 1; i++) {
+ if (argTypes[i].getSignature().startsWith("[")) {
+ return true;
+ }
+ }
+
+ String baseType = argTypes[argTypes.length-1].getSignature();
+ while (baseType.startsWith("[")) {
+ baseType = baseType.substring(1);
+ }
+
+ for (int i = 0; i < argTypes.length - 1; i++) {
+ if (argTypes[i].getSignature().equals(baseType)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private boolean isInherited(Method m) throws ClassNotFoundException {
JavaClass[] infs = javaClass.getAllInterfaces();
for (JavaClass inf : infs) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-06-05 23:55:52
|
Revision: 1565
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1565&view=rev
Author: dbrosius
Date: 2010-06-05 23:55:43 +0000 (Sat, 05 Jun 2010)
Log Message:
-----------
get ready for the 4.4.0 release
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/htdocs/mbfg_menu.shtml
trunk/fb-contrib/pom.xml
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/build.xml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -20,7 +20,7 @@
<property name="javac.deprecation" value="on"/>
<property name="javac.debug" value="on"/>
- <property name="fb-contrib.version" value="4.3.0"/>
+ <property name="fb-contrib.version" value="4.4.0"/>
<target name="clean" description="removes all generated collateral">
<delete dir="${classes.dir}"/>
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -113,9 +113,10 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.CustomBuiltXML"
speed="fast" reports="CBX_CUSTOM_BUILT_XML" />
+<!--
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedSynchronizedBlock"
speed="fast" reports="BSB_BLOATED_SYNCHRONIZED_BLOCK" hidden="true" />
-
+-->
<Detector class="com.mebigfatguy.fbcontrib.detect.ConstantListIndex"
speed="fast" reports="CLI_CONSTANT_LIST_INDEX" />
@@ -279,14 +280,14 @@
<Detector
class="com.mebigfatguy.fbcontrib.detect.DeprecatedTypesafeEnumPattern"
speed="fast" reports="DTEP_DEPRECATED_TYPESAFE_ENUM_PATTERN" />
-
+<!--
<Detector class="com.mebigfatguy.fbcontrib.detect.StutteredMethodArguments"
speed="fast" reports="SMA_STUTTERED_METHOD_ARGUMENTS" hidden="true" />
+-->
<Detector class="com.mebigfatguy.fbcontrib.detect.TristateBooleanPattern"
speed="fast" reports="TBP_TRISTATE_BOOLEAN_PATTERN" />
-
<Detector
class="com.mebigfatguy.fbcontrib.detect.SuspiciousUninitializedArray"
speed="fast" reports="SUA_SUSPICIOUS_UNINITIALIZED_ARRAY" />
@@ -306,16 +307,18 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NonSymmetricEquals"
speed="fast" reports="NSE_NON_SYMMETRIC_EQUALS" />
+<!--
<Detector
class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment"
speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" />
-
+ -->
+
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField"
speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
-
+<!--
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard"
speed="fast" hidden="true" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
-
+-->
<Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods"
speed="fast"
reports="MDM_RUNTIME_EXIT_OR_HALT,MDM_RUNFINALIZATION,MDM_BIGDECIMAL_EQUALS,MDM_INETADDRESS_GETLOCALHOST,MDM_PROMISCUOUS_SERVERSOCKET,MDM_RANDOM_SEED,MDM_SECURERANDOM_CTOR,MDM_SECURERANDOM_GETSEED,MDM_THREAD_PRIORITIES,MDM_THREAD_YIELD,MDM_WAIT_WITHOUT_TIMEOUT,MDM_THREAD_FAIRNESS,MDM_REENTRANTLOCK_HELDBY,MDM_STRING_BYTES_ENCODING,MDM_SETDEFAULTLOCALE" />
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -51,9 +51,9 @@
<a href="bugdescriptions.html">Bug Descriptions</a>
<!--#include virtual="mbfg_menu.shtml" -->
<hr/>
- <img id="svn_image" src="flip2.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
+ <img id="svn_image" src="flip1.gif" onClick="toggleBlock('svn', 'svn_image');" align="top"/>
Detectors added in svn<br/>
- <div id="svn" style="display:block;">
+ <div id="svn" style="display:none">
<ul>
<li><b>[CVAA] ContraVariant Array Assignment</b><br/>
Looks for contravariant array assignments. Since arrays are mutable data structures, their use
@@ -66,6 +66,13 @@
check. Instead it references another object of the same type. It is likely that null
check is being done on the wrong variable, either because of a copy/paste error,
or a change in implementation.</li>
+ </ul>
+ </div>
+ <hr/>
+ <img id="v4_4_0_image" src="flip2.gif" onClick="toggleBlock('v4_4_0', 'v4_4_0_image');" align="top"/>
+ Detectors added in v4.4.0<br/>
+ <div id="v4_4_0" style="display:block;">
+ <ul>
<li><b>[ROOM] Reflection on Object Methods</b><br/>
Looks for method calls through reflection on methods found in java.lang.Object.
As these methods are always available, there's no reason to do this.</li>
Modified: trunk/fb-contrib/htdocs/mbfg_menu.shtml
===================================================================
--- trunk/fb-contrib/htdocs/mbfg_menu.shtml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/htdocs/mbfg_menu.shtml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -10,7 +10,8 @@
<li><a href="http://pixelle.sf.net">Pixelle</a></li>
<li><a href="http://polycasso.sf.net">Polycasso</a></li>
<li><a href="http://schemalizer.sf.net">Schemalizer</a></li>
- <li><a href="http://tomailer.sf.net">ToMailer</a></li>
+ <li><a href="http://tomailer.sf.net">ToMailer</a></li>
+ <li><a href="http://jd4a.sf.net">JavaDoc for Android</a></li>
<li><a href="http://www.heartofgoldfarm.com">Heart of Gold Farm</a></li>
</ul>
</div>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2010-05-25 03:30:23 UTC (rev 1564)
+++ trunk/fb-contrib/pom.xml 2010-06-05 23:55:43 UTC (rev 1565)
@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>4.3.0-SNAPSHOT</version>
+ <version>4.4.0-SNAPSHOT</version>
<name>FindBugs Contrib plugin library</name>
<description>An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.</description>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-07-16 04:17:20
|
Revision: 1579
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1579&view=rev
Author: dbrosius
Date: 2010-07-16 04:17:14 +0000 (Fri, 16 Jul 2010)
Log Message:
-----------
don't report PRMC for System.currentTimeMillis
Modified Paths:
--------------
trunk/fb-contrib/samples/PRMC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java
Modified: trunk/fb-contrib/samples/PRMC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/PRMC_Sample.java 2010-07-10 19:11:41 UTC (rev 1578)
+++ trunk/fb-contrib/samples/PRMC_Sample.java 2010-07-16 04:17:14 UTC (rev 1579)
@@ -69,4 +69,13 @@
{
}
}
+
+ public long fpCurrentTimeMillis(Object o)
+ {
+ long time = -System.currentTimeMillis();
+ o.hashCode();
+ time += System.currentTimeMillis();
+
+ return time;
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2010-07-10 19:11:41 UTC (rev 1578)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2010-07-16 04:17:14 UTC (rev 1579)
@@ -21,7 +21,6 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
-import java.util.Locale;
import java.util.Map;
import java.util.Set;
@@ -80,7 +79,7 @@
if (userNameProp != null) {
String[] userNames = userNameProp.split("\\s*,\\s*");
for (String name : userNames)
- riskyMethodNameContents.add(name.toLowerCase(Locale.getDefault()));
+ riskyMethodNameContents.add(name);
}
Integer prop = Integer.getInteger(PRMC_HIGH_BYTECOUNT);
if (prop != null)
@@ -108,7 +107,7 @@
}
}
- private BugReporter bugReporter;
+ private final BugReporter bugReporter;
private OpcodeStack stack = null;
private Map<Integer, MethodCall> localMethodCalls = null;
private Map<String, MethodCall> fieldMethodCalls = null;
@@ -288,7 +287,6 @@
if (riskyClassNames.contains(className))
return true;
- methodName = methodName.toLowerCase(Locale.ENGLISH);
for (String riskyName : riskyMethodNameContents) {
if (methodName.indexOf(riskyName) >= 0)
return true;
@@ -301,9 +299,9 @@
*/
static class MethodCall
{
- private String methodName;
- private String methodSignature;
- private Object[] methodParms;
+ private final String methodName;
+ private final String methodSignature;
+ private final Object[] methodParms;
public MethodCall(String name, String signature, Object[] parms) {
methodName = name;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-07-16 04:29:18
|
Revision: 1580
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1580&view=rev
Author: dbrosius
Date: 2010-07-16 04:29:12 +0000 (Fri, 16 Jul 2010)
Log Message:
-----------
don't report WEM for UnsupportedOperationException
Modified Paths:
--------------
trunk/fb-contrib/samples/WEM_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java
Modified: trunk/fb-contrib/samples/WEM_Sample.java
===================================================================
--- trunk/fb-contrib/samples/WEM_Sample.java 2010-07-16 04:17:14 UTC (rev 1579)
+++ trunk/fb-contrib/samples/WEM_Sample.java 2010-07-16 04:29:12 UTC (rev 1580)
@@ -17,5 +17,9 @@
{
throw new RuntimeException("Wow");
}
-
+
+ public void fpunimpled()
+ {
+ throw new UnsupportedOperationException("fpunimpled is unimpled");
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java 2010-07-16 04:17:14 UTC (rev 1579)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/WeakExceptionMessaging.java 2010-07-16 04:29:12 UTC (rev 1580)
@@ -19,6 +19,8 @@
package com.mebigfatguy.fbcontrib.detect;
import java.util.BitSet;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.bcel.Constants;
import org.apache.bcel.Repository;
@@ -37,15 +39,19 @@
public class WeakExceptionMessaging extends BytecodeScanningDetector {
private static JavaClass exceptionClass;
+ private static final Set<String> ignorableExceptionTypes = new HashSet<String>();
+
static {
try {
exceptionClass = Repository.lookupClass("java/lang/Exception");
} catch (ClassNotFoundException cnfe) {
exceptionClass = null;
}
+
+ ignorableExceptionTypes.add("java.lang.UnsupportedOperationException");
}
- private BugReporter bugReporter;
+ private final BugReporter bugReporter;
private OpcodeStack stack;
/**
@@ -116,10 +122,13 @@
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
if (item.getUserValue() != null) {
- bugReporter.reportBug(new BugInstance(this, "WEM_WEAK_EXCEPTION_MESSAGING", LOW_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
+ JavaClass exClass = item.getJavaClass();
+ if ((exClass == null) || !ignorableExceptionTypes.contains(item.getJavaClass().getClassName())) {
+ bugReporter.reportBug(new BugInstance(this, "WEM_WEAK_EXCEPTION_MESSAGING", LOW_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
}
}
} else if ((seen == LDC) || (seen == LDC_W)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-08-28 01:33:50
|
Revision: 1591
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1591&view=rev
Author: dbrosius
Date: 2010-08-28 01:33:41 +0000 (Sat, 28 Aug 2010)
Log Message:
-----------
new detector: PUS
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/PUS_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleUnsuspectedSerialization.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-08-22 04:43:28 UTC (rev 1590)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-08-28 01:33:41 UTC (rev 1591)
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
- <!--
- Plugin descriptor for fb-contrib plugin. This plugin is enabled by
- default.
- -->
-<FindbugsPlugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:noNamespaceSchemaLocation="findbugsplugin.xsd" pluginid="com.mebigfatguy.fbcontrib"
- defaultenabled="true" provider="fb-contrib project" website="http://fb-contrib.sourceforge.net">
+<!-- Plugin descriptor for fb-contrib plugin. This plugin is enabled by default. -->
+<FindbugsPlugin xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="findbugsplugin.xsd" pluginid="com.mebigfatguy.fbcontrib" defaultenabled="true"
+ provider="fb-contrib project" website="http://fb-contrib.sourceforge.net">
<!-- Passes -->
@@ -19,628 +15,359 @@
<!-- Detectors -->
- <Detector class="com.mebigfatguy.fbcontrib.collect.CollectStatistics"
- speed="fast" reports="" hidden="true" />
+ <Detector class="com.mebigfatguy.fbcontrib.collect.CollectStatistics" speed="fast" reports="" hidden="true" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.InefficientStringBuffering"
- speed="fast" reports="ISB_INEFFICIENT_STRING_BUFFERING,ISB_EMPTY_STRING_APPENDING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.InefficientStringBuffering" speed="fast" reports="ISB_INEFFICIENT_STRING_BUFFERING,ISB_EMPTY_STRING_APPENDING" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SyncCollectionIterators"
- speed="slow" reports="SCI_SYNCHRONIZED_COLLECTION_ITERATORS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SyncCollectionIterators" speed="slow" reports="SCI_SYNCHRONIZED_COLLECTION_ITERATORS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.CyclomaticComplexity"
- speed="slow" reports="CC_CYCLOMATIC_COMPLEXITY" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CyclomaticComplexity" speed="slow" reports="CC_CYCLOMATIC_COMPLEXITY" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.OverlyConcreteParameter"
- speed="slow" reports="OCP_OVERLY_CONCRETE_PARAMETER" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.OverlyConcreteParameter" speed="slow" reports="OCP_OVERLY_CONCRETE_PARAMETER" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ListIndexedIterating"
- speed="moderate" reports="LII_LIST_INDEXED_ITERATING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ListIndexedIterating" speed="moderate" reports="LII_LIST_INDEXED_ITERATING" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.UnrelatedCollectionContents"
- speed="fast" reports="UCC_UNRELATED_COLLECTION_CONTENTS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UnrelatedCollectionContents" speed="fast" reports="UCC_UNRELATED_COLLECTION_CONTENTS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.DeclaredRuntimeException"
- speed="fast" reports="DRE_DECLARED_RUNTIME_EXCEPTION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.DeclaredRuntimeException" speed="fast" reports="DRE_DECLARED_RUNTIME_EXCEPTION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ClassEnvy"
- speed="fast" reports="CE_CLASS_ENVY" disabled="true" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ClassEnvy" speed="fast" reports="CE_CLASS_ENVY" disabled="true" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.LiteralStringComparison"
- speed="fast" reports="LSC_LITERAL_STRING_COMPARISON" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.LiteralStringComparison" speed="fast" reports="LSC_LITERAL_STRING_COMPARISON" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.PartiallyConstructedObjectAccess"
- speed="fast" reports="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PartiallyConstructedObjectAccess" speed="fast" reports="PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousListCollection"
- speed="fast" reports="DLC_DUBIOUS_LIST_COLLECTION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousListCollection" speed="fast" reports="DLC_DUBIOUS_LIST_COLLECTION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ParallelLists"
- speed="fast" reports="PL_PARALLEL_LISTS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ParallelLists" speed="fast" reports="PL_PARALLEL_LISTS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.FinalParameters"
- speed="slow" reports="FP_FINAL_PARAMETERS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.FinalParameters" speed="slow" reports="FP_FINAL_PARAMETERS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.AbstractClassEmptyMethods"
- speed="fast" reports="ACEM_ABSTRACT_CLASS_EMPTY_METHODS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.AbstractClassEmptyMethods" speed="fast" reports="ACEM_ABSTRACT_CLASS_EMPTY_METHODS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ManualArrayCopy"
- speed="fast" reports="MAC_MANUAL_ARRAY_COPY" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ManualArrayCopy" speed="fast" reports="MAC_MANUAL_ARRAY_COPY" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.FloatingPointLoops"
- speed="fast" reports="FPL_FLOATING_POINT_LOOPS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.FloatingPointLoops" speed="fast" reports="FPL_FLOATING_POINT_LOOPS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.NonCollectionMethodUse"
- speed="fast" reports="NCMU_NON_COLLECTION_METHOD_USE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NonCollectionMethodUse" speed="fast" reports="NCMU_NON_COLLECTION_METHOD_USE" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.ConfusingAutoboxedOverloading"
- speed="fast" reports="CAO_CONFUSING_AUTOBOXED_OVERLOADING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingAutoboxedOverloading" speed="fast" reports="CAO_CONFUSING_AUTOBOXED_OVERLOADING" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.AbnormalFinallyBlockReturn"
- speed="fast" reports="AFBR_ABNORMAL_FINALLY_BLOCK_RETURN" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.AbnormalFinallyBlockReturn" speed="fast" reports="AFBR_ABNORMAL_FINALLY_BLOCK_RETURN" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.StaticMethodInstanceInvocation"
- speed="fast" reports="SMII_STATIC_METHOD_INSTANCE_INVOCATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.StaticMethodInstanceInvocation" speed="fast" reports="SMII_STATIC_METHOD_INSTANCE_INVOCATION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SpuriousThreadStates"
- speed="fast" reports="STS_SPURIOUS_THREAD_STATES" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SpuriousThreadStates" speed="fast" reports="STS_SPURIOUS_THREAD_STATES" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing"
- speed="fast"
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing" speed="fast"
reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF,NAB_NEEDLESS_BOX_TO_UNBOX,NAB_NEEDLESS_BOX_TO_CAST,NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn"
- speed="fast" reports="USBR_UNNECESSARY_STORE_BEFORE_RETURN" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn" speed="fast" reports="USBR_UNNECESSARY_STORE_BEFORE_RETURN" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.CopiedOverriddenMethod"
- speed="fast" reports="COM_COPIED_OVERRIDDEN_METHOD" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CopiedOverriddenMethod" speed="fast" reports="COM_COPIED_OVERRIDDEN_METHOD" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ArrayBasedCollections"
- speed="fast" reports="ABC_ARRAY_BASED_COLLECTIONS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ArrayBasedCollections" speed="fast" reports="ABC_ARRAY_BASED_COLLECTIONS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.OrphanedDOMNode"
- speed="fast" reports="ODN_ORPHANED_DOM_NODE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.OrphanedDOMNode" speed="fast" reports="ODN_ORPHANED_DOM_NODE" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.AbstractOverriddenMethod"
- speed="fast" reports="AOM_ABSTRACT_OVERRIDDEN_METHOD" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.AbstractOverriddenMethod" speed="fast" reports="AOM_ABSTRACT_OVERRIDDEN_METHOD" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.CustomBuiltXML"
- speed="fast" reports="CBX_CUSTOM_BUILT_XML" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.CustomBuiltXML" speed="fast" reports="CBX_CUSTOM_BUILT_XML" />
-<!--
- <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedSynchronizedBlock"
- speed="fast" reports="BSB_BLOATED_SYNCHRONIZED_BLOCK" hidden="true" />
--->
- <Detector class="com.mebigfatguy.fbcontrib.detect.ConstantListIndex"
- speed="fast" reports="CLI_CONSTANT_LIST_INDEX" />
+ <!-- <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedSynchronizedBlock" speed="fast" reports="BSB_BLOATED_SYNCHRONIZED_BLOCK" hidden="true" /> -->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ConstantListIndex" speed="fast" reports="CLI_CONSTANT_LIST_INDEX" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SloppyClassReflection"
- speed="fast" reports="SCR_SLOPPY_CLASS_REFLECTION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SloppyClassReflection" speed="fast" reports="SCR_SLOPPY_CLASS_REFLECTION" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.ArrayWrappedCallByReference"
- speed="fast" reports="AWCBR_ARRAY_WRAPPED_CALL_BY_REFERENCE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ArrayWrappedCallByReference" speed="fast" reports="AWCBR_ARRAY_WRAPPED_CALL_BY_REFERENCE" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SluggishGui"
- speed="fast" reports="SG_SLUGGISH_GUI" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SluggishGui" speed="fast" reports="SG_SLUGGISH_GUI" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessInstanceRetrieval"
- speed="fast" reports="NIR_NEEDLESS_INSTANCE_RETRIEVAL" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessInstanceRetrieval" speed="fast" reports="NIR_NEEDLESS_INSTANCE_RETRIEVAL" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.DateComparison"
- speed="fast" reports="DDC_DOUBLE_DATE_COMPARISON" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.DateComparison" speed="fast" reports="DDC_DOUBLE_DATE_COMPARISON" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.SuspiciousWaitOnConcurrentObject"
- speed="fast" reports="SWCO_SUSPICIOUS_WAIT_ON_CONCURRENT_OBJECT" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousWaitOnConcurrentObject" speed="fast" reports="SWCO_SUSPICIOUS_WAIT_ON_CONCURRENT_OBJECT" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.JDBCVendorReliance"
- speed="fast" reports="JVR_JDBC_VENDOR_RELIANCE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.JDBCVendorReliance" speed="fast" reports="JVR_JDBC_VENDOR_RELIANCE" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleMemoryBloat"
- speed="fast" reports="PMB_POSSIBLE_MEMORY_BLOAT" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleMemoryBloat" speed="fast" reports="PMB_POSSIBLE_MEMORY_BLOAT" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.LocalSynchronizedCollection"
- speed="moderate" reports="LSYC_LOCAL_SYNCHRONIZED_COLLECTION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.LocalSynchronizedCollection" speed="moderate" reports="LSYC_LOCAL_SYNCHRONIZED_COLLECTION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.FieldCouldBeLocal"
- speed="slow" reports="FCBL_FIELD_COULD_BE_LOCAL" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.FieldCouldBeLocal" speed="slow" reports="FCBL_FIELD_COULD_BE_LOCAL" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.NonOwnedSynchronization"
- speed="fast" reports="NOS_NON_OWNED_SYNCHRONIZATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NonOwnedSynchronization" speed="fast" reports="NOS_NON_OWNED_SYNCHRONIZATION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.NonRecycleableTaglibs"
- speed="fast" reports="NRTL_NON_RECYCLEABLE_TAG_LIBS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NonRecycleableTaglibs" speed="fast" reports="NRTL_NON_RECYCLEABLE_TAG_LIBS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance"
- speed="fast"
+ <Detector class="com.mebigfatguy.fbcontrib.detect.Section508Compliance" speed="fast"
reports="S508C_NULL_LAYOUT,S508C_NO_SETLABELFOR,S508C_NO_SETSIZE,S508C_NON_ACCESSIBLE_JCOMPONENT,S508C_SET_COMP_COLOR,S508C_NON_TRANSLATABLE_STRING" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.UseEnumCollections"
- speed="fast" reports="UEC_USE_ENUM_COLLECTIONS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseEnumCollections" speed="fast" reports="UEC_USE_ENUM_COLLECTIONS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SQLInLoop"
- speed="fast" reports="SIL_SQL_IN_LOOP" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SQLInLoop" speed="fast" reports="SIL_SQL_IN_LOOP" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.NeedlessMemberCollectionSynchronization"
- speed="moderate" reports="NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessMemberCollectionSynchronization" speed="moderate" reports="NMCS_NEEDLESS_MEMBER_COLLECTION_SYNCHRONIZATION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.InheritanceTypeChecking"
- speed="moderate" reports="ITC_INHERITANCE_TYPE_CHECKING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.InheritanceTypeChecking" speed="moderate" reports="ITC_INHERITANCE_TYPE_CHECKING" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.StaticArrayCreatedInMethod"
- speed="fast" reports="SACM_STATIC_ARRAY_CREATED_IN_METHOD" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.StaticArrayCreatedInMethod" speed="fast" reports="SACM_STATIC_ARRAY_CREATED_IN_METHOD" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.PossiblyRedundantMethodCalls"
- speed="fast" reports="PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossiblyRedundantMethodCalls" speed="fast" reports="PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.UseToArray"
- speed="fast" reports="UTA_USE_TO_ARRAY" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseToArray" speed="fast" reports="UTA_USE_TO_ARRAY" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.LostExceptionStackTrace"
- speed="moderate" reports="LEST_LOST_EXCEPTION_STACK_TRACE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.LostExceptionStackTrace" speed="moderate" reports="LEST_LOST_EXCEPTION_STACK_TRACE" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.UseCharacterParameterizedMethod"
- speed="fast" reports="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseCharacterParameterizedMethod" speed="fast" reports="UCPM_USE_CHARACTER_PARAMETERIZED_METHOD" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.TailRecursion"
- speed="fast" reports="TR_TAIL_RECURSION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.TailRecursion" speed="fast" reports="TR_TAIL_RECURSION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.UnrelatedReturnValues"
- speed="fast"
- reports="URV_UNRELATED_RETURN_VALUES,URV_CHANGE_RETURN_TYPE,URV_INHERITED_METHOD_WITH_RELATED_TYPES" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UnrelatedReturnValues" speed="fast" reports="URV_UNRELATED_RETURN_VALUES,URV_CHANGE_RETURN_TYPE,URV_INHERITED_METHOD_WITH_RELATED_TYPES" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.PossibleIncompleteSerialization"
- speed="fast" reports="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleIncompleteSerialization" speed="fast" reports="PIS_POSSIBLE_INCOMPLETE_SERIALIZATION" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues"
- speed="fast" reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousComparatorReturnValues" speed="fast" reports="SC_SUSPICIOUS_COMPARATOR_RETURN_VALUES" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri"
- speed="fast"
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SillynessPotPourri" speed="fast"
reports="SPP_NEGATIVE_BITSET_ITEM,SPP_INTERN_ON_CONSTANT,SPP_NO_CHAR_SB_CTOR,SPP_USE_MATH_CONSTANT,SPP_STUTTERED_ASSIGNMENT,SPP_USE_ISNAN,SPP_USE_BIGDECIMAL_STRING_CTOR,SPP_STRINGBUFFER_WITH_EMPTY_STRING,SPP_EQUALS_ON_ENUM,SPP_INVALID_BOOLEAN_NULL_CHECK,SPP_USE_CHARAT,SPP_USELESS_TRINARY,SPP_SUSPECT_STRING_TEST,SPP_USE_STRINGBUILDER_LENGTH,SPP_INVALID_CALENDAR_COMPARE,SPP_USE_CONTAINSKEY,SPP_USE_ISEMPTY,SPP_USE_GETPROPERTY,SPP_USELESS_CASING,SPP_NON_ARRAY_PARM" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope"
- speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor"
- speed="fast" reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SpoiledChildInterfaceImplementor" speed="fast" reports="SCI_SPOILED_CHILD_INTERFACE_IMPLEMENTOR" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating"
- speed="fast" reports="DWI_DELETING_WHILE_ITERATING,DWI_MODIFYING_WHILE_ITERATING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.DeletingWhileIterating" speed="fast" reports="DWI_DELETING_WHILE_ITERATING,DWI_MODIFYING_WHILE_ITERATING" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.UseSplit"
- speed="fast" reports="USS_USE_STRING_SPLIT" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseSplit" speed="fast" reports="USS_USE_STRING_SPLIT" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse"
- speed="slow" reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" disabled="true" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousJDKVersionUse" speed="slow" reports="SJVU_SUSPICIOUS_JDK_VERSION_USE" disabled="true" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.UseAddAll"
- speed="fast" reports="UAA_USE_ADD_ALL" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseAddAll" speed="fast" reports="UAA_USE_ADD_ALL" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.MethodReturnsConstant"
- speed="fast" reports="MRC_METHOD_RETURNS_CONSTANT" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.MethodReturnsConstant" speed="fast" reports="MRC_METHOD_RETURNS_CONSTANT" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.NeedlessCustomSerialization"
- speed="fast" reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessCustomSerialization" speed="fast" reports="NCS_NEEDLESS_CUSTOM_SERIALIZATION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel"
- speed="fast" reports="MOM_MISLEADING_OVERLOAD_MODEL" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.MisleadingOverloadModel" speed="fast" reports="MOM_MISLEADING_OVERLOAD_MODEL" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ExceptionSoftening"
- speed="moderate"
- reports="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS,EXS_EXCEPTION_SOFTENING_HAS_CHECKED,EXS_EXCEPTION_SOFTENING_NO_CHECKED" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ExceptionSoftening" speed="moderate" reports="EXS_EXCEPTION_SOFTENING_NO_CONSTRAINTS,EXS_EXCEPTION_SOFTENING_HAS_CHECKED,EXS_EXCEPTION_SOFTENING_NO_CHECKED" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics"
- speed="fast" reports="CFS_CONFUSING_FUNCTION_SEMANTICS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ConfusingFunctionSemantics" speed="fast" reports="CFS_CONFUSING_FUNCTION_SEMANTICS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.JUnitAssertionOddities"
- speed="fast"
+ <Detector class="com.mebigfatguy.fbcontrib.detect.JUnitAssertionOddities" speed="fast"
reports="JAO_JUNIT_ASSERTION_ODDITIES_ACTUAL_CONSTANT,JAO_JUNIT_ASSERTION_ODDITIES_INEXACT_DOUBLE,JAO_JUNIT_ASSERTION_ODDITIES_BOOLEAN_ASSERT,JAO_JUNIT_ASSERTION_ODDITIES_IMPOSSIBLE_NULL" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousCloneAlgorithm"
- speed="fast" reports="SCA_SUSPICIOUS_CLONE_ALGORITHM" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousCloneAlgorithm" speed="fast" reports="SCA_SUSPICIOUS_CLONE_ALGORITHM" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.WeakExceptionMessaging"
- speed="fast" reports="WEM_WEAK_EXCEPTION_MESSAGING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.WeakExceptionMessaging" speed="fast" reports="WEM_WEAK_EXCEPTION_MESSAGING" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.SuspiciousClusteredSessionSupport"
- speed="fast" reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousClusteredSessionSupport" speed="fast" reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.LoggerOddities"
- speed="fast" reports="LO_SUSPECT_LOG_CLASS,LO_SUSPECT_LOG_PARAMETER" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.LoggerOddities" speed="fast" reports="LO_SUSPECT_LOG_CLASS,LO_SUSPECT_LOG_PARAMETER" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse"
- speed="fast" reports="IICU_INCORRECT_INTERNAL_CLASS_USE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse" speed="fast" reports="IICU_INCORRECT_INTERNAL_CLASS_USE" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousSetOfCollections"
- speed="moderate" reports="DSOC_DUBIOUS_SET_OF_COLLECTIONS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.DubiousSetOfCollections" speed="moderate" reports="DSOC_DUBIOUS_SET_OF_COLLECTIONS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.BogusExceptionDeclaration"
- speed="moderate" reports="BED_BOGUS_EXCEPTION_DECLARATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.BogusExceptionDeclaration" speed="moderate" reports="BED_BOGUS_EXCEPTION_DECLARATION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryNewNullCheck"
- speed="fast" reports="UNNC_UNNECESSARY_NEW_NULL_CHECK" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryNewNullCheck" speed="fast" reports="UNNC_UNNECESSARY_NEW_NULL_CHECK" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.DeprecatedTypesafeEnumPattern"
- speed="fast" reports="DTEP_DEPRECATED_TYPESAFE_ENUM_PATTERN" />
-<!--
- <Detector class="com.mebigfatguy.fbcontrib.detect.StutteredMethodArguments"
- speed="fast" reports="SMA_STUTTERED_METHOD_ARGUMENTS" hidden="true" />
--->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.DeprecatedTypesafeEnumPattern" speed="fast" reports="DTEP_DEPRECATED_TYPESAFE_ENUM_PATTERN" />
+ <!-- <Detector class="com.mebigfatguy.fbcontrib.detect.StutteredMethodArguments" speed="fast" reports="SMA_STUTTERED_METHOD_ARGUMENTS" hidden="true" /> -->
- <Detector class="com.mebigfatguy.fbcontrib.detect.TristateBooleanPattern"
- speed="fast" reports="TBP_TRISTATE_BOOLEAN_PATTERN" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.TristateBooleanPattern" speed="fast" reports="TBP_TRISTATE_BOOLEAN_PATTERN" />
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.SuspiciousUninitializedArray"
- speed="fast" reports="SUA_SUSPICIOUS_UNINITIALIZED_ARRAY" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousUninitializedArray" speed="fast" reports="SUA_SUSPICIOUS_UNINITIALIZED_ARRAY" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.InappropriateToStringUse"
- speed="fast" reports="ITU_INAPPROPRIATE_TOSTRING_USE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.InappropriateToStringUse" speed="fast" reports="ITU_INAPPROPRIATE_TOSTRING_USE" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.InconsistentKeyNameCasing"
- speed="fast" reports="IKNC_INCONSISTENT_HTTP_ATTRIBUTE_CASING,IKNC_INCONSISTENT_HTTP_PARAM_CASING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.InconsistentKeyNameCasing" speed="fast" reports="IKNC_INCONSISTENT_HTTP_ATTRIBUTE_CASING,IKNC_INCONSISTENT_HTTP_PARAM_CASING" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.OverzealousCasting"
- speed="fast" reports="OC_OVERZEALOUS_CASTING" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.OverzealousCasting" speed="fast" reports="OC_OVERZEALOUS_CASTING" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.PoorlyDefinedParameter"
- speed="fast" reports="PDP_POORLY_DEFINED_PARAMETER" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PoorlyDefinedParameter" speed="fast" reports="PDP_POORLY_DEFINED_PARAMETER" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.NonSymmetricEquals"
- speed="fast" reports="NSE_NON_SYMMETRIC_EQUALS" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NonSymmetricEquals" speed="fast" reports="NSE_NON_SYMMETRIC_EQUALS" />
-<!--
- <Detector
- class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment"
- speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" />
- -->
-
- <Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField"
- speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
-<!--
- <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard"
- speed="fast" hidden="true" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
--->
- <Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods"
- speed="fast"
+ <!-- <Detector class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment" speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" /> -->
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField" speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
+ <!-- <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard" speed="fast" hidden="true" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" /> -->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods" speed="fast"
reports="MDM_RUNTIME_EXIT_OR_HALT,MDM_RUNFINALIZATION,MDM_BIGDECIMAL_EQUALS,MDM_INETADDRESS_GETLOCALHOST,MDM_PROMISCUOUS_SERVERSOCKET,MDM_RANDOM_SEED,MDM_SECURERANDOM_CTOR,MDM_SECURERANDOM_GETSEED,MDM_THREAD_PRIORITIES,MDM_THREAD_YIELD,MDM_WAIT_WITHOUT_TIMEOUT,MDM_THREAD_FAIRNESS,MDM_REENTRANTLOCK_HELDBY,MDM_STRING_BYTES_ENCODING,MDM_SETDEFAULTLOCALE" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ReflectionOnObjectMethods"
- speed="fast"
- reports="ROOM_REFLECTION_ON_OBJECT_METHODS" />
-
- <Detector class="com.mebigfatguy.fbcontrib.detect.ImproperPropertiesUse"
- speed="fast"
- reports="IPU_IMPROPER_PROPERTIES_USE,IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ReflectionOnObjectMethods" speed="fast" reports="ROOM_REFLECTION_ON_OBJECT_METHODS" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop"
- speed="fast"
- reports="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP" />
-
- <Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection"
- speed="fast"
- reports="WOC_WRITE_ONLY_COLLECTION_LOCAL,WOC_WRITE_ONLY_COLLECTION_FIELD" />
-
- <Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs"
- speed="fast"
- reports="UVA_USE_VAR_ARGS" />
-
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ImproperPropertiesUse" speed="fast" reports="IPU_IMPROPER_PROPERTIES_USE,IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleConstantAllocationInLoop" speed="fast" reports="PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.WriteOnlyCollection" speed="fast" reports="WOC_WRITE_ONLY_COLLECTION_LOCAL,WOC_WRITE_ONLY_COLLECTION_FIELD" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseVarArgs" speed="fast" reports="UVA_USE_VAR_ARGS" />
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.PossibleUnsuspectedSerialization" speed="fast" reports="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" />
+
<!-- BugPattern -->
- <BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING"
- category="PERFORMANCE" />
- <BugPattern abbrev="ISB" type="ISB_EMPTY_STRING_APPENDING"
- category="PERFORMANCE" />
- <BugPattern abbrev="SCI" type="SCI_SYNCHRONIZED_COLLECTION_ITERATORS"
- category="CORRECTNESS" />
- <BugPattern abbrev="CC" type="CC_CYCLOMATIC_COMPLEXITY"
- category="STYLE" />
- <BugPattern abbrev="OCP" type="OCP_OVERLY_CONCRETE_PARAMETER"
- category="STYLE" />
- <BugPattern abbrev="LII" type="LII_LIST_INDEXED_ITERATING"
- category="STYLE" />
- <BugPattern abbrev="UCC" type="UCC_UNRE...
[truncated message content] |
|
From: <dbr...@us...> - 2010-08-29 06:15:14
|
Revision: 1594
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1594&view=rev
Author: dbrosius
Date: 2010-08-29 06:15:07 +0000 (Sun, 29 Aug 2010)
Log Message:
-----------
remove javadoc from svn
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/SEC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java
Removed Paths:
-------------
trunk/fb-contrib/javadoc/
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-08-29 05:31:24 UTC (rev 1593)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-08-29 06:15:07 UTC (rev 1594)
@@ -211,6 +211,8 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.PossibleUnsuspectedSerialization" speed="fast" reports="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SideEffectConstructor" speed="fast" reports="SEC_SIDE_EFFECT_CONSTRUCTOR" />
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -369,5 +371,6 @@
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_LOCAL" category="CORRECTNESS" />
<BugPattern abbrev="WOC" type="WOC_WRITE_ONLY_COLLECTION_FIELD" category="CORRECTNESS" />
<BugPattern abbrev="UVA" type="UVA_USE_VAR_ARGS" category="STYLE" />
- <BugPattern abbrev="PUS" type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" category="CORRECTNESS" />
+ <BugPattern abbrev="PUS" type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" category="CORRECTNESS" experimental="true" />
+ <BugPattern abbrev="SEC" type="SEC_SIDE_EFFECT_CONSTRUCTOR" category="STYLE" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-08-29 05:31:24 UTC (rev 1593)
+++ trunk/fb-contrib/etc/messages.xml 2010-08-29 06:15:07 UTC (rev 1594)
@@ -1167,6 +1167,17 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SideEffectConstructor">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for object creation where the object isn't assigned to any variable or
+ field. This implies that the class operates through side effects in the constructor, which makes
+ for difficult to maintain code.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -3188,6 +3199,19 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="SEC_SIDE_EFFECT_CONSTRUCTOR">
+ <ShortDescription>Method uses a Side Effect Constructor</ShortDescription>
+ <LongDescription>Method {1} uses a Side Effect Constructor</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates an object but does not assign this object to any variable or field.
+ This implies that the class operations through side effects in the constructor, which is a
+ pattern to use. Consider pull the side effect out of the constructor, into a separate method,
+ of into the calling method.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3287,4 +3311,5 @@
<BugCode abbrev="WOC">Write Only Collection</BugCode>
<BugCode abbrev="UVA">Use Var Args</BugCode>
<BugCode abbrev="PUS">Possible Unsuspected Serialization</BugCode>
+ <BugCode abbrev="SEC">Side Effect Constructor</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/SEC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SEC_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/SEC_Sample.java 2010-08-29 06:15:07 UTC (rev 1594)
@@ -0,0 +1,17 @@
+import java.util.ArrayList;
+import java.util.List;
+
+
+public class SEC_Sample
+{
+ public SEC_Sample(List<SEC_Sample> l)
+ {
+ l.add(this);
+ }
+
+ public static void main(String[] args)
+ {
+ List<SEC_Sample> l = new ArrayList<SEC_Sample>();
+ new SEC_Sample(l);
+ }
+}
Property changes on: trunk/fb-contrib/samples/SEC_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java 2010-08-29 06:15:07 UTC (rev 1594)
@@ -0,0 +1,85 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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 org.apache.bcel.classfile.Code;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+
+/**
+ * looks for constructors that operate through side effects, specifically
+ * constructors that aren't assigned to any variable or field.
+ */
+public class SideEffectConstructor extends BytecodeScanningDetector {
+
+ private enum State {SAW_NOTHING, SAW_CTOR};
+ private final BugReporter bugReporter;
+ private State state;
+
+ /**
+ * constructs a SEC detector given the reporter to report bugs on
+ *
+ * @param bugReporter the sync of bug reports
+ */
+ public SideEffectConstructor(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ /**
+ * overrides the visitor to reset the state
+ *
+ * @param obj the context object of the currently parsed code
+ */
+ @Override
+ public void visitCode(Code obj) {
+ state = State.SAW_NOTHING;
+ super.visitCode(obj);
+ }
+ /**
+ * overrides the visitor to look for constructors who's value is
+ * popped off the stack, and not assigned.
+ *
+ * @param seen the opcode of the currently parse opcode
+ */
+ @Override
+ public void sawOpcode(int seen) {
+ switch (state) {
+ case SAW_NOTHING:
+ if (seen == INVOKESPECIAL) {
+ String name = getNameConstantOperand();
+ if ("<init>".equals(name)) {
+ state = State.SAW_CTOR;
+ }
+ }
+ break;
+
+ case SAW_CTOR:
+ if (seen == POP) {
+ bugReporter.reportBug(new BugInstance(this, "SEC_SIDE_EFFECT_CONSTRUCTOR", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ state = State.SAW_NOTHING;
+ break;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-08-30 02:43:28
|
Revision: 1597
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1597&view=rev
Author: dbrosius
Date: 2010-08-30 02:43:22 +0000 (Mon, 30 Aug 2010)
Log Message:
-----------
later jdk's can be sloppy about tidying up the stack, so look for returns with unassigned allocations still on the stack
Modified Paths:
--------------
trunk/fb-contrib/samples/SEC_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java
Modified: trunk/fb-contrib/samples/SEC_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SEC_Sample.java 2010-08-29 06:22:58 UTC (rev 1596)
+++ trunk/fb-contrib/samples/SEC_Sample.java 2010-08-30 02:43:22 UTC (rev 1597)
@@ -14,4 +14,11 @@
List<SEC_Sample> l = new ArrayList<SEC_Sample>();
new SEC_Sample(l);
}
+
+ public void test()
+ {
+ List<SEC_Sample> l = new ArrayList<SEC_Sample>();
+ new SEC_Sample(l);
+ main(new String[0]);
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java 2010-08-29 06:22:58 UTC (rev 1596)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SideEffectConstructor.java 2010-08-30 02:43:22 UTC (rev 1597)
@@ -19,10 +19,13 @@
package com.mebigfatguy.fbcontrib.detect;
import org.apache.bcel.classfile.Code;
+import org.apache.bcel.generic.Type;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
/**
* looks for constructors that operate through side effects, specifically
@@ -32,6 +35,7 @@
private enum State {SAW_NOTHING, SAW_CTOR};
private final BugReporter bugReporter;
+ private OpcodeStack stack;
private State state;
/**
@@ -44,42 +48,92 @@
}
/**
- * overrides the visitor to reset the state
+ * overrides the visitor to set up and tear down the opcode stack
*
+ * @param classContext the context object of the currently parsed class
+ */
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ }
+ }
+ /**
+ * overrides the visitor to reset the state and reset the opcode stack
+ *
* @param obj the context object of the currently parsed code
*/
@Override
public void visitCode(Code obj) {
state = State.SAW_NOTHING;
+ stack.resetForMethodEntry(this);
super.visitCode(obj);
}
+
/**
* overrides the visitor to look for constructors who's value is
- * popped off the stack, and not assigned.
+ * popped off the stack, and not assigned before the pop of the value, or if a
+ * return is issued with that object still on the stack.
*
* @param seen the opcode of the currently parse opcode
*/
@Override
public void sawOpcode(int seen) {
- switch (state) {
- case SAW_NOTHING:
- if (seen == INVOKESPECIAL) {
- String name = getNameConstantOperand();
- if ("<init>".equals(name)) {
- state = State.SAW_CTOR;
+ int pc = 0;
+ try {
+ switch (state) {
+ case SAW_NOTHING:
+ if (seen == INVOKESPECIAL) {
+ String name = getNameConstantOperand();
+ if ("<init>".equals(name)) {
+ String sig = getSigConstantOperand();
+ int numArgs = Type.getArgumentTypes(sig).length;
+ if (stack.getStackDepth() > numArgs) {
+ OpcodeStack.Item caller = stack.getStackItem(numArgs);
+ if (caller.getRegisterNumber() != 0) {
+ state = State.SAW_CTOR;
+ pc = getPC();
+ }
+ }
+ }
+ } else if (seen == RETURN) {
+ int depth = stack.getStackDepth();
+ for (int i = 0; i < depth; i++) {
+ OpcodeStack.Item item = stack.getStackItem(i);
+ Integer secPC = (Integer)item.getUserValue();
+ if (secPC != null) {
+ bugReporter.reportBug(new BugInstance(this, "SEC_SIDE_EFFECT_CONSTRUCTOR", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this, secPC.intValue()));
+ break;
+ }
+
+ }
}
+ break;
+
+ case SAW_CTOR:
+ if (seen == POP || seen == RETURN) {
+ bugReporter.reportBug(new BugInstance(this, "SEC_SIDE_EFFECT_CONSTRUCTOR", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ state = State.SAW_NOTHING;
+ break;
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (pc != 0) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(Integer.valueOf(pc));
}
- break;
-
- case SAW_CTOR:
- if (seen == POP) {
- bugReporter.reportBug(new BugInstance(this, "SEC_SIDE_EFFECT_CONSTRUCTOR", NORMAL_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this));
- }
- state = State.SAW_NOTHING;
- break;
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-08-31 01:10:29
|
Revision: 1599
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1599&view=rev
Author: dbrosius
Date: 2010-08-31 01:10:22 +0000 (Tue, 31 Aug 2010)
Log Message:
-----------
fix various spilleng and engrish problems in bug detectors and web page, thanks to Jean-No?\195?\171l Rouvignac
Modified Paths:
--------------
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.shtml
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-08-30 12:55:14 UTC (rev 1598)
+++ trunk/fb-contrib/etc/messages.xml 2010-08-31 01:10:22 UTC (rev 1599)
@@ -1159,7 +1159,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.PossibleUnsuspectedSerialization">
<Details>
<![CDATA[
- <p>This detector looks for code that serailizes objects that are non-static inner
+ <p>This detector looks for code that serializes objects that are non-static inner
classes of other classes. Since there is a reference to the containing class, this class will be serialized as well.
It is often the case that this is not what is wanted, and will cause much more data to be serialized
than is necessary.</p>
@@ -3206,9 +3206,9 @@
<Details>
<![CDATA[
<p>This method creates an object but does not assign this object to any variable or field.
- This implies that the class operations through side effects in the constructor, which is a
- bad pattern to use, as it adds unnecessary coupling. Consider pulling the side effect out of the constructor, into a separate method,
- or into the calling method.
+ This implies that the class operates through side effects in the constructor, which is a
+ bad pattern to use, as it adds unnecessary coupling. Consider pulling the side effect out of
+ the constructor, into a separate method, or into the calling method.
]]>
</Details>
</BugPattern>
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-08-30 12:55:14 UTC (rev 1598)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-08-31 01:10:22 UTC (rev 1599)
@@ -90,8 +90,14 @@
or a change in implementation.</li>
<li><b>[PUS] Possible Unsuspected Serialization</b><br/>
Looks for serialization of non-static inner classes. As this serializes
- the enclosing class, it may unintentially bring in more to the serialization
+ the enclosing class, it may unintentionally bring in more to the serialization
than is wanted.</li>
+ <li><b>[SEC] Side Effect Constructor</b><br/>
+ Looks for constructors that operate through side effects, specifically
+ constructors that aren't assigned to any variable or field. This makes
+ the code more difficult to maintain as it has a tendency to increase cohesion
+ between classes.
+ </li>
</ul>
</div>
<hr/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-09-04 20:38:10
|
Revision: 1603
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1603&view=rev
Author: dbrosius
Date: 2010-09-04 20:38:03 +0000 (Sat, 04 Sep 2010)
Log Message:
-----------
New detector SGSU
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
Added Paths:
-----------
trunk/fb-contrib/samples/SGSU_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-08-31 01:33:46 UTC (rev 1602)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-09-04 20:38:03 UTC (rev 1603)
@@ -213,6 +213,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SideEffectConstructor" speed="fast" reports="SEC_SIDE_EFFECT_CONSTRUCTOR" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousGetterSetterUse" speed="fast" reports="SGSU_SUSPICIOUS_GETTER_SETTER_USE" />
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -373,4 +374,5 @@
<BugPattern abbrev="UVA" type="UVA_USE_VAR_ARGS" category="STYLE" />
<BugPattern abbrev="PUS" type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="SEC" type="SEC_SIDE_EFFECT_CONSTRUCTOR" category="STYLE" experimental="true" />
+ <BugPattern abbrev="SGSU" type="SGSU_SUSPICIOUS_GETTER_SETTER_USE" category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
\ No newline at end of file
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-08-31 01:33:46 UTC (rev 1602)
+++ trunk/fb-contrib/etc/messages.xml 2010-09-04 20:38:03 UTC (rev 1603)
@@ -1178,6 +1178,20 @@
]]>
</Details>
</Detector>
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousGetterSetterUse">
+ <Details>
+ <![CDATA[
+ <p>This detector looks for java bean getter-setter use where the value of a property is set
+ with the value retrieved from the same bean's correllary getter, like this:</p>
+ <pre>
+ person.setAge(person.getAge());
+ </pre>
+ <p>Typically this is a copy paste typo.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
<!-- BugPattern -->
@@ -3212,6 +3226,17 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="SGSU_SUSPICIOUS_GETTER_SETTER_USE">
+ <ShortDescription>Method uses same bean's getter value for setter</ShortDescription>
+ <LongDescription>Method {1} uses same bean's getter value for setter</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method retrieves the property of a java bean, only to use it in the setter
+ for the same property of the same bean. This is usually a copy/paste typo.
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -3312,4 +3337,5 @@
<BugCode abbrev="UVA">Use Var Args</BugCode>
<BugCode abbrev="PUS">Possible Unsuspected Serialization</BugCode>
<BugCode abbrev="SEC">Side Effect Constructor</BugCode>
+ <BugCode abbrev="SGSU">Suspicious Getter Setter Use</BugCode>
</MessageCollection>
Added: trunk/fb-contrib/samples/SGSU_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SGSU_Sample.java (rev 0)
+++ trunk/fb-contrib/samples/SGSU_Sample.java 2010-09-04 20:38:03 UTC (rev 1603)
@@ -0,0 +1,20 @@
+
+public class SGSU_Sample
+{
+ private SGSU_Sample foo;
+
+ public void testSGSU(SGSU_Sample s1, SGSU_Sample s2)
+ {
+ s1.setSGSU(s1.getSGSU());
+ }
+
+ public void setSGSU(SGSU_Sample f)
+ {
+ foo = f;
+ }
+
+ public SGSU_Sample getSGSU()
+ {
+ return foo;
+ }
+}
Property changes on: trunk/fb-contrib/samples/SGSU_Sample.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java (rev 0)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java 2010-09-04 20:38:03 UTC (rev 1603)
@@ -0,0 +1,157 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2010 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 org.apache.bcel.classfile.Code;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+
+/**
+ * looks for methods that set a setter with the value obtained from the same bean's
+ * complimentary getter. This is usually a typo.
+ */
+public class SuspiciousGetterSetterUse extends BytecodeScanningDetector {
+
+ private static enum State {SEEN_NOTHING, SEEN_ALOAD, SEEN_GETFIELD, SEEN_DUAL_LOADS, SEEN_INVOKEVIRTUAL};
+ private final BugReporter bugReporter;
+ private State state;
+ private String beanReference;
+ private String propName;
+ private String propType;
+
+ /**
+ * constructs a SGSU detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
+ public SuspiciousGetterSetterUse(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ /**
+ * overrides the visitor to reset the state to SEEN_NOTHING, and clear the beanReference, propName
+ * and propType
+ *
+ * @param code the context object of the currently parsed code block
+ */
+ @Override
+ public void visitCode(Code obj) {
+ state = State.SEEN_NOTHING;
+ beanReference = null;
+ propName = null;
+ propType = null;
+ super.visitCode(obj);
+ }
+
+ /**
+ * overrides the visitor to look for a setXXX with the value returned from a getXXX
+ * using the same base object.
+ *
+ * @param seen the currently parsed opcode
+ */
+ @Override
+ public void sawOpcode(int seen) {
+ boolean reset = true;
+ switch (state) {
+ case SEEN_NOTHING:
+ switch (seen) {
+ case ALOAD:
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3:
+ beanReference = String.valueOf(getRegisterOperand());
+ state = State.SEEN_ALOAD;
+ reset = false;
+ break;
+
+ case GETFIELD:
+ beanReference = getNameConstantOperand();
+ state = State.SEEN_GETFIELD;
+ reset = false;
+ break;
+ }
+ break;
+
+ case SEEN_ALOAD:
+ switch (seen) {
+ case ALOAD:
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3:
+ if (beanReference.equals(String.valueOf(getRegisterOperand()))) {
+ state = State.SEEN_DUAL_LOADS;
+ reset = false;
+ }
+ break;
+ }
+ break;
+
+ case SEEN_GETFIELD:
+ if (beanReference.equals(getNameConstantOperand())) {
+ state = State.SEEN_DUAL_LOADS;
+ reset = false;
+ }
+ break;
+
+ case SEEN_DUAL_LOADS:
+ if (seen == INVOKEVIRTUAL) {
+ String sig = getSigConstantOperand();
+ if (sig.startsWith("()")) {
+ propType = sig.substring("()".length());
+ if (!propType.equals("V")) {
+ propName = getNameConstantOperand();
+ if (propName.startsWith("get")) {
+ propName = propName.substring("get".length());
+ state = State.SEEN_INVOKEVIRTUAL;
+ reset = false;
+ }
+ }
+ }
+ }
+ break;
+
+ case SEEN_INVOKEVIRTUAL:
+ if (seen == INVOKEVIRTUAL) {
+ String sig = getSigConstantOperand();
+ if (sig.equals("(" + propType + ")V")) {
+ String name = getNameConstantOperand();
+ if (name.startsWith("set")) {
+ if (propName.equals(name.substring("set".length()))) {
+ bugReporter.reportBug(new BugInstance(this, "SGSU_SUSPICIOUS_GETTER_SETTER_USE", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+ break;
+ }
+
+ if (reset) {
+ beanReference = null;
+ propType = null;
+ propName = null;
+ state = State.SEEN_NOTHING;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-09-05 00:38:04
|
Revision: 1606
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1606&view=rev
Author: dbrosius
Date: 2010-09-05 00:37:58 +0000 (Sun, 05 Sep 2010)
Log Message:
-----------
handle field based beans correctly
Modified Paths:
--------------
trunk/fb-contrib/samples/SGSU_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java
Modified: trunk/fb-contrib/samples/SGSU_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SGSU_Sample.java 2010-09-04 20:41:14 UTC (rev 1605)
+++ trunk/fb-contrib/samples/SGSU_Sample.java 2010-09-05 00:37:58 UTC (rev 1606)
@@ -2,12 +2,23 @@
public class SGSU_Sample
{
private SGSU_Sample foo;
+ private SGSU_Sample foo2;
- public void testSGSU(SGSU_Sample s1, SGSU_Sample s2)
+ public void testSGSULocals(SGSU_Sample s1, SGSU_Sample s2)
{
s1.setSGSU(s1.getSGSU());
}
+ public void testSGSUFields()
+ {
+ foo.setSGSU(foo.getSGSU());
+ }
+
+ public void fpSGSUFields()
+ {
+ foo.setSGSU(foo2.getSGSU());
+ }
+
public void setSGSU(SGSU_Sample f)
{
foo = f;
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java 2010-09-04 20:41:14 UTC (rev 1605)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousGetterSetterUse.java 2010-09-05 00:37:58 UTC (rev 1606)
@@ -33,9 +33,11 @@
private static enum State {SEEN_NOTHING, SEEN_ALOAD, SEEN_GETFIELD, SEEN_DUAL_LOADS, SEEN_INVOKEVIRTUAL};
private final BugReporter bugReporter;
private State state;
- private String beanReference;
+ private String beanReference1;
+ private String beanReference2;
private String propName;
private String propType;
+ private boolean sawField;
/**
* constructs a SGSU detector given the reporter to report bugs on
@@ -54,9 +56,11 @@
@Override
public void visitCode(Code obj) {
state = State.SEEN_NOTHING;
- beanReference = null;
+ beanReference1 = null;
+ beanReference2 = null;
propName = null;
propType = null;
+ sawField = false;
super.visitCode(obj);
}
@@ -77,16 +81,10 @@
case ALOAD_1:
case ALOAD_2:
case ALOAD_3:
- beanReference = String.valueOf(getRegisterOperand());
+ beanReference1 = String.valueOf(getRegisterOperand());
state = State.SEEN_ALOAD;
reset = false;
break;
-
- case GETFIELD:
- beanReference = getNameConstantOperand();
- state = State.SEEN_GETFIELD;
- reset = false;
- break;
}
break;
@@ -97,19 +95,42 @@
case ALOAD_1:
case ALOAD_2:
case ALOAD_3:
- if (beanReference.equals(String.valueOf(getRegisterOperand()))) {
+ if (!sawField && beanReference1.equals(String.valueOf(getRegisterOperand()))) {
state = State.SEEN_DUAL_LOADS;
reset = false;
}
break;
+
+ case GETFIELD: {
+ if (sawField) {
+ beanReference2 += ":" + getNameConstantOperand();
+ if (beanReference1.equals(beanReference2)) {
+ state = State.SEEN_DUAL_LOADS;
+ reset = false;
+ }
+ } else {
+ state = State.SEEN_GETFIELD;
+ beanReference1 += ":" + getNameConstantOperand();
+ sawField = true;
+ reset = false;
+ }
+ }
}
break;
- case SEEN_GETFIELD:
- if (beanReference.equals(getNameConstantOperand())) {
- state = State.SEEN_DUAL_LOADS;
- reset = false;
+ case SEEN_GETFIELD: {
+ switch (seen) {
+ case ALOAD:
+ case ALOAD_0:
+ case ALOAD_1:
+ case ALOAD_2:
+ case ALOAD_3:
+ beanReference2 = String.valueOf(getRegisterOperand());
+ state = State.SEEN_ALOAD;
+ reset = false;
+ break;
}
+ }
break;
case SEEN_DUAL_LOADS:
@@ -148,9 +169,11 @@
}
if (reset) {
- beanReference = null;
+ beanReference1 = null;
+ beanReference2 = null;
propType = null;
propName = null;
+ sawField = false;
state = State.SEEN_NOTHING;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-09-10 01:25:56
|
Revision: 1608
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1608&view=rev
Author: dbrosius
Date: 2010-09-10 01:25:50 +0000 (Fri, 10 Sep 2010)
Log Message:
-----------
add support for commons logging in LO
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-09-06 02:47:08 UTC (rev 1607)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-09-10 01:25:50 UTC (rev 1608)
@@ -195,7 +195,7 @@
<!-- <Detector class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment" speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" /> -->
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField" speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
- <!-- <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard" speed="fast" hidden="true" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" /> -->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard" speed="fast" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
<Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods" speed="fast"
reports="MDM_RUNTIME_EXIT_OR_HALT,MDM_RUNFINALIZATION,MDM_BIGDECIMAL_EQUALS,MDM_INETADDRESS_GETLOCALHOST,MDM_PROMISCUOUS_SERVERSOCKET,MDM_RANDOM_SEED,MDM_SECURERANDOM_CTOR,MDM_SECURERANDOM_GETSEED,MDM_THREAD_PRIORITIES,MDM_THREAD_YIELD,MDM_WAIT_WITHOUT_TIMEOUT,MDM_THREAD_FAIRNESS,MDM_REENTRANTLOCK_HELDBY,MDM_STRING_BYTES_ENCODING,MDM_SETDEFAULTLOCALE" />
@@ -375,4 +375,4 @@
<BugPattern abbrev="PUS" type="PUS_POSSIBLE_UNSUSPECTED_SERIALIZATION" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="SEC" type="SEC_SIDE_EFFECT_CONSTRUCTOR" category="STYLE" experimental="true" />
<BugPattern abbrev="SGSU" type="SGSU_SUSPICIOUS_GETTER_SETTER_USE" category="CORRECTNESS" experimental="true" />
-</FindbugsPlugin>
\ No newline at end of file
+</FindbugsPlugin>
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2010-09-06 02:47:08 UTC (rev 1607)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2010-09-10 01:25:50 UTC (rev 1608)
@@ -91,7 +91,8 @@
{
String parmSig = t.getSignature();
if ("Lorg/slf4j/Logger;".equals(parmSig)
- || "Lorg/apache/log4j/Logger;".equals(parmSig)) {
+ || "Lorg/apache/log4j/Logger;".equals(parmSig)
+ || "Lorg/apache/commons/logging/Log;".equals(parmSig)) {
bugReporter.reportBug(new BugInstance(this, "LO_SUSPECT_LOG_PARAMETER", NORMAL_PRIORITY)
.addClass(this)
.addMethod(this)
@@ -136,8 +137,9 @@
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
loggingClassName = (String)item.getConstant();
- if (loggingClassName != null)
- loggingClassName = loggingClassName.replace('.', '/');
+ if (loggingClassName != null) {
+ loggingClassName = loggingClassName.replace('.', '/');
+ }
}
}
} else if ("org/apache/log4j/Logger".equals(callingClsName)
@@ -153,17 +155,37 @@
if (stack.getStackDepth() > 0) {
OpcodeStack.Item item = stack.getStackItem(0);
loggingClassName = (String)item.getConstant();
- if (loggingClassName != null)
- loggingClassName = loggingClassName.replace('.', '/');
+ if (loggingClassName != null) {
+ loggingClassName = loggingClassName.replace('.', '/');
+ }
}
} else if ("(Ljava/lang/String;Lorg/apache/log4j/spi/LoggerFactory;)Lorg/apache/log4j/Logger;".equals(signature)) {
if (stack.getStackDepth() > 1) {
OpcodeStack.Item item = stack.getStackItem(1);
loggingClassName = (String)item.getConstant();
- if (loggingClassName != null)
- loggingClassName = loggingClassName.replace('.', '/');
+ if (loggingClassName != null) {
+ loggingClassName = loggingClassName.replace('.', '/');
+ }
}
}
+ } else if ("org/apache/commons/logging/LogFactory".equals(callingClsName)
+ && "getLog".equals(mthName)) {
+ String signature = getSigConstantOperand();
+
+ if ("(Ljava/lang/Class;)Lorg/apache/commons/logging/Log;".equals(signature)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ loggingClassName = (String)item.getUserValue();
+ }
+ } else if ("(Ljava/lang/String;)Lorg/apache/commons/logging/Log;".equals(signature)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ loggingClassName = (String)item.getConstant();
+ if (loggingClassName != null) {
+ loggingClassName = loggingClassName.replace('.', '/');
+ }
+ }
+ }
}
if (loggingClassName != null) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-09-11 15:42:02
|
Revision: 1610
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1610&view=rev
Author: dbrosius
Date: 2010-09-11 15:41:55 +0000 (Sat, 11 Sep 2010)
Log Message:
-----------
add LO_STUTTERED_MESSAGE to LoggerOddities
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/samples/LO_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-09-10 13:02:35 UTC (rev 1609)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-09-11 15:41:55 UTC (rev 1610)
@@ -165,7 +165,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousClusteredSessionSupport" speed="fast" reports="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.LoggerOddities" speed="fast" reports="LO_SUSPECT_LOG_CLASS,LO_SUSPECT_LOG_PARAMETER" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.LoggerOddities" speed="fast" reports="LO_SUSPECT_LOG_CLASS,LO_SUSPECT_LOG_PARAMETER,LO_STUTTERED_MESSAGE" />
<Detector class="com.mebigfatguy.fbcontrib.detect.IncorrectInternalClassUse" speed="fast" reports="IICU_INCORRECT_INTERNAL_CLASS_USE" />
@@ -331,6 +331,7 @@
<BugPattern abbrev="SCSS" type="SCSS_SUSPICIOUS_CLUSTERED_SESSION_SUPPORT" category="CORRECTNESS" />
<BugPattern abbrev="LO" type="LO_SUSPECT_LOG_CLASS" category="CORRECTNESS" />
<BugPattern abbrev="LO" type="LO_SUSPECT_LOG_PARAMETER" category="CORRECTNESS" />
+ <BugPattern abbrev="LO" type="LO_STUTTERED_MESSAGE" category="STYLE" />
<BugPattern abbrev="IICU" type="IICU_INCORRECT_INTERNAL_CLASS_USE" category="CORRECTNESS" />
<BugPattern abbrev="DSOC" type="DSOC_DUBIOUS_SET_OF_COLLECTIONS" category="PERFORMANCE" />
<BugPattern abbrev="BED" type="BED_BOGUS_EXCEPTION_DECLARATION" category="CORRECTNESS" />
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-09-10 13:02:35 UTC (rev 1609)
+++ trunk/fb-contrib/etc/messages.xml 2010-09-11 15:41:55 UTC (rev 1610)
@@ -882,7 +882,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.LoggerOddities">
<Details>
<![CDATA[
- <p>Looks for odd patterns of use of Logger classes from either log4j or slf4j.</p>
+ <p>Looks for odd patterns of use of Logger classes from either log4j, slf4j or commons logging.</p>
<p>It is a fast detector</p>
]]>
</Details>
@@ -2699,6 +2699,21 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="LO_STUTTERED_MESSAGE">
+ <ShortDescription>method stutters exception message in logger</ShortDescription>
+ <LongDescription>method {1} stutters exception message in logger</LongDescription>
+ <Details>
+ <![CDATA[
+ This method uses a logger method that takes an exception, and passes the result of
+ the getMessage() method on the exception that occurred as the log message.
+ Since you are already passing in the exception, that message is already present in the
+ logs, and by passing it in as the message, you are just stuttering information.
+ It would be more helpful to provide a hand written message that describes the error in
+ this method, possibly including the values of key variables.
+ ]]>
+ </Details>
+ </BugPattern>
<BugPattern type="IICU_INCORRECT_INTERNAL_CLASS_USE">
<ShortDescription>class relies on internal api classes</ShortDescription>
Modified: trunk/fb-contrib/samples/LO_Sample.java
===================================================================
--- trunk/fb-contrib/samples/LO_Sample.java 2010-09-10 13:02:35 UTC (rev 1609)
+++ trunk/fb-contrib/samples/LO_Sample.java 2010-09-11 15:41:55 UTC (rev 1610)
@@ -1,3 +1,8 @@
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
import org.apache.log4j.Logger;
@@ -11,4 +16,22 @@
{
}
+
+ public void testStutter() throws IOException
+ {
+ InputStream is = null;
+ try
+ {
+ File f = new File("Foo");
+ is = new FileInputStream(f);
+ }
+ catch (Exception e)
+ {
+ l1.error(e.getMessage(), e);
+ }
+ finally
+ {
+ is.close();
+ }
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2010-09-10 13:02:35 UTC (rev 1609)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LoggerOddities.java 2010-09-11 15:41:55 UTC (rev 1610)
@@ -18,11 +18,16 @@
*/
package com.mebigfatguy.fbcontrib.detect;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.classfile.ConstantClass;
import org.apache.bcel.classfile.ConstantPool;
import org.apache.bcel.classfile.ConstantUtf8;
+import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.generic.Type;
@@ -33,6 +38,24 @@
import edu.umd.cs.findbugs.ba.ClassContext;
public class LoggerOddities extends BytecodeScanningDetector {
+ private static JavaClass THROWABLE_CLASS;
+ private static Set<String> loggerMethods;
+
+ static {
+ try {
+ THROWABLE_CLASS = Repository.lookupClass("java/lang/Throwable");
+
+ loggerMethods = new HashSet<String>();
+ loggerMethods.add("trace");
+ loggerMethods.add("debug");
+ loggerMethods.add("info");
+ loggerMethods.add("warn");
+ loggerMethods.add("error");
+ loggerMethods.add("fatal");
+ } catch (ClassNotFoundException cnfe) {
+ THROWABLE_CLASS = null;
+ }
+ }
private final BugReporter bugReporter;
private OpcodeStack stack;
private String clsName;
@@ -111,6 +134,8 @@
@Override
public void sawOpcode(int seen) {
String ldcClassName = null;
+ int exMessageReg = -1;
+
try {
if ((seen == LDC) || (seen == LDC_W)) {
Constant c = getConstantRefOperand();
@@ -198,7 +223,42 @@
}
}
}
+ } else if (((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) && (THROWABLE_CLASS != null)) {
+ String mthName = getNameConstantOperand();
+ if (mthName.equals("getMessage")) {
+ String callingClsName = getClassConstantOperand();
+ JavaClass cls = Repository.lookupClass(callingClsName);
+ if (cls.instanceOf(THROWABLE_CLASS)) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item exItem = stack.getStackItem(0);
+ exMessageReg = exItem.getRegisterNumber();
+ }
+ }
+ } else if (loggerMethods.contains(mthName)) {
+ String callingClsName = getClassConstantOperand();
+ if (callingClsName.endsWith("Log") || (callingClsName.endsWith("Logger"))) {
+ String sig = getSigConstantOperand();
+ if ("(Ljava/lang/String;Ljava/lang/Throwable;)V".equals(sig) || "(Ljava/lang/Object;Ljava/lang/Throwable;)V".equals(sig)) {
+ if (stack.getStackDepth() >= 2) {
+ OpcodeStack.Item exItem = stack.getStackItem(0);
+ OpcodeStack.Item msgItem = stack.getStackItem(1);
+
+ Integer exReg = (Integer)msgItem.getUserValue();
+ if (exReg != null) {
+ if (exReg.intValue() == exItem.getRegisterNumber()) {
+ bugReporter.reportBug(new BugInstance(this, "LO_STUTTERED_MESSAGE", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ }
+ }
+ }
+ }
+ }
+ }
}
+ } catch (ClassNotFoundException cnfe) {
+ bugReporter.reportMissingClass(cnfe);
} finally {
stack.sawOpcode(this, seen);
if (ldcClassName != null) {
@@ -207,6 +267,12 @@
item.setUserValue(ldcClassName);
}
}
+ if (exMessageReg >= 0) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(Integer.valueOf(exMessageReg));
+ }
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-09-13 05:15:28
|
Revision: 1612
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1612&view=rev
Author: dbrosius
Date: 2010-09-13 05:15:21 +0000 (Mon, 13 Sep 2010)
Log Message:
-----------
attempt to reduce FP on SNG by removing compound conditionals
Modified Paths:
--------------
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/samples/SNG_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2010-09-13 02:00:34 UTC (rev 1611)
+++ trunk/fb-contrib/etc/findbugs.xml 2010-09-13 05:15:21 UTC (rev 1612)
@@ -195,7 +195,9 @@
<!-- <Detector class="com.mebigfatguy.fbcontrib.detect.ContraVariantArrayAssignment" speed="fast" hidden="true" reports="CVAA_CONTRAVARIANT_ARRAY_ASSIGNMENT,CVAA_CONTRAVARIANT_ELEMENT_ASSIGNMENT" /> -->
<Detector class="com.mebigfatguy.fbcontrib.detect.NonFunctionalField" speed="fast" reports="NFF_NON_FUNCTIONAL_FIELD" />
- <!-- <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard" speed="fast" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />-->
+
+ <Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousNullGuard" speed="fast" reports="SNG_SUSPICIOUS_NULL_FIELD_GUARD,SNG_SUSPICIOUS_NULL_LOCAL_GUARD" />
+
<Detector class="com.mebigfatguy.fbcontrib.detect.MoreDumbMethods" speed="fast"
reports="MDM_RUNTIME_EXIT_OR_HALT,MDM_RUNFINALIZATION,MDM_BIGDECIMAL_EQUALS,MDM_INETADDRESS_GETLOCALHOST,MDM_PROMISCUOUS_SERVERSOCKET,MDM_RANDOM_SEED,MDM_SECURERANDOM_CTOR,MDM_SECURERANDOM_GETSEED,MDM_THREAD_PRIORITIES,MDM_THREAD_YIELD,MDM_WAIT_WITHOUT_TIMEOUT,MDM_THREAD_FAIRNESS,MDM_REENTRANTLOCK_HELDBY,MDM_STRING_BYTES_ENCODING,MDM_SETDEFAULTLOCALE" />
Modified: trunk/fb-contrib/samples/SNG_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SNG_Sample.java 2010-09-13 02:00:34 UTC (rev 1611)
+++ trunk/fb-contrib/samples/SNG_Sample.java 2010-09-13 05:15:21 UTC (rev 1612)
@@ -99,4 +99,12 @@
f1 = f2;
}
}
+
+ public void fpDup()
+ {
+ if ((f1 == null) || file.isDirectory())
+ {
+ f1 = file.getPath();
+ }
+ }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-09-13 02:00:34 UTC (rev 1611)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-09-13 05:15:21 UTC (rev 1612)
@@ -44,7 +44,7 @@
*/
public class SuspiciousNullGuard extends BytecodeScanningDetector {
- private BugReporter bugReporter;
+ private final BugReporter bugReporter;
private OpcodeStack stack;
private LocalVariableTable lvt;
private Map<Integer, NullGuard> nullGuards;
@@ -126,6 +126,24 @@
}
break;
+ case IFEQ:
+ case IFNE:
+ case IFLE:
+ case IFGE:
+ case IFGT:
+ case IFLT:
+ case IF_ICMPEQ:
+ case IF_ICMPNE:
+ case IF_ICMPGT:
+ case IF_ICMPLE:
+ case IF_ACMPEQ:
+ case IF_ACMPNE: {
+ int target = getBranchTarget();
+ removeGuardsBeforePC(target);
+ }
+ break;
+
+
case ALOAD:
case ALOAD_0:
case ALOAD_1:
@@ -193,8 +211,9 @@
removeGuardForRegister(reg);
} else {
XField field = item.getXField();
- if (field != null)
+ if (field != null) {
removeGuardForField(field);
+ }
}
}
}
@@ -230,6 +249,16 @@
}
}
+ private void removeGuardsBeforePC(int pc) {
+ Iterator<Integer> it = nullGuards.keySet().iterator();
+ while (it.hasNext()) {
+ Integer nullGuardPC = it.next();
+ if (pc > nullGuardPC) {
+ it.remove();
+ }
+ }
+ }
+
static class NullGuard {
int register;
XField field;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-09-19 02:30:51
|
Revision: 1614
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1614&view=rev
Author: dbrosius
Date: 2010-09-19 02:30:45 +0000 (Sun, 19 Sep 2010)
Log Message:
-----------
Redo SNG to look for if (a != null) a = somevalue;
Modified Paths:
--------------
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/samples/SNG_Sample.java
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2010-09-17 04:51:05 UTC (rev 1613)
+++ trunk/fb-contrib/etc/messages.xml 2010-09-19 02:30:45 UTC (rev 1614)
@@ -1081,10 +1081,9 @@
<Details>
<![CDATA[
<p>Looks for code that checks to see if a field or local variable is not null,
- before entering a code block either an if, or while statement, and then doesn't
- reference that field or local in the block of code that is guarded by the null
- check. It is likely that null check is being done on the wrong variable, either
- because of a copy/paste error, or a change in implementation.</p>
+ before entering a code block either an if, or while statement, and then reassigns that
+ field or local variable. It is likely that guard should have been to see if that
+ field or local variable is null, not, not null</p>
<p>It is a fast detector</p>
]]>
</Details>
@@ -2953,26 +2952,25 @@
</BugPattern>
<BugPattern type="SNG_SUSPICIOUS_NULL_FIELD_GUARD">
- <ShortDescription>Method tests a field for null as guard for code that doesn't use it</ShortDescription>
- <LongDescription>Method {1} tests a field for null as guard for code that doesn't use it</LongDescription>
+ <ShortDescription>Method tests a field for not null as guard and reassigns it</ShortDescription>
+ <LongDescription>Method {1} tests a field for not null as guard and reassigns it</LongDescription>
<Details>
<![CDATA[
<p>This method tests a field to make sure it's not null before executing a conditional block of
- code. However, it does not appear that this block of code relies on the field in question, so the
- choice of null guard seems dubious. It is possible that the code block calls a method that requires
- this field not to be null, but that would seem like an odd construct.</p>
+ code. However in the conditional block is reassigns the field. It is likely that the guard
+ should have been a check to see if the field is null, not that the field was not null.</p>
]]>
</Details>
</BugPattern>
<BugPattern type="SNG_SUSPICIOUS_NULL_LOCAL_GUARD">
- <ShortDescription>Method tests a local variable for null as guard for code that doesn't use it</ShortDescription>
- <LongDescription>Method {1} tests a local variable for null as guard for code that doesn't use it</LongDescription>
+ <ShortDescription>Method tests a local variable for not null as guard and reassigns it</ShortDescription>
+ <LongDescription>Method {1} tests a local variable for not null as guard and reassigns it</LongDescription>
<Details>
<![CDATA[
<p>This method tests a local variable to make sure it's not null before executing a conditional block of
- code. However, this block of does not access the local variable in question, so the
- choice of null guard seems wrong. Perhaps this is a copy/paste mistake.</p>
+ code. However in the conditional block is reassigns the local variable. It is likely that the guard
+ should have been a check to see if the local variable is null, not that the local variable was not null.</p>
]]>
</Details>
</BugPattern>
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2010-09-17 04:51:05 UTC (rev 1613)
+++ trunk/fb-contrib/htdocs/index.shtml 2010-09-19 02:30:45 UTC (rev 1614)
@@ -82,12 +82,10 @@
must be restricted to covariant or invariant usage.
<span style="color: #0000FF;">--contributed by Bhaskar Maddala - THANKS!</span></li>
<li><b>[SNG] Suspicious Null Guard</b><br/>
- Looks for code that checks to see if a field or local variable is not null,
- before entering a code block (either an if, or while statement) and then doesn't
- reference that field or local in the block of code that is guarded by the null
- check. Instead it references another object of the same type. It is likely that null
- check is being done on the wrong variable, either because of a copy/paste error,
- or a change in implementation.</li>
+ Looks for code that checks to see if a field or local variable is not null
+ before entering a code block either an if, or while statement, and reassigns
+ that field or variable. It seems that perhaps the guard should check if the field
+ or variable is null.</li>
<li><b>[PUS] Possible Unsuspected Serialization</b><br/>
Looks for serialization of non-static inner classes. As this serializes
the enclosing class, it may unintentionally bring in more to the serialization
Modified: trunk/fb-contrib/samples/SNG_Sample.java
===================================================================
--- trunk/fb-contrib/samples/SNG_Sample.java 2010-09-17 04:51:05 UTC (rev 1613)
+++ trunk/fb-contrib/samples/SNG_Sample.java 2010-09-19 02:30:45 UTC (rev 1614)
@@ -7,104 +7,33 @@
private Object f1 = null;
private final Object f2 = null;
private final File file = null;
- private byte[] buffer = null;
+ private final byte[] buffer = null;
- public String badSNGFields()
+ public void badSNGFields()
{
if (f1 != null)
{
- return f2.toString();
+ f1 = "Foo";
}
-
- return null;
}
- public String badSNGLocals(Object l1, Object l2)
+ public void badSNGLocals(Object l1, Object l2)
{
if (l1 != null)
{
- return l2.toString();
- }
-
- return null;
+ l1 = l2;
+ }
}
- public boolean fpReturn(Object o)
- {
- return o != null;
- }
-
- public boolean fpAssign(Object o)
- {
- boolean b = o != null;
- return b;
- }
-
- public boolean fpField()
- {
- if (f1 != null)
- {
- return true;
+ public void fpNGFieldSetToNull() {
+ if (f1 != null) {
+ f1 = null;
}
-
- return false;
}
- public void fpAssert()
- {
- assert (f1 != null) && f1.equals(f2);
- }
-
- public Object fpSetNull(Object o) {
- if (o != null)
- {
- o = null;
+ public void fpNGLocalSetToNull(String s1) {
+ if (s1 != null) {
+ s1 = null;
}
-
- return o;
}
-
- public void fpSetMemberNull()
- {
- if (f1 != null)
- {
- f1 = null;
- }
- }
-
- public void fpDual(Object o1, Object o2)
- {
- if ((o1 == null) || (o2 == null))
- {
- throw new IllegalArgumentException("o1/o2 can not be null");
- }
- }
-
- public void discard()
- {
- if (file != null)
- {
- file.delete();
- }
- else if (buffer != null)
- {
- buffer = EMPTY_BYTE_ARRAY;
- }
- }
-
- public void fpCompound()
- {
- if ((file == null) || (buffer[0] == 0))
- {
- f1 = f2;
- }
- }
-
- public void fpDup()
- {
- if ((f1 == null) || file.isDirectory())
- {
- f1 = file.getPath();
- }
- }
}
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-09-17 04:51:05 UTC (rev 1613)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousNullGuard.java 2010-09-19 02:30:45 UTC (rev 1614)
@@ -19,12 +19,9 @@
package com.mebigfatguy.fbcontrib.detect;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import org.apache.bcel.classfile.Code;
-import org.apache.bcel.classfile.LocalVariable;
-import org.apache.bcel.classfile.LocalVariableTable;
import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
@@ -37,16 +34,14 @@
/**
* looks for code that checks to see if a field or local variable is not null,
- * before entering a code block either an if, or while statement, and then doesn't
- * reference that field or local in the block of code that is guarded by the null
- * check. It is likely that null check is being done on the wrong variable, either
- * because of a copy/paste error, or a change in implementation.
+ * before entering a code block either an if, or while statement, and reassigns
+ * that field or variable. It seems that perhaps the guard should check if the field
+ * or variable is null.
*/
public class SuspiciousNullGuard extends BytecodeScanningDetector {
private final BugReporter bugReporter;
private OpcodeStack stack;
- private LocalVariableTable lvt;
private Map<Integer, NullGuard> nullGuards;
/**
@@ -80,14 +75,9 @@
*/
@Override
public void visitCode(Code obj) {
- try {
- stack.resetForMethodEntry(this);
- lvt = getMethod().getLocalVariableTable();
- nullGuards.clear();
- super.visitCode(obj);
- } finally {
- lvt = null;
- }
+ stack.resetForMethodEntry(this);
+ nullGuards.clear();
+ super.visitCode(obj);
}
/**
@@ -99,14 +89,7 @@
public void sawOpcode(int seen) {
try {
Integer pc = Integer.valueOf(getPC());
- NullGuard guard = nullGuards.remove(pc);
- if ((guard != null) && guard.sawSignatureOfGuard()) {
- boolean localBug = guard.getRegister() >= 0;
- bugReporter.reportBug(new BugInstance(this, localBug ? "SNG_SUSPICIOUS_NULL_LOCAL_GUARD" : "SNG_SUSPICIOUS_NULL_FIELD_GUARD", localBug ? NORMAL_PRIORITY : LOW_PRIORITY)
- .addClass(this)
- .addMethod(this)
- .addSourceLine(this, guard.getLocation()));
- }
+ nullGuards.remove(pc);
switch (seen) {
case IFNULL: {
@@ -125,140 +108,93 @@
}
}
break;
-
- case IFEQ:
- case IFNE:
- case IFLE:
- case IFGE:
- case IFGT:
- case IFLT:
- case IF_ICMPEQ:
- case IF_ICMPNE:
- case IF_ICMPGT:
- case IF_ICMPLE:
- case IF_ACMPEQ:
- case IF_ACMPNE: {
- int target = getBranchTarget();
- removeGuardsBeforePC(target);
- }
- break;
-
-
- case ALOAD:
- case ALOAD_0:
- case ALOAD_1:
- case ALOAD_2:
- case ALOAD_3: {
- if (lvt != null) {
- LocalVariable lv = lvt.getLocalVariable(RegisterUtils.getALoadReg(this, seen), getNextPC());
- if (lv != null) {
- markNullGuards(lv.getSignature());
- }
- }
- }
- break;
case ASTORE:
case ASTORE_0:
case ASTORE_1:
case ASTORE_2:
case ASTORE_3: {
- removeGuardForRegister(RegisterUtils.getAStoreReg(this, seen));
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (!item.isNull()) {
+ NullGuard guard = findNullGuardWithRegister(RegisterUtils.getAStoreReg(this, seen));
+ if (guard != null) {
+ bugReporter.reportBug(new BugInstance(this, "SNG_SUSPICIOUS_NULL_LOCAL_GUARD", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ nullGuards.remove(guard);
+ }
+ }
+ }
}
break;
- case GETFIELD: {
- markNullGuards(getSigConstantOperand());
- }
- break;
-
case PUTFIELD: {
- removeGuardForField(getXField());
- }
- break;
-
- case INVOKEVIRTUAL:
- case INVOKEINTERFACE: {
- if (nullGuards.size() > 0) {
- String clsName = getClassConstantOperand();
- String methodName = getNameConstantOperand();
- if ("java/io/PrintStream".equals(clsName) && methodName.startsWith("print")) {
- nullGuards.clear();
+ if (stack.getStackDepth() > 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ if (!item.isNull()) {
+ XField xf = getXFieldOperand();
+ if (xf != null) {
+ NullGuard guard = findNullGuardWithField(xf);
+ if (guard != null) {
+ bugReporter.reportBug(new BugInstance(this, "SNG_SUSPICIOUS_NULL_FIELD_GUARD", NORMAL_PRIORITY)
+ .addClass(this)
+ .addMethod(this)
+ .addSourceLine(this));
+ nullGuards.remove(guard);
+ }
+ }
}
}
}
break;
-
+
+ case IFEQ:
+ case IFNE:
+ case IFLT:
+ case IFGE:
+ case IFGT:
+ case IFLE:
+ case IF_ICMPEQ:
+ case IF_ICMPNE:
+ case IF_ICMPLT:
+ case IF_ICMPGE:
+ case IF_ICMPGT:
+ case IF_ICMPLE:
+ case IF_ACMPEQ:
+ case IF_ACMPNE:
+ case GOTO:
+ case GOTO_W:
case IFNONNULL:
- case ATHROW: {
- nullGuards.clear();
- }
+ nullGuards.clear();
break;
-
- case GOTO: {
- if (stack.getStackDepth() > 0) {
- nullGuards.clear();
- }
- }
- break;
}
} finally {
stack.sawOpcode(this, seen);
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item item = stack.getStackItem(0);
- int reg = item.getRegisterNumber();
- if (reg >= 0) {
- removeGuardForRegister(reg);
- } else {
- XField field = item.getXField();
- if (field != null) {
- removeGuardForField(field);
- }
- }
- }
}
}
- private void markNullGuards(String signature) {
- for (NullGuard ng : nullGuards.values()) {
- if (ng.getSignature().equals(signature)) {
- ng.markSignatureOfGuard();
+ private NullGuard findNullGuardWithRegister(int reg) {
+ for (NullGuard guard : nullGuards.values()) {
+ if (guard.getRegister() == reg) {
+ return guard;
}
}
+
+ return null;
}
- private void removeGuardForRegister(int reg) {
- Iterator<NullGuard> it = nullGuards.values().iterator();
- while (it.hasNext()) {
- NullGuard guard = it.next();
- if (reg == guard.getRegister()) {
- it.remove();
+ private NullGuard findNullGuardWithField(XField field) {
+ for (NullGuard guard : nullGuards.values()) {
+ if (field.equals(guard.getField())) {
+ return guard;
}
}
+
+ return null;
}
- private void removeGuardForField(XField field) {
- Iterator<NullGuard> it = nullGuards.values().iterator();
- while (it.hasNext()) {
- NullGuard guard = it.next();
- if (field != null) {
- if (field.equals(guard.getField())) {
- it.remove();
- }
- }
- }
- }
-
- private void removeGuardsBeforePC(int pc) {
- Iterator<Integer> it = nullGuards.keySet().iterator();
- while (it.hasNext()) {
- Integer nullGuardPC = it.next();
- if (pc > nullGuardPC) {
- it.remove();
- }
- }
- }
-
static class NullGuard {
int register;
XField field;
@@ -296,13 +232,5 @@
public String getSignature() {
return signature;
}
-
- public void markSignatureOfGuard() {
- sawSignature = true;
- }
-
- public boolean sawSignatureOfGuard() {
- return sawSignature;
- }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|