Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [640] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/d
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-09-10 03:54:57
|
Revision: 640 http://svn.sourceforge.net/fb-contrib/?rev=640&view=rev Author: dbrosius Date: 2006-09-09 20:54:51 -0700 (Sat, 09 Sep 2006) Log Message: ----------- misc fixes suggested by fb-contrib Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-09-10 01:51:12 UTC (rev 639) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-09-10 03:54:51 UTC (rev 640) @@ -347,7 +347,7 @@ * @return the package of the class */ private String getPackageName(final String className) { - int dotPos = className.lastIndexOf("."); + int dotPos = className.lastIndexOf('.'); if (dotPos < 0) return ""; return className.substring(0, dotPos); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-09-10 01:51:12 UTC (rev 639) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java 2006-09-10 03:54:51 UTC (rev 640) @@ -85,7 +85,7 @@ JavaClass cls = classContext.getJavaClass(); Field[] fields = cls.getFields(); for (Field f : fields) { - if ((!f.isStatic() && f.getName().indexOf("$") < 0) && f.isPrivate()) { + if ((!f.isStatic() && f.getName().indexOf('$') < 0) && f.isPrivate()) { FieldAnnotation fa = new FieldAnnotation(cls.getClassName(), f.getName(), f.getSignature(), false); localizableFields.put(f.getName(), new FieldInfo(fa)); } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java 2006-09-10 01:51:12 UTC (rev 639) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java 2006-09-10 03:54:51 UTC (rev 640) @@ -189,8 +189,9 @@ String fieldInfo = fields.keySet().iterator().next(); - String fieldName = fieldInfo.substring(0, fieldInfo.indexOf(":")); - String fieldType = fieldInfo.substring(fieldInfo.indexOf(":")+1); + int colonPos = fieldInfo.indexOf(':'); + String fieldName = fieldInfo.substring(0, colonPos); + String fieldType = fieldInfo.substring(colonPos+1); if (!attType.equals(fieldType)) continue; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-17 07:56:43
|
Revision: 736 http://svn.sourceforge.net/fb-contrib/?rev=736&view=rev Author: dbrosius Date: 2006-12-16 23:53:07 -0800 (Sat, 16 Dec 2006) Log Message: ----------- warnings Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2006-12-17 07:53:07 UTC (rev 736) @@ -27,8 +27,6 @@ import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; -import edu.umd.cs.findbugs.FindBugsAnalysisFeatures; -import edu.umd.cs.findbugs.ba.AnalysisContext; import edu.umd.cs.findbugs.ba.ClassContext; /** Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java 2006-12-17 07:53:07 UTC (rev 736) @@ -121,6 +121,7 @@ * @param obj the code that is currently being parsed */ @Override + @SuppressWarnings("unchecked") public void visitCode(final Code obj) { stack.resetForMethodEntry(this); thisClsAccessCount = 0; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2006-12-17 07:53:07 UTC (rev 736) @@ -133,6 +133,7 @@ * * @return whether the code blocks are the same */ + @SuppressWarnings("deprecation") public boolean codeEquals(Code child, Code parent) { byte[] childBytes = child.getCode(); byte[] parentBytes = parent.getCode(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-17 07:47:05 UTC (rev 735) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-17 07:53:07 UTC (rev 736) @@ -29,7 +29,6 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.generic.Type; -import com.mebigfatguy.fbcontrib.detect.DubiousListCollection.FieldInfo; import com.mebigfatguy.fbcontrib.utils.Integer14; import edu.umd.cs.findbugs.BugInstance; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-12-22 18:21:00
|
Revision: 748 http://svn.sourceforge.net/fb-contrib/?rev=748&view=rev Author: dbrosius Date: 2006-12-22 10:21:00 -0800 (Fri, 22 Dec 2006) Log Message: ----------- BAS fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java 2006-12-22 04:18:42 UTC (rev 747) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java 2006-12-22 18:21:00 UTC (rev 748) @@ -127,15 +127,15 @@ if (seen == INVOKEINTERFACE) { String className = this.getClassConstantOperand(); - String methodName = getNameConstantOperand(); - String signature = getSigConstantOperand(); if (className.startsWith("java/util/") && className.endsWith("List")) { + String signature = getSigConstantOperand(); XField field = getFieldFromStack(stack, signature); if (field != null) { String fieldName = field.getName(); FieldInfo fi = fieldsReported.get(fieldName); if (fi != null) { + String methodName = getNameConstantOperand(); String methodInfo = methodName + signature; if (listMethods.contains(methodInfo)) fieldsReported.remove(fieldName); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-22 04:18:42 UTC (rev 747) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java 2006-12-22 18:21:00 UTC (rev 748) @@ -364,11 +364,11 @@ */ private void processCollectionStore(int seen) { String fieldClassName = getDottedClassConstantOperand(); - String fieldName = getNameConstantOperand(); if (fieldClassName.equals(className)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); if (item.getUserValue() != null) { + String fieldName = getNameConstantOperand(); if (fieldName != null) { FieldInfo fi = collectionFields.get(fieldName); if (fi != null) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2006-12-22 04:18:42 UTC (rev 747) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java 2006-12-22 18:21:00 UTC (rev 748) @@ -321,12 +321,13 @@ } private void removeUselessDefiners(final int reg) { - String methodSig = getSigConstantOperand(); - String methodName = getNameConstantOperand(); - String methodInfo = methodName + methodSig; Map<JavaClass, List<String>> definers = parameterDefiners.get(Integer14.valueOf(reg)); if ((definers != null) && (definers.size() > 0)) { + String methodSig = getSigConstantOperand(); + String methodName = getNameConstantOperand(); + String methodInfo = methodName + methodSig; + Iterator<List<String>> it = definers.values().iterator(); while (it.hasNext()) { boolean methodDefined = false; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java 2006-12-22 04:18:42 UTC (rev 747) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java 2006-12-22 18:21:00 UTC (rev 748) @@ -192,7 +192,6 @@ String clsName = getClassConstantOperand(); String methodName = getNameConstantOperand(); String methodInfo = clsName + ":" + methodName; - String methodSig = getSigConstantOperand(); String thisMethodInfo = (clsName.equals(getClassName())) ? (methodName + ":" + methodSig) : "0"; if (expensiveCalls.contains(methodInfo) || expensiveThisCalls.contains(thisMethodInfo)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-01 07:58:42
|
Revision: 810 http://svn.sourceforge.net/fb-contrib/?rev=810&view=rev Author: dbrosius Date: 2007-01-31 23:58:41 -0800 (Wed, 31 Jan 2007) Log Message: ----------- make 1.4 compatible Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2007-01-31 03:45:16 UTC (rev 809) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2007-02-01 07:58:41 UTC (rev 810) @@ -94,11 +94,11 @@ ignoreRegs.clear(); Method method = getMethod(); if (!method.isStatic()) - ignoreRegs.add(Integer.valueOf(0)); + ignoreRegs.add(Integer14.valueOf(0)); int[] parmRegs = RegisterUtils.getParameterRegisters(method); for (int parm : parmRegs) { - ignoreRegs.add(Integer.valueOf(parm)); + ignoreRegs.add(Integer14.valueOf(parm)); } rootScopeBlock = new ScopeBlock(0, obj.getLength()); @@ -106,7 +106,7 @@ CodeException[] exceptions = obj.getExceptionTable(); if (exceptions != null) { for (CodeException ex : exceptions) { - catchHandlers.add(Integer.valueOf(ex.getHandlerPC())); + catchHandlers.add(Integer14.valueOf(ex.getHandlerPC())); } } @@ -143,7 +143,7 @@ || ((seen >= FSTORE_0) && (seen <= FSTORE_1)) || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) { int reg = RegisterUtils.getStoreReg(this, seen); - Integer iReg = Integer.valueOf(reg); + Integer iReg = Integer14.valueOf(reg); int pc = getPC(); if (catchHandlers.contains(Integer14.valueOf(pc))) ignoreRegs.add(iReg); @@ -171,18 +171,18 @@ || ((seen >= FLOAD_0) && (seen <= FLOAD_1)) || ((seen >= DLOAD_0) && (seen <= DLOAD_1))) { int reg = RegisterUtils.getLoadReg(this, seen); - if (!ignoreRegs.contains(Integer.valueOf(reg))) { + if (!ignoreRegs.contains(Integer14.valueOf(reg))) { ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); if (sb != null) sb.addLoad(reg, getPC()); else - ignoreRegs.add(Integer.valueOf(reg)); + ignoreRegs.add(Integer14.valueOf(reg)); } } else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { int target = getBranchTarget(); if (target > getPC()) { if ((seen == GOTO) || (seen == GOTO_W)) { - Integer nextPC = Integer.valueOf(getNextPC()); + Integer nextPC = Integer14.valueOf(getNextPC()); if (!switchTargets.contains(nextPC)) { ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); if (sb == null) { @@ -226,8 +226,8 @@ int[] offsets = getSwitchOffsets(); List<Integer> targets = new ArrayList<Integer>(); for (int i = 0; i < offsets.length; i++) - targets.add(Integer.valueOf(offsets[i] + pc)); - Integer defOffset = Integer.valueOf(getDefaultSwitchOffset() + pc); + targets.add(Integer14.valueOf(offsets[i] + pc)); + Integer defOffset = Integer14.valueOf(getDefaultSwitchOffset() + pc); if (!targets.contains(defOffset)) targets.add(defOffset); Collections.sort(targets); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-01-31 03:45:16 UTC (rev 809) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-02-01 07:58:41 UTC (rev 810) @@ -24,6 +24,7 @@ import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; import edu.umd.cs.findbugs.BugInstance; @@ -103,7 +104,7 @@ if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { int reg = RegisterUtils.getALoadReg(this, seen); - Integer type = regValueType.get(Integer.valueOf(reg)); + Integer type = regValueType.get(Integer14.valueOf(reg)); if (type != null) state = type.intValue(); else @@ -114,14 +115,14 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); int reg = RegisterUtils.getAStoreReg(this, seen); - regValueType.put(Integer.valueOf(reg), (Integer)item.getUserValue()); + regValueType.put(Integer14.valueOf(reg), (Integer)item.getUserValue()); } state = SEEN_NOTHING; return; } if ((seen == ILOAD) || ((seen >= ILOAD_0) && (seen <= ILOAD_3))) { int reg = RegisterUtils.getLoadReg(this, seen); - Integer type = regValueType.get(Integer.valueOf(reg)); + Integer type = regValueType.get(Integer14.valueOf(reg)); if (type != null) state = type.intValue(); else @@ -132,7 +133,7 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); int reg = RegisterUtils.getStoreReg(this, seen); - regValueType.put(Integer.valueOf(reg), (Integer)item.getUserValue()); + regValueType.put(Integer14.valueOf(reg), (Integer)item.getUserValue()); } state = SEEN_NOTHING; return; @@ -226,7 +227,7 @@ if (state != SEEN_NOTHING) { if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); - item.setUserValue(Integer.valueOf(state)); + item.setUserValue(Integer14.valueOf(state)); } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-06-26 23:05:50
|
Revision: 892 http://svn.sourceforge.net/fb-contrib/?rev=892&view=rev Author: dbrosius Date: 2007-06-26 16:05:51 -0700 (Tue, 26 Jun 2007) Log Message: ----------- javadoc cleanups Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousWaitOnConcurrentObject.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or @@ -32,7 +32,7 @@ /** * looks for classes that implement interfaces by relying on methods being - * implemented in superclasses, even tho the superclass knows nothing about + * implemented in super classes, even though the superclass knows nothing about * the interface being implemented by the child. */ public class SpoiledChildInterfaceImplementor implements Detector { @@ -122,7 +122,7 @@ } /** - * removes methods found in an interface when a superinterface having the same methods + * removes methods found in an interface when a super interface having the same methods * is implemented in a parent. While this is somewhat hinky, we'll allow it. * * @param inf the interface to look for super interfaces for Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousWaitOnConcurrentObject.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousWaitOnConcurrentObject.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousWaitOnConcurrentObject.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or @@ -148,7 +148,7 @@ } /** - * checks if the curent opcode is a store, if so saves the register + * checks if the current opcode is a store, if so saves the register * * @param seen the opcode of the currently parsed instruction * @return if a store was seen Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2007-06-26 21:55:38 UTC (rev 891) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java 2007-06-26 23:05:51 UTC (rev 892) @@ -1,5 +1,5 @@ /* - * fb-contrib - Auxilliary detectors for Java programs + * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2007 Dave Brosius * * This library is free software; you can redistribute it and/or This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-09-15 04:29:09
|
Revision: 898 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=898&view=rev Author: dbrosius Date: 2007-09-14 21:29:10 -0700 (Fri, 14 Sep 2007) Log Message: ----------- initial checkin MRC detector Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InheritanceTypeChecking.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleIncompleteSerialization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java Added Paths: ----------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MethodReturnsConstant.java Property Changed: ---------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayBasedCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingAutoboxedOverloading.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DateComparison.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeclaredRuntimeException.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DubiousListCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FieldCouldBeLocal.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FinalParameters.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FloatingPointLoops.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InheritanceTypeChecking.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/JDBCVendorReliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LiteralStringComparison.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LocalSynchronizedCollection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ManualArrayCopy.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessInstanceRetrieval.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessMemberCollectionSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonCollectionMethodUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonOwnedSynchronization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NonRecycleableTaglibs.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OrphanedDOMNode.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/OverlyConcreteParameter.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ParallelLists.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PartiallyConstructedObjectAccess.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleIncompleteSerialization.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SQLInLoop.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/Section508Compliance.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SluggishGui.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SpuriousThreadStates.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousComparatorReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousWaitOnConcurrentObject.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SyncCollectionIterators.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/TailRecursion.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnnecessaryStoreBeforeReturn.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedCollectionContents.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseEnumCollections.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseSplit.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseToArray.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/package.html Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbnormalFinallyBlockReturn.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractOverriddenMethod.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayBasedCollections.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ArrayWrappedCallByReference.java ___________________________________________________________________ Name: svn:mime-type + text/plain Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2007-09-15 03:02:05 UTC (rev 897) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2007-09-15 04:29:10 UTC (rev 898) @@ -1,578 +1,578 @@ -/* - * fb-contrib - Auxilliary detectors for Java programs - * Copyright (C) 2005-2007 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.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.bcel.classfile.Code; -import org.apache.bcel.classfile.CodeException; -import org.apache.bcel.classfile.Method; - -import com.mebigfatguy.fbcontrib.utils.Integer14; -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.ba.ClassContext; - -/** - * looks for variable assignments at a scope larger than its use. In this case, - * the assignment can be pushed down into the smaller scope to reduce the performance - * impact of that assignment. - */ -public class BloatedAssignmentScope extends BytecodeScanningDetector -{ - BugReporter bugReporter; - private Set<Integer> ignoreRegs; - private ScopeBlock rootScopeBlock; - private Set<Integer> catchHandlers; - private Set<Integer> switchTargets; - private boolean dontReport; - private boolean sawDup; - private boolean sawNull; - - /** - * constructs a BAS detector given the reporter to report bugs on - - * @param bugReporter the sync of bug reports - */ - public BloatedAssignmentScope(BugReporter bugReporter) { - this.bugReporter = bugReporter; - } - - /** - * implements the visitor to create and the clear the register to location map - * - * @param classContext the context object of the currently parsed class - */ - @Override - public void visitClassContext(ClassContext classContext) { - try { - ignoreRegs = new HashSet<Integer>(); - catchHandlers = new HashSet<Integer>(); - switchTargets = new HashSet<Integer>(); - super.visitClassContext(classContext); - } finally { - ignoreRegs = null; - catchHandlers = null; - switchTargets = null; - } - } - - /** - * implements the visitor to reset the register to location map - * - * @param obj the context object of the currently parsed code block - */ - @Override - public void visitCode(Code obj) { - try { - - ignoreRegs.clear(); - Method method = getMethod(); - if (!method.isStatic()) - ignoreRegs.add(Integer14.valueOf(0)); - - int[] parmRegs = RegisterUtils.getParameterRegisters(method); - for (int parm : parmRegs) { - ignoreRegs.add(Integer14.valueOf(parm)); - } - - rootScopeBlock = new ScopeBlock(0, obj.getLength()); - catchHandlers.clear(); - CodeException[] exceptions = obj.getExceptionTable(); - if (exceptions != null) { - for (CodeException ex : exceptions) { - catchHandlers.add(Integer14.valueOf(ex.getHandlerPC())); - } - } - - switchTargets.clear(); - dontReport = false; - sawDup = false; - sawNull = false; - super.visitCode(obj); - - if (!dontReport) - rootScopeBlock.findBugs(new HashSet<Integer>()); - - } finally { - rootScopeBlock = null; - } - } - - /** - * implements the visitor to look for variables assigned below the scope - * in which they are used. - * - * @param seen the opcode of the currently parsed instruction - */ - @Override - public void sawOpcode(int seen) { - if ((seen == ASTORE) - || (seen == ISTORE) - || (seen == LSTORE) - || (seen == FSTORE) - || (seen == DSTORE) - || ((seen >= ASTORE_0) && (seen <= ASTORE_3)) - || ((seen >= ISTORE_0) && (seen <= ISTORE_3)) - || ((seen >= LSTORE_0) && (seen <= LSTORE_1)) - || ((seen >= FSTORE_0) && (seen <= FSTORE_1)) - || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) { - int reg = RegisterUtils.getStoreReg(this, seen); - Integer iReg = Integer14.valueOf(reg); - int pc = getPC(); - if (catchHandlers.contains(Integer14.valueOf(pc))) - ignoreRegs.add(iReg); - else if (sawNull) - ignoreRegs.add(iReg); - - if (!ignoreRegs.contains(iReg)) { - ScopeBlock sb = findScopeBlock(rootScopeBlock, pc); - if (sb != null) { - sb.addStore(reg, pc); - if (sawDup) - sb.addLoad(reg, pc); - } - else - ignoreRegs.add(iReg); - } - } else if ((seen == ALOAD) - || (seen == ILOAD) - || (seen == LLOAD) - || (seen == FLOAD) - || (seen == DLOAD) - || ((seen >= ALOAD_0) && (seen <= ALOAD_3)) - || ((seen >= ILOAD_0) && (seen <= ILOAD_3)) - || ((seen >= LLOAD_0) && (seen <= LLOAD_1)) - || ((seen >= FLOAD_0) && (seen <= FLOAD_1)) - || ((seen >= DLOAD_0) && (seen <= DLOAD_1))) { - int reg = RegisterUtils.getLoadReg(this, seen); - if (!ignoreRegs.contains(Integer14.valueOf(reg))) { - ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); - if (sb != null) - sb.addLoad(reg, getPC()); - else - ignoreRegs.add(Integer14.valueOf(reg)); - } - } else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { - int target = getBranchTarget(); - if (target > getPC()) { - if ((seen == GOTO) || (seen == GOTO_W)) { - Integer nextPC = Integer14.valueOf(getNextPC()); - if (!switchTargets.contains(nextPC)) { - ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); - if (sb == null) { - sb = new ScopeBlock(getPC(), target); - sb.setLoop(); - sb.setGoto(); - rootScopeBlock.addChild(sb); - } else { - sb = new ScopeBlock(getPC(), target); - sb.setGoto(); - rootScopeBlock.addChild(sb); - } - } - } else { - ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), target); - if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) { - if (sb.isGoto()) { - ScopeBlock parent = sb.getParent(); - sb.pushUpLoadStores(); - if (parent != null) - parent.removeChild(sb); - sb = new ScopeBlock(getPC(), target); - rootScopeBlock.addChild(sb); - } else { - sb.pushUpLoadStores(); - sb.setStart(getPC()); - sb.setFinish(target); - } - } else { - sb = new ScopeBlock(getPC(), target); - rootScopeBlock.addChild(sb); - } - } - } else { - ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); - if (sb != null) - sb.setLoop(); - } - } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) { - int pc = getPC(); - int[] offsets = getSwitchOffsets(); - List<Integer> targets = new ArrayList<Integer>(); - for (int i = 0; i < offsets.length; i++) - targets.add(Integer14.valueOf(offsets[i] + pc)); - Integer defOffset = Integer14.valueOf(getDefaultSwitchOffset() + pc); - if (!targets.contains(defOffset)) - targets.add(defOffset); - Collections.sort(targets); - - Integer lastTarget = targets.get(0); - for (int i = 1; i < targets.size(); i++) { - Integer nextTarget = targets.get(i); - ScopeBlock sb = new ScopeBlock(lastTarget.intValue(), nextTarget.intValue()); - rootScopeBlock.addChild(sb); - lastTarget = nextTarget; - } - switchTargets.addAll(targets); - } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEVIRTUAL)) { - if ("wasNull".equals(getNameConstantOperand()) - && "()Z".equals(getSigConstantOperand())) - dontReport = true; - } - - sawDup = (seen == DUP); - sawNull = (seen == ACONST_NULL); - } - - /** - * returns the scope block in which this register was assigned, by traversing the scope block tree - * - * @param sb the scope block to start searching in - * @param pc the current program counter - * @return the scope block or null if not found - */ - private ScopeBlock findScopeBlock(ScopeBlock sb, int pc) { - - if ((pc > sb.getStart()) && (pc < sb.getFinish())) { - if (sb.children != null) { - for (ScopeBlock child : sb.children) { - ScopeBlock foundSb = findScopeBlock(child, pc); - if (foundSb != null) - return foundSb; - } - } - return sb; - } - return null; - } - - /** - * returns an existing scope block that has the same target as the one looked for - * - * @param sb the scope block to start with - * @param target the target to look for - * - * @return the scope block found or null - */ - private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int start, int target) { - ScopeBlock parentBlock = null; - if ((sb.startLocation < start) && (sb.finishLocation >= start)) { - if ((sb.finishLocation <= target) || (sb.isGoto() && !sb.isLoop())) - parentBlock = sb; - } - - if (sb.children != null) - { - for (ScopeBlock child : sb.children) { - ScopeBlock targetBlock = findScopeBlockWithTarget(child, start, target); - if (targetBlock != null) - return targetBlock; - } - } - - return parentBlock; - } - - /** holds the description of a scope { } block, be it a for, if, while block - */ - private class ScopeBlock - { - private ScopeBlock parent; - private int startLocation; - private int finishLocation; - private boolean isLoop; - private boolean isGoto; - private Map<Integer, Integer> loads; - private Map<Integer, Integer> stores; - private List<ScopeBlock> children; - - /** construts a new scope block - * - * @param start the beginning of the block - * @param finish the end of the block - */ - public ScopeBlock(int start, int finish) { - parent = null; - startLocation = start; - finishLocation = finish; - isLoop = false; - isGoto = false; - loads = null; - stores = null; - children = null; - } - - /** - * returns a string representation of the scope block - * - * @returns a string representation - */ - @Override - public String toString() { - return "Start=" + startLocation + " Finish=" + finishLocation + " Loop=" + isLoop + " Loads=" + loads + " Stores=" + stores; - } - - /** - * returns the scope blocks parent - * - * @return the parent of this scope block - */ - public ScopeBlock getParent() { - return parent; - } - - /** returns the start of the block - * - * @return the start of the block - */ - public int getStart() { - return startLocation; - } - - /** returns the end of the block - * - * @return the end of the block - */ - public int getFinish() { - return finishLocation; - } - - /** - * sets the start pc of the block - * @param start the start pc - */ - public void setStart(int start) { - startLocation = start; - } - - /** - * sets the finish pc of the block - * @param finish the finish pc - */ - public void setFinish(int finish) { - finishLocation = finish; - } - - public boolean hasChildren() { - return children != null; - } - /** - * sets that this block is a loop - */ - public void setLoop() { - isLoop = true; - } - - /** - * returns whether this scope block is a loop - * - * @returns whether this block is a loop - */ - public boolean isLoop() { - return isLoop; - } - - /** - * sets that this block was caused from a goto, (an if block exit) - */ - public void setGoto() { - isGoto = true; - } - - /** - * returns whether this block was caused from a goto - * - * @returns whether this block was caused by a goto - */ - public boolean isGoto() { - return isGoto; - } - - /** - * adds the register as a store in this scope block - * - * @param reg the register that was stored - * @param pc the instruction that did the store - */ - public void addStore(int reg, int pc) { - if (stores == null) - stores = new HashMap<Integer, Integer>(); - - stores.put(Integer14.valueOf(reg), Integer14.valueOf(pc)); - } - - /** - * adds the register as a load in this scope block - * - * @param reg the register that was loaded - * @param pc the instruction that did the load - */ - public void addLoad(int reg, int pc) { - if (loads == null) - loads = new HashMap<Integer, Integer>(); - - loads.put(Integer14.valueOf(reg), Integer14.valueOf(pc)); - } - - /** - * adds a scope block to this subtree by finding the correct place in the hierarchy to store it - * - * @param child the scope block to add to the tree - */ - public void addChild(ScopeBlock newChild) { - newChild.parent = this; - - if (children != null) { - for (ScopeBlock child : children) { - if ((newChild.startLocation > child.startLocation) && (newChild.finishLocation < child.finishLocation)) { - child.addChild(newChild); - return; - } - } - int pos = 0; - for (ScopeBlock child : children) { - if (newChild.startLocation < child.startLocation) { - children.add(pos, newChild); - return; - } - pos++; - } - children.add(newChild); - return; - } - children = new ArrayList<ScopeBlock>(); - children.add(newChild); - } - - /** - * removes a child from this node - * @param child the child to remove - */ - public void removeChild(ScopeBlock child) { - if (children != null) - children.remove(child); - } - - /** - * report stores that occur at scopes higher than associated loads that are not involved with loops - */ - public void findBugs(Set<Integer> parentUsedRegs) { - if (isLoop) - return; - - Set<Integer> usedRegs = new HashSet<Integer>(parentUsedRegs); - if (stores != null) - usedRegs.addAll(stores.keySet()); - if (loads != null) - usedRegs.addAll(loads.keySet()); - - if (stores != null) { - if (loads != null) - stores.keySet().removeAll(loads.keySet()); - stores.keySet().removeAll(parentUsedRegs); - - if (stores.size() > 0) { - if (children != null) { - for (Map.Entry<Integer, Integer> entry : stores.entrySet()) { - int childUseCount = 0; - boolean inLoop = false; - Integer reg = entry.getKey(); - for (ScopeBlock child : children) { - if (child.usesReg(reg)) { - if (child.isLoop) { - inLoop = true; - break; - } - childUseCount++; - } - } - if ((!inLoop) && (childUseCount == 1)) { - bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY) - .addClass(BloatedAssignmentScope.this) - .addMethod(BloatedAssignmentScope.this) - .addSourceLine(BloatedAssignmentScope.this, entry.getValue().intValue())); - } - } - } - } - } - - if (children != null) { - for (ScopeBlock child : children) { - child.findBugs(usedRegs); - } - } - } - - /** - * returns whether this block either loads or stores into the register in question - * - * @param reg the register to look for loads or stores - * - * @return whether the block uses the register - */ - public boolean usesReg(Integer reg) { - if ((loads != null) && (loads.containsKey(reg))) - return true; - if ((stores != null) && (stores.containsKey(reg))) - return true; - - if (children != null) { - for (ScopeBlock child : children) { - if (child.usesReg(reg)) - return true; - } - } - - return false; - } - - /** - * push all loads and stores to this block up to the parent - */ - public void pushUpLoadStores() { - if (parent != null) { - if (loads != null) { - if (parent.loads != null) - parent.loads.putAll(loads); - else - parent.loads = loads; - } - if (stores != null) { - if (parent.stores != null) - parent.stores.putAll(stores); - else - parent.stores = stores; - } - loads = null; - stores = null; - } - } - } -} +/* + * fb-contrib - Auxilliary detectors for Java programs + * Copyright (C) 2005-2007 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.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.bcel.classfile.Code; +import org.apache.bcel.classfile.CodeException; +import org.apache.bcel.classfile.Method; + +import com.mebigfatguy.fbcontrib.utils.Integer14; +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.ba.ClassContext; + +/** + * looks for variable assignments at a scope larger than its use. In this case, + * the assignment can be pushed down into the smaller scope to reduce the performance + * impact of that assignment. + */ +public class BloatedAssignmentScope extends BytecodeScanningDetector +{ + BugReporter bugReporter; + private Set<Integer> ignoreRegs; + private ScopeBlock rootScopeBlock; + private Set<Integer> catchHandlers; + private Set<Integer> switchTargets; + private boolean dontReport; + private boolean sawDup; + private boolean sawNull; + + /** + * constructs a BAS detector given the reporter to report bugs on + + * @param bugReporter the sync of bug reports + */ + public BloatedAssignmentScope(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * implements the visitor to create and the clear the register to location map + * + * @param classContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + ignoreRegs = new HashSet<Integer>(); + catchHandlers = new HashSet<Integer>(); + switchTargets = new HashSet<Integer>(); + super.visitClassContext(classContext); + } finally { + ignoreRegs = null; + catchHandlers = null; + switchTargets = null; + } + } + + /** + * implements the visitor to reset the register to location map + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + try { + + ignoreRegs.clear(); + Method method = getMethod(); + if (!method.isStatic()) + ignoreRegs.add(Integer14.valueOf(0)); + + int[] parmRegs = RegisterUtils.getParameterRegisters(method); + for (int parm : parmRegs) { + ignoreRegs.add(Integer14.valueOf(parm)); + } + + rootScopeBlock = new ScopeBlock(0, obj.getLength()); + catchHandlers.clear(); + CodeException[] exceptions = obj.getExceptionTable(); + if (exceptions != null) { + for (CodeException ex : exceptions) { + catchHandlers.add(Integer14.valueOf(ex.getHandlerPC())); + } + } + + switchTargets.clear(); + dontReport = false; + sawDup = false; + sawNull = false; + super.visitCode(obj); + + if (!dontReport) + rootScopeBlock.findBugs(new HashSet<Integer>()); + + } finally { + rootScopeBlock = null; + } + } + + /** + * implements the visitor to look for variables assigned below the scope + * in which they are used. + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + if ((seen == ASTORE) + || (seen == ISTORE) + || (seen == LSTORE) + || (seen == FSTORE) + || (seen == DSTORE) + || ((seen >= ASTORE_0) && (seen <= ASTORE_3)) + || ((seen >= ISTORE_0) && (seen <= ISTORE_3)) + || ((seen >= LSTORE_0) && (seen <= LSTORE_1)) + || ((seen >= FSTORE_0) && (seen <= FSTORE_1)) + || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) { + int reg = RegisterUtils.getStoreReg(this, seen); + Integer iReg = Integer14.valueOf(reg); + int pc = getPC(); + if (catchHandlers.contains(Integer14.valueOf(pc))) + ignoreRegs.add(iReg); + else if (sawNull) + ignoreRegs.add(iReg); + + if (!ignoreRegs.contains(iReg)) { + ScopeBlock sb = findScopeBlock(rootScopeBlock, pc); + if (sb != null) { + sb.addStore(reg, pc); + if (sawDup) + sb.addLoad(reg, pc); + } + else + ignoreRegs.add(iReg); + } + } else if ((seen == ALOAD) + || (seen == ILOAD) + || (seen == LLOAD) + || (seen == FLOAD) + || (seen == DLOAD) + || ((seen >= ALOAD_0) && (seen <= ALOAD_3)) + || ((seen >= ILOAD_0) && (seen <= ILOAD_3)) + || ((seen >= LLOAD_0) && (seen <= LLOAD_1)) + || ((seen >= FLOAD_0) && (seen <= FLOAD_1)) + || ((seen >= DLOAD_0) && (seen <= DLOAD_1))) { + int reg = RegisterUtils.getLoadReg(this, seen); + if (!ignoreRegs.contains(Integer14.valueOf(reg))) { + ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); + if (sb != null) + sb.addLoad(reg, getPC()); + else + ignoreRegs.add(Integer14.valueOf(reg)); + } + } else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { + int target = getBranchTarget(); + if (target > getPC()) { + if ((seen == GOTO) || (seen == GOTO_W)) { + Integer nextPC = Integer14.valueOf(getNextPC()); + if (!switchTargets.contains(nextPC)) { + ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC()); + if (sb == null) { + sb = new ScopeBlock(getPC(), target); + sb.setLoop(); + sb.setGoto(); + rootScopeBlock.addChild(sb); + } else { + sb = new ScopeBlock(getPC(), target); + sb.setGoto(); + rootScopeBlock.addChild(sb); + } + } + } else { + ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), target); + if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) { + if (sb.isGoto()) { + ScopeBlock parent = sb.getParent(); + sb.pushUpLoadStores(); + if (parent != null) + parent.removeChild(sb); + sb = new ScopeBlock(getPC(), target); + rootScopeBlock.addChild(sb); + } else { + sb.pushUpLoadStores(); + sb.setStart(getPC()); + sb.setFinish(target); + } + } else { + sb = new ScopeBlock(getPC(), target); + rootScopeBlock.addChild(sb); + } + } + } else { + ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC()); + if (sb != null) + sb.setLoop(); + } + } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) { + int pc = getPC(); + int[] offsets = getSwitchOffsets(); + List<Integer> targets = new ArrayList<Integer>(); + for (int i = 0; i < offsets.length; i++) + targets.add(Integer14.valueOf(offsets[i] + pc)); + Integer defOffset = Integer14.valueOf(getDefaultSwitchOffset() + pc); + if (!targets.contains(defOffset)) + targets.add(defOffset); + Collections.sort(targets); + + Integer lastTarget = targets.get(0); + for (int i = 1; i < targets.size(); i++) { + Integer nextTarget = targets.get(i); + ScopeBlock sb = new ScopeBlock(lastTarget.intValue(), nextTarget.intValue()); + rootScopeBlock.addChild(sb); + lastTarget = nextTarget; + } + switchTargets.addAll(targets); + } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEVIRTUAL)) { + if ("wasNull".equals(getNameConstantOperand()) + && "()Z".equals(getSigConstantOperand())) + dontReport = true; + } + + sawDup = (seen == DUP); + sawNull = (seen == ACONST_NULL); + } + + /** + * returns the scope block in which this register was assigned, by traversing the scope block tree + * + * @param sb the scope block to start searching in + * @param pc the current program counter + * @return the scope block or null if not found + */ + private ScopeBlock findScopeBlock(ScopeBlock sb, int pc) { + + if ((pc > sb.getStart()) && (pc < sb.getFinish())) { + if (sb.children != null) { + for (ScopeBlock child : sb.children) { + ScopeBlock foundSb = findScopeBlock(child, pc); + if (foundSb != null) + return foundSb; + } + } + return sb; + } + return null; + } + + /** + * returns an existing scope block that has the same target as the one looked for + * + * @param sb the scope block to start with + * @param target the target to look for + * + * @return the scope block found or null + */ + private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int start, int target) { + ScopeBlock parentBlock = null; + if ((sb.startLocation < start) && (sb.finishLocation >= start)) { + if ((sb.finishLocation <= target) || (sb.isGoto() && !sb.isLoop())) + parentBlock = sb; + } + + if (sb.children != null) + { + for (ScopeBlock child : sb.children) { + ScopeBlock targetBlock = findScopeBlockWithTarget(child, start, target); + if (targetBlock != null) + return targetBlock; + } + } + + return parentBlock; + } + + /** holds the description of a scope { } block, be it a for, if, while block + */ + private class ScopeBlock + { + private ScopeBlock parent; + private int startLocation; + private int finishLocation; + private boolean isLoop; + private boolean isGoto; + private Map<Integer, Integer> loads; + private Map<Integer, Integer> stores; + private List<ScopeBlock> children; + + /** construts a new scope block + * + * @param start the beginning of the block + * @param finish the end of the block + */ + public ScopeBlock(int start, int finish) { + parent = null; + startLocation = start; + finishLocation = finish; + isLoop = false; + isGoto = false; + loads = null; + stores = null; + children = null; + } + + /** + * returns a string representation of the scope block + * + * @returns a string representation + */ + @Override + public String toString() { + return "Start=" + startLocation + " Finish=" + finishLocation + " Loop=" + isLoop + " Loads=" + loads + " Stores=" + stores; + } + + /** + * returns the scope blocks parent + * + * @return the parent of this scope block + */ + public ScopeBlock getParent() { + return parent; + } + + /** returns the start of the block + * + * @return the start of the block + */ + public int getStart() { + return startLocation; + } + + /** returns the end of the block + * + * @return the end of the block + */ + public int getFinish() { + return finishLocation; + } + + /** + * sets the start pc of the block + * @param start the start pc + */ + public void setStart(int start) { + startLocation = start; + } + + /** + * sets the finish pc of the block + * @param finish the finish pc + */ + public void setFinish(int finish) { + finishLocation = finish; + } + + public boolean hasChildren() { + return children != null; + } + /** + * sets that this block is a loop + */ + public void setLoop() { + isLoop = true; + } + + /** + * returns whether this scope block is a loop + * + * @returns whether this block is a loop + */ + public boolean isLoop() { + return isLoop; + } + + /** + * sets that this block was caused from a goto, (an if block exit) + */ + public void setGoto() { + isGoto = true; + } + + /** + * returns whether this block was caused from a goto + * + * @returns whether this block was caused by a goto + */ + public boolean isGoto() { + return isGoto; + } + + /** + * adds the register as a store in this scope block + * + * @param reg the register that was stored + * @param pc the instruction that did the store + */ + public void addStore(int reg, int pc) { + if (stores == null) + stores = new HashMap<Integer, Integer>(); + + stores.put(Integer14.valueOf(reg), Integer14.valueOf(pc)); + } + + /** + * adds the register as a load in this scope block + * + * @param reg the register that was loaded + * @param pc the instruction that did the load + */ + public void addLoad(int reg, int pc) { + if (loads == null) + loads = new HashMap<Integer, Integer>(); + + loads.put(Integer14.valueOf(reg), Integer14.valueOf(pc)); + } + + /** + * adds a scope block to this subtree by finding the correct place in the hierarchy to store it + * + * @param child the scope block to add to the tree + */ + public void addChild(ScopeBlock newChild) { + newChild.parent = this; + + if (children != null) { + for (ScopeBlock child : children) { + if ((newChild.startLocation > child.startLocation) && (newChild.finishLocation < child.finishLocation)) { + child.addChild(newChild); + return; + } + } + int pos = 0; + for (ScopeBlock child : children) { + if (newChild.startLocation < child.startLocation) { + children.add(pos, newChild); + return; + } + pos++; + } + children.add(newChild); + return; + } + children = new ArrayList<ScopeBlock>(); + children.add(newChild); + } + + /** + * removes a child from this node + * @param child the child to remove + */ + public void removeChild(ScopeBlock child) { + if (children != null) + children.remove(child); + } + + /** + * report stores that occur at scopes higher than associated loads that are not involved with loops + */ + public void findBugs(Set<Integer> parentUsedRegs) { + if (isLoop) + return; + + Set<Integer> usedRegs = new HashSet<Integer>(parentUsedRegs); + if (stores != null) + usedRegs.addAll(stores.keySet()); + if (loads != null) + usedRegs.addAll(loads.keySet()); + + if (stores != null) { + if (loads != null) + stores.keySet().removeAll(loads.keySet()); + stores.keySet().removeAll(parentUsedRegs); + + if (stores.size() > 0) { + if (children != null) { + for (Map.Entry<Integer, Integer> entry : stores.entrySet()) { + int childUseCount = 0; + boolean inLoop = false; + Integer reg = entry.getKey(); + for (ScopeBlock child : children) { + if (child.usesReg(reg)) { + if (child.isLoop) { + inLoop = true; + break; + } + childUseCount++; + } + } + if ((!inLoop) && (childUseCount == 1)) { + bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY) + .addClass(BloatedAssignmentScope.this) + .addMethod(BloatedAssignmentScope.this) + .addSourceLine(BloatedAssignmentScope.this, entry.getValue().intValue())); + } + } + } + } + } + + if (children != null) { + for (ScopeBlock child : children) { + child.findBugs(usedRegs); + } + } + } + + /** + * returns whether this block either loads or stores into the register in question + * + * @param reg the register to look for loads or stores + * + * @return whether the block uses the register + */ + public boolean usesReg(Integer reg) { + if ((loads != null) && (loads.containsKey(reg))) + return true; + if ((stores != null) && (stores.containsKey(reg))) + return true; + + if (children != null) { + for (ScopeBlock child : children) { + if (child.usesReg(reg)) + return true; + } + } + + return false; + } + + /** + * push all loads and stores to this block up to the parent + */ + public void pushUpLoadStores() { + if (parent != null) { + if (loads != null) { + if (parent.loads != null) + parent.loads.putAll(loads); + else + parent.loads = loads; + } + if (stores != null) { + if (parent.stores != null) + parent.stores.putAll(stores); + else + parent.stores = stores; + } + loads = null; + stores = null; + } + } + } +} Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java ___________________________________________________________________ Name: svn:mime-type + text/plain Name: svn:eol-style + native Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ClassEnvy.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingAutoboxedOverloading.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DateComparison.java ___________________________________________________________________ Name: svn:mime-type + text/plain Property changes on: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeclaredRuntimeException.java ___________________________________________________________________ Name: svn:mime-type + text/plain Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-09-15 03:02:05 UTC (rev 897) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2007-09-15 04:29:10 UTC (rev 898) @@ -1,378 +1,378 @@ -/* - * fb-contrib - Auxiliary detectors for Java programs - * Copyright (C) 2005-2007 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.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.bcel.Repository; -import org.apache.bcel.classfile.Code; -import org.apache.bcel.classfile.JavaClass; - -import com.mebigfatguy.fbcontrib.utils.Integer14; -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.FieldAnnotation; -import edu.umd.cs.findbugs.OpcodeStack; -import edu.umd.cs.findbugs.ba.ClassContext; -import edu.umd.cs.findbugs.ba.XField; -import edu.umd.cs.findbugs.classfile.FieldDescriptor; - -/** - * looks for deletion of items from a collection using the remove method - * of the collection at the same time that the collection is being iterated on. If - * this occurs the iterator will become invalid and throw a ConcurrentModificationException. - * Instead, the remove should be called on the iterator itself. - */ -public class DeletingWhileIterating extends BytecodeScanningDetector -{ - private static JavaClass collectionClass; - private static JavaClass iteratorClass; - private static final Set<String> collectionMethods; - static { - try { - collectionClass = Repository.lookupClass("java.util.Collection"); - iteratorClass = Repository.lookupClass("java.util.Iterator"); - } catch (ClassNotFoundException cnfe) { - collectionClass = null; - iteratorClass = null; - } - - collectionMethods = new HashSet<String>(); - collectionMethods.add("entrySet()Ljava/lang/Set;"); - collectionMethods.add("keySet()Ljava/lang/Set;"); - collectionMethods.add("values()Ljava/lang/Collection;"); - } - private static final Map<String, Integer> modifyingMethods = new HashMap<String, Integer>(); - static { - modifyingMethods.put("add(Ljava/lang/Object;)Z", Integer14.valueOf(1)); - modifyingMethods.put("addAll(Ljava/util/Collection;)Z", Integer14.valueOf(1)); - modifyingMethods.put("addAll(ILjava/util/Collection;)Z", Integer14.valueOf(2)); - modifyingMethods.put("clear()V", Integer14.valueOf(0)); - modifyingMethods.put("remove(I)Ljava/lang/Object;", Integer14.valueOf(1)); - modifyingMethods.put("removeAll(Ljava/util/Collection;)Z", Integer14.valueOf(1)); - modifyingMethods.put("retainAll(Ljava/util/Collection;)Z", Integer14.valueOf(1)); - modifyingMethods.put("set(ILjava/lang/Object;)Ljava/lang/Object;", Integer14.valueOf(2)); - - } - - private BugReporter bugReporter; - private OpcodeStack stack; - private List<Set<Comparable>> collectionGroups; - private Map<Integer, Integer> groupToIterator; - private Map<Integer, Loop> loops; - - /** - * constructs a DWI detector given the reporter to report bugs on - * @param bugReporter the sync of bug reports - */ - public DeletingWhileIterating(BugReporter bugReporter) { - this.bugReporter = bugReporter; - } - - /** - * implements the visitor to setup the opcode stack, collectionGroups, groupToIterator and loops - * - * @param classContext the context object of the currently parsed class - */ - @Override - public void visitClassContext(ClassContext classContext) { - if ((collectionClass == null) || (iteratorClass == null)) - return; - - try { - stack = new OpcodeStack(); - collectionGroups = new ArrayList<Set<Comparable>>(); - groupToIterator = new HashMap<Integer, Integer>(); - loops = new HashMap<Integer, Loop>(); - super.visitClassContext(classContext); - } finally { - stack = null; - collectionGroups = null; - groupToIterator = null; - loops = null; - } - } - - /** - * implements the visitor to reset the stack, collectionGroups, groupToIterator and loops - * - * @param obj the context object of the currently parsed code block - */ - @Override - public void visitCode(Code obj) { - stack.resetForMethodEntry(this); - collectionGroups.clear(); - groupToIterator.clear(); - loops.clear(); - super.visitCode(obj); - } - - /** - * implements the visitor to look for deletes on collections that are being iterated - * - * @param seen the opcode of the currently parsed instruction - */ - @Override - public void sawOpcode(int seen) { - int groupId = -1; - - try { - if (seen == INVOKEINTERFACE) - { - String className = getClassConstantOperand(); - String methodName = getNameConstantOperand(); - String signature = getSigConstantOperand(); - String methodInfo = methodName + signature; - - if (isCollection(className)) { - if (collectionMethods.contains(methodInfo)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - groupId = findCollectionGroup(itm, true); - - } - } else if ("iterator()Ljava/util/Iterator;".equals(methodInfo)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - groupId = findCollectionGroup(itm, true); - } - } else if ("remove(Ljava/lang/Object;)Z".equals(methodInfo)) { - if (stack.getStackDepth() > 1) { - OpcodeStack.Item itm = stack.getStackItem(1); - int id = findCollectionGroup(itm, true); - if (id >= 0) { - Integer it = groupToIterator.get(Integer14.valueOf(id)); - Loop loop = loops.get(it); - if (loop != null) { - int pc = getPC(); - if (loop.hasPC(pc)) { - bugReporter.reportBug(new BugInstance(this, "DWI_DELETING_WHILE_ITERATING", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - } - } - } - } - } else { - Integer numArgs = modifyingMethods.get(methodInfo); - if (numArgs != null) { - if (stack.getStackDepth() > numArgs.intValue()) { - OpcodeStack.Item itm = stack.getStackItem(numArgs.intValue()); - int id = findCollectionGroup(itm, true); - if (id >= 0) { - Integer it = groupToIterator.get(Integer14.valueOf(id)); - if (it != null) { - Loop loop = loops.get(it); - if (loop != null) { - int pc = getPC(); - if (loop.hasPC(pc)) { - bugReporter.reportBug(new BugInstance(this, "DWI_MODIFYING_WHILE_ITERATING", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); - } - } - } - } - } - } - } - } else if ("java/util/Iterator".equals(className) && "hasNext()Z".equals(methodInfo)) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - Integer id = (Integer)itm.getUserValue(); - if (id != null) - groupId = id.intValue(); - } - } - } else if (seen == PUTFIELD) { - if (stack.getStackDepth() > 1) { - OpcodeStack.Item itm = stack.getStackItem(0); - - Integer id = (Integer)itm.getUserValue(); - if (id == null) { - FieldAnnotation fa = FieldAnnotation.fromFieldDescriptor(new FieldDescriptor(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand(), false)); - itm = new OpcodeStack.Item(itm.getSignature(), fa, stack.getStackItem(1).getRegisterNumber()); - removeFromCollectionGroup(itm); - } - } - } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - Integer id = (Integer)itm.getUserValue(); - if (id != null) { - int reg = RegisterUtils.getAStoreReg(this, seen); - - try { - JavaClass cls = itm.getJavaClass(); - if ((cls != null) && cls.implementationOf(iteratorClass)) { - Integer regIt = Integer14.valueOf(reg); - Iterator<Integer> curIt = groupToIterator.values().iterator(); - while (curIt.hasNext()) { - if (curIt.next().equals(regIt)) - curIt.remove(); - } - groupToIterator.put(id, regIt); - } - - Set<Comparable> group = collectionGroups.get(id.intValue()); - if (group != null) { - group.add(Integer14.valueOf(reg)); - } - } catch (ClassNotFoundException cnfe) { - bugReporter.reportMissingClass(cnfe); - } - } - } - } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { - int reg = RegisterUtils.getALoadReg(this, seen); - OpcodeStack.Item itm = new OpcodeStack.Item(new OpcodeStack.Item(), reg); - groupId = findCollectionGroup(itm, false); - } else if (seen == IFEQ) { - if (stack.getStackDepth() > 0) { - OpcodeStack.Item itm = stack.getStackItem(0); - Integer id = (Integer)itm.getUserValue(); - if (id != null) { - int target = getBranchTarget(); - int gotoAddr = target - 3; - int ins = getCode().getCode()[gotoAddr]; - if (ins < 0) - ins = 256 + ins; - if (ins == GOTO) { - Integer reg = groupToIterator.get(id); - if (reg != null) - loops.put(reg, new Loop(getPC(), gotoAddr)); - } - } - } - } - } finally { - stack.sawOpcode(this, seen); - if ((groupId >= 0) && (stack.getStackDepth() > 0)) { - OpcodeStack.Item itm = stack.getStackItem(0); - itm.setUserValue(Integer14.valueOf(groupId)); - } - } - } - - private boolean isCollection(String className) { - try { - JavaClass cls = Repository.lookupClass(className); - return cls.implementationOf(collectionClass); - } catch (ClassNotFoundException cnfe) { - bugReporter.reportMissingClass(cnfe); - return false; - } - } - - private Comparable getGroupElement(OpcodeStack.Item itm) { - Comparable groupElement = null; - - int reg = itm.getRegisterNumber(); - if (reg >= 0) - groupElement = Integer14.valueOf(reg); - else { - XField field = itm.getXField(); - if (field != null) { - int regLoad = itm.getFieldLoadedFromRegister(); - if (regLoad >= 0) - groupElement = field.getName() + ":{" + regLoad + "}"; - } - } - - return groupElement; - } - - private int findCollectionGroup(OpcodeStack.Item itm, boolean addIfNotFound) { - - Integer id = (Integer)itm.getUserValue(); - if (id != null) - return id.intValue(); - - Comparable groupElement = getGroupElement(itm); - if (groupElement != null) { - int numGroups = collectionGroups.size(); - for (int i = 0; i < numGroups; i++) { - Set<? extends Comparable> group = collectionGroups.get(i); - if (group.contains(groupElement)) { - return i; - } - } - - if (addIfNotFound) { - Set<Comparable> group = new HashSet<Comparable>(); - group.add(groupElement); - collectionGroups.add(group); - return collectionGroups.size() - 1; - } - } - - return -1; - } - - private void removeFromCollectionGroup(OpcodeStack.Item itm) { - Comparable groupElement = getGroupElement(itm); - if (groupElement != null) { - for (Set<? extends Comparable> group : collectionGroups) { - if (group.contains(groupElement)) { - group.remove(groupElement); - break; - } - } - } - } - - static class Loop - { - public int loopStart; - public int loopFinish; - - public Loop(int start, int finish) { - loopStart = start; - loopFinish = finish; - } - - public int getLoopFinish() { - return loopFinish; - } - - public int getLoopStart() { - return loopStart; - } - - public boolean hasPC(int pc) { - return (loopStart <= pc) && (pc <= loopFinish); - } - - @Override - public String toString() { - return "Start=" + loopStart + " Finish=" + loopFinish; - } - } -} +/* + * fb-contrib - Auxiliary detectors for Java programs + * Copyright (C) 2005-2007 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 distribu... [truncated message content] |
From: <dbr...@us...> - 2007-11-03 03:27:18
|
Revision: 952 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=952&view=rev Author: dbrosius Date: 2007-11-02 20:27:19 -0700 (Fri, 02 Nov 2007) Log Message: ----------- DLS fixes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-03 02:52:55 UTC (rev 951) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-03 03:27:19 UTC (rev 952) @@ -123,10 +123,7 @@ if (possibleParmRegs.size() > 0) { stack.resetForMethodEntry(this); super.visitCode(obj); - for (Map.Entry<Integer, ParmUsage> entry : possibleParmRegs.entrySet()) { - Integer reg = entry.getKey(); - ParmUsage pu = entry.getValue(); - + for (ParmUsage pu : possibleParmRegs.values()) { if (pu.returned && (pu.alteredPC >= 0)) { bugReporter.reportBug(new BugInstance(this, "CFS_CONFUSING_FUNCTION_SEMANTICS", NORMAL_PRIORITY) .addClass(this) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2007-11-03 02:52:55 UTC (rev 951) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2007-11-03 03:27:19 UTC (rev 952) @@ -89,7 +89,7 @@ bugReporter.reportMissingClass(cnfe); } finally { superclassCode = null; - classContext = null; + this.classContext = null; childPoolGen = null; parentPoolGen = null; } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java 2007-11-03 02:52:55 UTC (rev 951) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/MisleadingOverloadModel.java 2007-11-03 03:27:19 UTC (rev 952) @@ -37,7 +37,7 @@ Method[] methods = cls.getMethods(); for (Method m : methods) { String methodName = m.getName(); - boolean report = false; + boolean report; MethodType newType; if (m.isStatic()) { report = declMethods.get(methodName) == MethodType.INSTANCE; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-11-03 02:52:55 UTC (rev 951) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SuspiciousJDKVersionUse.java 2007-11-03 03:27:19 UTC (rev 952) @@ -125,7 +125,7 @@ @Override public void sawOpcode(int seen) { - String clsName = null; + String clsName; try { if ((seen == INVOKEVIRTUAL) //Interfaces are more difficult, ignore for now Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2007-11-03 02:52:55 UTC (rev 951) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2007-11-03 03:27:19 UTC (rev 952) @@ -103,7 +103,7 @@ } JavaClass cls = findCommonType(returnTypes.keySet()); - BugInstance bug = null; + BugInstance bug; if ((cls != null) && !isInherited) { bug = new BugInstance(this, "URV_CHANGE_RETURN_TYPE", priority) .addClass(this) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-11-03 02:52:55 UTC (rev 951) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseAddAll.java 2007-11-03 03:27:19 UTC (rev 952) @@ -119,7 +119,7 @@ @Override public void sawOpcode(int seen) { Comparable regOrField = null; - Comparable uValue = null; + Comparable uValue; boolean sawAlias = false; boolean sawLoad = false; @@ -243,7 +243,6 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); if (item.getRegisterNumber() == 0) { - uValue = userValues.get(getNameConstantOperand()); sawLoad = true; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-03 03:57:39
|
Revision: 953 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=953&view=rev Author: dbrosius Date: 2007-11-02 20:57:43 -0700 (Fri, 02 Nov 2007) Log Message: ----------- primarily report the return pc, but also include the alter pc Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-03 03:27:19 UTC (rev 952) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-03 03:57:43 UTC (rev 953) @@ -124,10 +124,11 @@ stack.resetForMethodEntry(this); super.visitCode(obj); for (ParmUsage pu : possibleParmRegs.values()) { - if (pu.returned && (pu.alteredPC >= 0)) { + if ((pu.returnPC >= 0) && (pu.alteredPC >= 0)) { bugReporter.reportBug(new BugInstance(this, "CFS_CONFUSING_FUNCTION_SEMANTICS", NORMAL_PRIORITY) .addClass(this) .addMethod(this) + .addSourceLine(this, pu.returnPC) .addSourceLine(this, pu.alteredPC)); } } @@ -150,7 +151,7 @@ int reg = item.getRegisterNumber(); ParmUsage pu = possibleParmRegs.get(Integer14.valueOf(reg)); if (pu != null) - pu.setReturned(); + pu.setReturnPC(getPC()); } } else if (seen == PUTFIELD) { if (stack.getStackDepth() > 1) { @@ -185,11 +186,11 @@ static class ParmUsage { - boolean returned = false; + int returnPC = -1; int alteredPC = -1; - public void setReturned() { - returned = true; + public void setReturnPC(int pc) { + returnPC = pc; } public void setAlteredPC(int pc) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2007-11-03 03:27:19 UTC (rev 952) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UnrelatedReturnValues.java 2007-11-03 03:57:43 UTC (rev 953) @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Set; +import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; @@ -179,7 +180,7 @@ if (populate) { possibleCommonTypes.addAll(Arrays.asList(infs)); possibleCommonTypes.addAll(Arrays.asList(supers)); - possibleCommonTypes.remove("java/lang/Object"); + possibleCommonTypes.remove(Repository.lookupClass("java/lang/Object")); populate = false; } else { Set<JavaClass> retain = new HashSet<JavaClass>(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-11-07 07:02:37
|
Revision: 956 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=956&view=rev Author: dbrosius Date: 2007-11-06 23:02:42 -0800 (Tue, 06 Nov 2007) Log Message: ----------- get rid of java5 dependencies Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-07 07:01:26 UTC (rev 955) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConfusingFunctionSemantics.java 2007-11-07 07:02:42 UTC (rev 956) @@ -163,7 +163,7 @@ } } else if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { int reg = RegisterUtils.getAStoreReg(this, seen); - possibleParmRegs.remove(Integer.valueOf(reg)); + possibleParmRegs.remove(Integer14.valueOf(reg)); } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) { String calledSig = getSigConstantOperand(); String calledRet = Type.getReturnType(calledSig).getSignature(); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-11-07 07:01:26 UTC (rev 955) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ExceptionSoftening.java 2007-11-07 07:02:42 UTC (rev 956) @@ -39,6 +39,7 @@ import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.classfile.Method; +import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.SignatureUtils; import edu.umd.cs.findbugs.BugInstance; @@ -127,7 +128,7 @@ try { stack.mergeJumps(this); int pc = getPC(); - CodeException ex = catchHandlerPCs.get(Integer.valueOf(pc)); + CodeException ex = catchHandlerPCs.get(Integer14.valueOf(pc)); if (ex != null) { int endPC; if ((seen == GOTO) || (seen == GOTO_W)) @@ -235,7 +236,7 @@ LinkedHashMap<Integer, CodeException> handlers = new LinkedHashMap<Integer, CodeException>(); for (CodeException ex : filteredEx) { - handlers.put(Integer.valueOf(ex.getEndPC()), ex); + handlers.put(Integer14.valueOf(ex.getEndPC()), ex); } return handlers; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-06-07 02:42:14
|
Revision: 1038 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1038&view=rev Author: dbrosius Date: 2008-06-06 19:42:22 -0700 (Fri, 06 Jun 2008) Log Message: ----------- look for LDC_W in addition to LDC Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java 2008-06-07 02:35:40 UTC (rev 1037) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/AbstractClassEmptyMethods.java 2008-06-07 02:42:22 UTC (rev 1038) @@ -133,7 +133,7 @@ break; case SEEN_DUP: - if ((seen == LDC) && (getConstantRefOperand() instanceof ConstantString)) + if (((seen == LDC) || (seen == LDC_W)) && (getConstantRefOperand() instanceof ConstantString)) state = SEEN_LDC; else state = SEEN_DONE; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2008-06-07 02:35:40 UTC (rev 1037) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2008-06-07 02:42:22 UTC (rev 1038) @@ -100,7 +100,7 @@ state = SEEN_CONSTANT_0; else if ((seen >= ICONST_1) && (seen <= ICONST_5)) state = SEEN_CONSTANT; - else if (seen == LDC) { + else if ((seen == LDC) || (seen == LDC_W)) { Constant c = getConstantRefOperand(); if (c instanceof ConstantInteger) state = SEEN_CONSTANT; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2008-06-07 02:35:40 UTC (rev 1037) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2008-06-07 02:42:22 UTC (rev 1038) @@ -162,7 +162,7 @@ OpcodeStack.Item itm = stack.getStackItem(i); itm.setUserValue(Boolean.FALSE); } - } else if (seen == LDC) { + } else if ((seen == LDC) || (seen == LDC_W)) { Constant c = getConstantRefOperand(); if (c instanceof ConstantString) { String s = ((ConstantString) c).getBytes(getConstantPool()); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-06-07 02:35:40 UTC (rev 1037) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2008-06-07 02:42:22 UTC (rev 1038) @@ -189,8 +189,9 @@ byte[] bytes = getCode().getCode(); if (lastPCs[1] != -1) { + int loadIns = getbyte(bytes, lastPCs[2]); if ((getbyte(bytes, lastPCs[3]) == INVOKEVIRTUAL) - && (getbyte(bytes, lastPCs[2]) == LDC) + && ((loadIns == LDC) || (loadIns == LDC_W)) && (getbyte(bytes, lastPCs[1]) == INVOKEVIRTUAL)) { ConstantPool pool = getConstantPool(); int toStringIndex = getshort(bytes, lastPCs[1]+1); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java 2008-06-07 02:35:40 UTC (rev 1037) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SloppyClassReflection.java 2008-06-07 02:42:22 UTC (rev 1038) @@ -142,7 +142,7 @@ break; case SEEN_NOTHING: - if (seen == LDC) { + if ((seen == LDC) || (seen == LDC_W)) { Constant c = getConstantRefOperand(); if (c instanceof ConstantString) { clsName = ((ConstantString) c).getBytes(getConstantPool()); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java 2008-06-07 02:35:40 UTC (rev 1037) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticArrayCreatedInMethod.java 2008-06-07 02:42:22 UTC (rev 1038) @@ -126,7 +126,7 @@ break; case SEEN_INDEX: - if (seen == LDC) + if ((seen == LDC) || (seen == LDC_W)) state = SEEN_LDC; else state = SEEN_NOTHING; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2008-06-07 02:35:40 UTC (rev 1037) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseCharacterParameterizedMethod.java 2008-06-07 02:42:22 UTC (rev 1038) @@ -95,7 +95,7 @@ private boolean prescreen(Method obj) { BitSet bytecodeSet = getClassContext().getBytecodeSet(obj); - return (bytecodeSet != null) && (bytecodeSet.get(Constants.LDC)); + return (bytecodeSet != null) && ((bytecodeSet.get(Constants.LDC) || (bytecodeSet.get(Constants.LDC_W)))); } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2008-06-07 04:48:36
|
Revision: 1039 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1039&view=rev Author: dbrosius Date: 2008-06-06 21:48:44 -0700 (Fri, 06 Jun 2008) Log Message: ----------- handle GOTO_W along with GOTO Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FloatingPointLoops.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -145,7 +145,7 @@ unsafeCallOccurred = false; } else if (seen == INVOKESTATIC) unsafeCallOccurred = (getDottedClassConstantOperand().equals(this.getClassContext().getJavaClass().getClassName())); - else if ((seen >= IFEQ) && (seen <= GOTO)) + else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { Integer from = Integer14.valueOf(getPC()); Integer to = Integer14.valueOf(getBranchTarget()); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConstantListIndex.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -151,7 +151,7 @@ break; } - if ((seen >= IFEQ) && (seen <= GOTO)) { + if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) { int branchTarget = this.getBranchTarget(); Iterator<Integer> it = iConst0Looped.iterator(); while (it.hasNext()) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -270,7 +270,7 @@ int ins = getCode().getCode()[gotoAddr]; if (ins < 0) ins = 256 + ins; - if (ins == GOTO) { + if ((ins == GOTO) || (ins == GOTO_W)) { Integer reg = groupToIterator.get(id); if (reg != null) loops.put(reg, new Loop(getPC(), gotoAddr)); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FloatingPointLoops.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FloatingPointLoops.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/FloatingPointLoops.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -153,7 +153,7 @@ return false; case SEEN_STORE: - if ((seen == GOTO) && (getBranchTarget() == loopPC)) { + if (((seen == GOTO) || (seen == GOTO_W)) && (getBranchTarget() == loopPC)) { bugReporter.reportBug(new BugInstance(FloatingPointLoops.this, "FPL_FLOATING_POINT_LOOPS", NORMAL_PRIORITY) .addClass(FloatingPointLoops.this) .addMethod(FloatingPointLoops.this) Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/InefficientStringBuffering.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -156,7 +156,7 @@ } } - } else if (seen == GOTO) { + } else if ((seen == GOTO) || (seen == GOTO_W)) { int depth = stack.getStackDepth(); for (int i = 0; i < depth; i++) { OpcodeStack.Item itm = stack.getStackItem(i); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ListIndexedIterating.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -86,7 +86,7 @@ } /** - * looks for methods that contain a GOTO or GOTO_W opcodes + * looks for methods that contain a IINC and GOTO or GOTO_W opcodes * * @param method the context object of the current method * @return if the class uses synchronization Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/NeedlessAutoboxing.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -139,7 +139,7 @@ if ("TRUE".equals(fldName) || "FALSE".equals(fldName)) state = SEEN_GETSTATIC; } - } else if (seen == GOTO) { + } else if ((seen == GOTO) || (seen == GOTO_W)) { state = SEEN_GOTO; } break; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java 2008-06-07 02:42:22 UTC (rev 1038) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/StaticMethodInstanceInvocation.java 2008-06-07 04:48:44 UTC (rev 1039) @@ -133,7 +133,8 @@ || ((seen >= ASTORE_0) && (seen <= ASTORE_3)) || (seen == PUTFIELD) || (seen == ATHROW) - || (seen == GOTO)) { + || (seen == GOTO) + || (seen == GOTO_W)) { popStack.clear(); } else if ((seen == INVOKESPECIAL) || (seen == INVOKEINTERFACE) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |