Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib:[1491] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2010-01-18 17:00:11
|
Revision: 1491
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1491&view=rev
Author: dbrosius
Date: 2010-01-18 16:59:58 +0000 (Mon, 18 Jan 2010)
Log Message:
-----------
clear loadedClassTypes on a store, if the variable isn't a class array
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-18 16:57:46 UTC (rev 1490)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-18 16:59:58 UTC (rev 1491)
@@ -106,14 +106,16 @@
case ASTORE_2:
case ASTORE_3:
case ASTORE: {
+ Integer reg = Integer.valueOf(RegisterUtils.getAStoreReg(this, seen));
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);
+ localClassTypes.put(reg, arrayTypes);
+ return;
}
- }
+ }
+ localClassTypes.remove(reg);
}
break;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-18 17:27:26
|
Revision: 1496
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1496&view=rev
Author: dbrosius
Date: 2010-01-18 17:27:20 +0000 (Mon, 18 Jan 2010)
Log Message:
-----------
add support for fields
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-18 17:26:55 UTC (rev 1495)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-18 17:27:20 UTC (rev 1496)
@@ -41,6 +41,7 @@
private BugReporter bugReporter;
private OpcodeStack stack;
private Map<Integer, String[]> localClassTypes;
+ private Map<String, String[]> fieldClassTypes;
public ReflectionOnObjectMethods(BugReporter bugReporter) {
this.bugReporter = bugReporter;
@@ -51,10 +52,12 @@
try {
stack = new OpcodeStack();
localClassTypes = new HashMap<Integer, String[]>();
+ fieldClassTypes = new HashMap<String, String[]>();
super.visitClassContext(classContext);
} finally {
stack = null;
localClassTypes = null;
+ fieldClassTypes = null;
}
}
@@ -101,6 +104,28 @@
}
break;
+ case PUTFIELD:
+ case PUTSTATIC: {
+ String name = getNameConstantOperand();
+ if (stack.getStackDepth() >= 1) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ String[] arrayTypes = (String[])item.getUserValue();
+ if (arrayTypes != null) {
+ fieldClassTypes.put(name, arrayTypes);
+ return;
+ }
+ }
+ fieldClassTypes.remove(name);
+ }
+ break;
+
+ case GETFIELD:
+ case GETSTATIC: {
+ String name = getNameConstantOperand();
+ loadedTypes = fieldClassTypes.get(name);
+ }
+ break;
+
case ASTORE_0:
case ASTORE_1:
case ASTORE_2:
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-18 17:32:53
|
Revision: 1498
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1498&view=rev
Author: dbrosius
Date: 2010-01-18 17:32:47 +0000 (Mon, 18 Jan 2010)
Log Message:
-----------
try to support null parms
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-18 17:31:58 UTC (rev 1497)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-18 17:32:47 UTC (rev 1498)
@@ -164,7 +164,7 @@
if (stack.getStackDepth() >= 2) {
OpcodeStack.Item clsArgs = stack.getStackItem(0);
String[] arrayTypes = (String[])clsArgs.getUserValue();
- if (arrayTypes != null) {
+ if ((arrayTypes != null) || (clsArgs.isNull())) {
OpcodeStack.Item methodItem = stack.getStackItem(1);
String methodName = (String)methodItem.getConstant();
if (methodName != null) {
@@ -215,12 +215,14 @@
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(";");
+ if (parmTypes != null) {
+ 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();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-19 01:27:43
|
Revision: 1500
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1500&view=rev
Author: dbrosius
Date: 2010-01-19 01:27:35 +0000 (Tue, 19 Jan 2010)
Log Message:
-----------
support the Class array being setup in clinit
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-19 00:20:13 UTC (rev 1499)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-19 01:27:35 UTC (rev 1500)
@@ -6,6 +6,8 @@
import java.util.Set;
import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.Method;
import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
@@ -53,6 +55,13 @@
stack = new OpcodeStack();
localClassTypes = new HashMap<Integer, String[]>();
fieldClassTypes = new HashMap<String, String[]>();
+ JavaClass cls = classContext.getJavaClass();
+ Method staticInit = findStaticInitializer(cls);
+ if (staticInit != null) {
+ setupVisitorForClass(cls);
+ doVisitMethod(staticInit);
+ }
+
super.visitClassContext(classContext);
} finally {
stack = null;
@@ -228,4 +237,14 @@
return sb.toString();
}
+ private Method findStaticInitializer(JavaClass cls) {
+ Method[] methods = cls.getMethods();
+ for (Method m : methods) {
+ if ("<clinit>".equals(m.getName())) {
+ return m;
+ }
+ }
+
+ return null;
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-19 01:36:03
|
Revision: 1501
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1501&view=rev
Author: dbrosius
Date: 2010-01-19 01:35:57 +0000 (Tue, 19 Jan 2010)
Log Message:
-----------
support null (as new Class[0]) for getMethod parms
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-19 01:27:35 UTC (rev 1500)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-19 01:35:57 UTC (rev 1501)
@@ -179,7 +179,7 @@
if (methodName != null) {
String reflectionSig = buildReflectionSignature(methodName, arrayTypes);
if (objectSigs.contains(reflectionSig)) {
- loadedTypes = arrayTypes;
+ loadedTypes = (arrayTypes == null) ? new String[0] : arrayTypes;
}
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-19 02:08:53
|
Revision: 1504
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1504&view=rev
Author: dbrosius
Date: 2010-01-19 02:08:47 +0000 (Tue, 19 Jan 2010)
Log Message:
-----------
java doc
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-19 02:01:16 UTC (rev 1503)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-19 02:08:47 UTC (rev 1504)
@@ -1,3 +1,21 @@
+/*
+ * 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;
@@ -45,10 +63,20 @@
private Map<Integer, String[]> localClassTypes;
private Map<String, String[]> fieldClassTypes;
+ /**
+ * constructs a ROOM detector given the reporter to report bugs on
+ * @param bugReporter the sync of bug reports
+ */
public ReflectionOnObjectMethods(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
+ /**
+ * implements the visitor to create the stack and local and field maps
+ * for Class arrays to be used for getting the reflection method
+ *
+ * @param classContext the context object of the currently parse class
+ */
@Override
public void visitClassContext(ClassContext classContext) {
try {
@@ -70,6 +98,11 @@
}
}
+ /**
+ * implements the visitor to reset the opcode stack and clear the local variable map@
+ *
+ * @param obj the context object of the currently parsed code block
+ */
@Override
public void visitCode(Code obj) {
stack.resetForMethodEntry(this);
@@ -77,6 +110,12 @@
super.visitCode(obj);
}
+ /**
+ * implements the visitor to look for calls that invoke a method through reflection
+ * where the method is defined in java.lang.Object
+ *
+ * @param seen the currently parsed opcode
+ */
@Override
public void sawOpcode(int seen) {
Integer arraySize = null;
@@ -220,6 +259,15 @@
}
}
+ /**
+ * builds a string that represents the signature of the method call that is being
+ * executed though reflection.
+ *
+ * @param methodName the method name
+ * @param parmTypes the array of parameter types of the method
+ *
+ * @return a signature string minus the return type
+ */
private String buildReflectionSignature(String methodName, String[] parmTypes) {
StringBuilder sb = new StringBuilder(64);
sb.append(methodName);
@@ -237,6 +285,13 @@
return sb.toString();
}
+ /**
+ * finds the method that is the static initializer for the class
+ *
+ * @param cls the class to find the initializer for
+ *
+ * @return the Method of the static initializer or null if this class has none
+ */
private Method findStaticInitializer(JavaClass cls) {
Method[] methods = cls.getMethods();
for (Method m : methods) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2010-01-23 12:43:09
|
Revision: 1505
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1505&view=rev
Author: dbrosius
Date: 2010-01-23 12:17:32 +0000 (Sat, 23 Jan 2010)
Log Message:
-----------
guard against NPEs
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-19 02:08:47 UTC (rev 1504)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-01-23 12:17:32 UTC (rev 1505)
@@ -276,6 +276,8 @@
for (int i = 0; i < parmTypes.length; i++) {
sb.append("L");
String type = parmTypes[i];
+ if (type == null)
+ return "";
sb.append(type);
if ((type.length() > 1) || ("IJ".indexOf(type) < 0))
sb.append(";");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <dbr...@us...> - 2011-01-22 01:20:22
|
Revision: 1650
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1650&view=rev
Author: dbrosius
Date: 2011-01-22 01:20:16 +0000 (Sat, 22 Jan 2011)
Log Message:
-----------
clone() is declared protected so don't report reflection on clone()
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2010-12-13 00:09:47 UTC (rev 1649)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ReflectionOnObjectMethods.java 2011-01-22 01:20:16 UTC (rev 1650)
@@ -1,17 +1,17 @@
/*
* 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
@@ -36,33 +36,33 @@
import edu.umd.cs.findbugs.ba.ClassContext;
/**
- * looks for method calls through reflection on methods found in
+ * 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("clone()"); // clone is declared protected
objectSigs.add("equals(Ljava/lang/Object;)");
objectSigs.add("finalize()");
objectSigs.add("getClass()");
objectSigs.add("hashCode()");
- objectSigs.add("notify()");
+ objectSigs.add("notify()");
objectSigs.add("notifyAll()");
objectSigs.add("toString()");
objectSigs.add("wait");
objectSigs.add("wait(J)");
objectSigs.add("wait(JI");
-
+
}
- private BugReporter bugReporter;
+ private final BugReporter bugReporter;
private OpcodeStack stack;
private Map<Integer, String[]> localClassTypes;
private Map<String, String[]> fieldClassTypes;
-
+
/**
* constructs a ROOM detector given the reporter to report bugs on
* @param bugReporter the sync of bug reports
@@ -70,11 +70,11 @@
public ReflectionOnObjectMethods(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
-
+
/**
* implements the visitor to create the stack and local and field maps
* for Class arrays to be used for getting the reflection method
- *
+ *
* @param classContext the context object of the currently parse class
*/
@Override
@@ -89,7 +89,7 @@
setupVisitorForClass(cls);
doVisitMethod(staticInit);
}
-
+
super.visitClassContext(classContext);
} finally {
stack = null;
@@ -97,10 +97,10 @@
fieldClassTypes = null;
}
}
-
+
/**
* implements the visitor to reset the opcode stack and clear the local variable map@
- *
+ *
* @param obj the context object of the currently parsed code block
*/
@Override
@@ -109,18 +109,18 @@
localClassTypes.clear();
super.visitCode(obj);
}
-
+
/**
* implements the visitor to look for calls that invoke a method through reflection
* where the method is defined in java.lang.Object
- *
+ *
* @param seen the currently parsed opcode
*/
@Override
public void sawOpcode(int seen) {
Integer arraySize = null;
String[] loadedTypes = null;
-
+
try {
switch (seen) {
case ANEWARRAY: {
@@ -132,7 +132,7 @@
}
}
break;
-
+
case AASTORE: {
if (stack.getStackDepth() >= 3) {
OpcodeStack.Item arrayItem = stack.getStackItem(2);
@@ -151,7 +151,7 @@
}
}
break;
-
+
case PUTFIELD:
case PUTSTATIC: {
String name = getNameConstantOperand();
@@ -166,14 +166,14 @@
fieldClassTypes.remove(name);
}
break;
-
+
case GETFIELD:
case GETSTATIC: {
String name = getNameConstantOperand();
- loadedTypes = fieldClassTypes.get(name);
+ loadedTypes = fieldClassTypes.get(name);
}
break;
-
+
case ASTORE_0:
case ASTORE_1:
case ASTORE_2:
@@ -191,17 +191,17 @@
localClassTypes.remove(reg);
}
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));
- }
+ loadedTypes = localClassTypes.get(Integer.valueOf(reg));
+ }
break;
-
+
case INVOKEVIRTUAL: {
String cls = getClassConstantOperand();
if ("java/lang/Class".equals(cls)) {
@@ -258,14 +258,14 @@
}
}
}
-
+
/**
* builds a string that represents the signature of the method call that is being
* executed though reflection.
- *
+ *
* @param methodName the method name
* @param parmTypes the array of parameter types of the method
- *
+ *
* @return a signature string minus the return type
*/
private String buildReflectionSignature(String methodName, String[] parmTypes) {
@@ -273,25 +273,26 @@
sb.append(methodName);
sb.append("(");
if (parmTypes != null) {
- for (int i = 0; i < parmTypes.length; i++) {
+ for (String type : parmTypes) {
sb.append("L");
- String type = parmTypes[i];
- if (type == null)
+ if (type == null) {
return "";
+ }
sb.append(type);
- if ((type.length() > 1) || ("IJ".indexOf(type) < 0))
+ if ((type.length() > 1) || ("IJ".indexOf(type) < 0)) {
sb.append(";");
+ }
}
}
sb.append(")");
return sb.toString();
}
-
+
/**
* finds the method that is the static initializer for the class
- *
+ *
* @param cls the class to find the initializer for
- *
+ *
* @return the Method of the static initializer or null if this class has none
*/
private Method findStaticInitializer(JavaClass cls) {
@@ -301,7 +302,7 @@
return m;
}
}
-
+
return null;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|