[Fb-contrib-commit] SF.net SVN: fb-contrib:[1782] trunk/fb-contrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2015-08-22 22:14:21
|
Revision: 1782 http://sourceforge.net/p/fb-contrib/code/1782 Author: dbrosius Date: 2015-08-22 22:14:18 +0000 (Sat, 22 Aug 2015) Log Message: ----------- sync from github Modified Paths: -------------- trunk/fb-contrib/.classpath trunk/fb-contrib/build.xml trunk/fb-contrib/etc/findbugs.xml trunk/fb-contrib/htdocs/index.shtml trunk/fb-contrib/htdocs/repository.html trunk/fb-contrib/samples/DWI_Sample.java trunk/fb-contrib/samples/PRMC_Sample.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConflictingTimeUnits.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/DeletingWhileIterating.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java Modified: trunk/fb-contrib/.classpath =================================================================== --- trunk/fb-contrib/.classpath 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/.classpath 2015-08-22 22:14:18 UTC (rev 1782) @@ -11,7 +11,7 @@ <classpathentry kind="lib" path="lib/javax.servlet.jsp-api-2.3.1.jar"/> <classpathentry kind="lib" path="lib/commons-lang3-3.3.jar"/> <classpathentry kind="lib" path="lib/slf4j-api-1.7.7.jar"/> - <classpathentry kind="lib" path="lib/guava-17.0.jar"/> + <classpathentry kind="lib" path="lib/guava-17.0.jar" sourcepath="lib/sources/guava-17.0-sources.jar"/> <classpathentry kind="lib" path="lib/httpclient-cache-4.3.4.jar"/> <classpathentry kind="lib" path="lib/httpcore-4.3.2.jar"/> <classpathentry kind="lib" path="lib/httpclient-4.3.4.jar"/> Modified: trunk/fb-contrib/build.xml =================================================================== --- trunk/fb-contrib/build.xml 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/build.xml 2015-08-22 22:14:18 UTC (rev 1782) @@ -126,7 +126,7 @@ </target> <target name="jar" depends="compile" xmlns:vcs="antlib:com.mebigfatguy.vcsversion" description="produces the fb-contrib jar file"> - <vcs:vcsversion vcs="git" revisionProperty="_rev_" dateProperty="_date_" branchProperty="_branch_"/> + <vcs:vcsversion vcs="git" revisionProperty="_rev_" dateProperty="_date_" branchProperty="_branch_" urlProperty="_url_"/> <jar destfile="${target.dir}/fb-contrib-${fb-contrib.version}.jar"> <fileset dir="etc"> <include name="findbugs.xml" /> @@ -144,7 +144,10 @@ <manifest> <attribute name="fb-contrib-version" value="${fb-contrib.version}" /> <attribute name="Main-Class" value="com.mebigfatguy.fbcontrib.FBContrib" /> - <attribute name="git-revision" value="${_branch_} ${_rev_} ${_date_}" /> + <attribute name="git-url" value="${_url_}" /> + <attribute name="git-branch" value="${_branch_}" /> + <attribute name="git-revision" value="${_rev_}" /> + <attribute name="git-date" value="${_date_}" /> <attribute name="Eclipse-RegisterBuddy" value="edu.umd.cs.findbugs.plugin.eclipse" /> <attribute name="Bundle-ManifestVersion" value="2" /> <attribute name="Bundle-Name" value="fb-contrib plugin" /> Modified: trunk/fb-contrib/etc/findbugs.xml =================================================================== --- trunk/fb-contrib/etc/findbugs.xml 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/etc/findbugs.xml 2015-08-22 22:14:18 UTC (rev 1782) @@ -286,7 +286,7 @@ <Detector class="com.mebigfatguy.fbcontrib.detect.ConflatingResourcesAndFiles" speed="fast" reports="CRF_CONFLATING_RESOURCES_AND_FILES" /> <!-- COMMENT OUT FOR POINT RELEASE --> - + <Detector class="com.mebigfatguy.fbcontrib.detect.OverlyPermissiveMethod" speed="fast" reports="OPM_OVERLY_PERMISSIVE_METHOD" /> <Detector class="com.mebigfatguy.fbcontrib.detect.ClassImpersonatingString" speed="fast" reports="CIS_STRING_PARSING_A_FIELD,CIS_TOSTRING_STORED_IN_FIELD" /> Modified: trunk/fb-contrib/htdocs/index.shtml =================================================================== --- trunk/fb-contrib/htdocs/index.shtml 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/htdocs/index.shtml 2015-08-22 22:14:18 UTC (rev 1782) @@ -68,7 +68,7 @@ </li> </ul> </p> - <p style="font-weight: bold;">The latest version of fb-contrib is 6.2.1 available for download + <p style="font-weight: bold;">The latest version of fb-contrib is 6.2.2 available for download <a href="http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22fb-contrib%22">here</a>.</p> <p style="font-weight: bold;">This version requires FindBugs 3.0.1 or better</p> <p style="font-weight: bold;">Please note that active development for this project is now done on Modified: trunk/fb-contrib/htdocs/repository.html =================================================================== --- trunk/fb-contrib/htdocs/repository.html 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/htdocs/repository.html 2015-08-22 22:14:18 UTC (rev 1782) @@ -22,7 +22,7 @@ <table style="margin-left: 40px; background-color: #A0A0FF; padding: 20px; border-width: 1px; border-style: outset; border-color: #000000;"> <tr><td><b>GroupId:</b></td><td>com.mebigfatguy.fb-contrib</td></tr> <tr><td><b>ArtifactId:</b></td><td>fb-contrib</td></tr> - <tr><td><b>Version:</b></td><td>6.2.1</td></tr> + <tr><td><b>Version:</b></td><td>6.2.2</td></tr> </table> </div> Modified: trunk/fb-contrib/samples/DWI_Sample.java =================================================================== --- trunk/fb-contrib/samples/DWI_Sample.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/samples/DWI_Sample.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -13,15 +13,17 @@ Iterator<Integer> it = bagOInts.iterator(); while (it.hasNext()) { Integer i = it.next(); - if ((i.intValue() & 0x01) == 1) + if ((i.intValue() & 0x01) == 1) { bagOInts.remove(i); + } } } public void addIf(Set<String> s, Collection<String> c) { for (String ss : s) { - if (ss.equals("addem")) + if (ss.equals("addem")) { s.addAll(c); + } } } @@ -52,6 +54,26 @@ } } + public void fpRemoveWithReturn(Set<String> ss) { + for (String s : ss) { + if (s.equals("foo")) { + ss.remove("foo"); + return; + } + } + } + + public boolean fpRemoveWithReturn2(Set<String> ss) { + for (String s : ss) { + if (s.equals("foo")) { + ss.remove("foo"); + return true; + } + } + + return false; + } + public void fpNonCMECollection() { for (String s : cow) { if (s.isEmpty()) { Modified: trunk/fb-contrib/samples/PRMC_Sample.java =================================================================== --- trunk/fb-contrib/samples/PRMC_Sample.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/samples/PRMC_Sample.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -6,6 +6,8 @@ import java.util.List; import java.util.Set; +import com.google.common.collect.Lists; + import edu.emory.mathcs.backport.java.util.Collections; @SuppressWarnings("all") @@ -30,8 +32,9 @@ @Override public boolean equals(Object o) { PRMC_Sample rmc = (PRMC_Sample) o; - if (data.equals("INF") || rmc.data.equals("INF")) + if (data.equals("INF") || rmc.data.equals("INF")) { return false; + } return data.equals(rmc.data); } @@ -113,6 +116,11 @@ SAMPLE2.setValue(5); } + public void fpWithGuava() { + List<String> l = Lists.newArrayList(); + List<String> ll = Lists.newArrayList(); + } + public void fpAsListLiterals() { System.out.println(Arrays.asList("foo")); System.out.println(Arrays.asList("bar")); @@ -124,6 +132,7 @@ class Chain { public Chain chainedField; + @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("--"); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -100,7 +100,7 @@ /** * constructs a BAS detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ @@ -111,7 +111,7 @@ /** * implements the visitor to create and the clear the register to location * map - * + * * @param classContext * the context object of the currently parsed class */ @@ -137,7 +137,7 @@ /** * implements the visitor to reset the register to location map - * + * * @param obj * the context object of the currently parsed code block */ @@ -186,7 +186,7 @@ /** * 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 */ @@ -378,8 +378,9 @@ } else if (seen == MONITOREXIT) { if (monitorSyncPCs.size() > 0) { ScopeBlock sb = findSynchronizedScopeBlock(rootScopeBlock, monitorSyncPCs.get(0).intValue()); - if (sb != null) + if (sb != null) { sb.setFinish(pc); + } monitorSyncPCs.remove(monitorSyncPCs.size() - 1); } } @@ -402,7 +403,7 @@ /** * returns either a register number of a field reference of the object that * a method is being called on, or null, if it can't be determined. - * + * * @return either an Integer for a register, or a String for the field name, * or null */ @@ -437,7 +438,7 @@ /** * 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 @@ -463,12 +464,12 @@ /** * 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) { @@ -493,7 +494,7 @@ /** * finds the scope block that is the active synchronized block - * + * * @return the scope block */ private ScopeBlock findSynchronizedScopeBlock(ScopeBlock sb, int monitorEnterPC) { @@ -516,19 +517,20 @@ /** * returns the catch handler for a given try block - * + * * @param pc * the current instruction * @return the pc of the handler for this pc if it's the start of a try * block, or -1 - * + * */ private int findCatchHandlerFor(int pc) { CodeException[] exceptions = getMethod().getCode().getExceptionTable(); if (exceptions != null) { for (CodeException ex : exceptions) { - if (ex.getStartPC() == pc) + if (ex.getStartPC() == pc) { return ex.getHandlerPC(); + } } } @@ -554,7 +556,7 @@ /** * construts a new scope block - * + * * @param start * the beginning of the block * @param finish @@ -577,7 +579,7 @@ /** * returns a string representation of the scope block - * + * * @returns a string representation */ @Override @@ -587,7 +589,7 @@ /** * returns the scope blocks parent - * + * * @return the parent of this scope block */ public ScopeBlock getParent() { @@ -596,7 +598,7 @@ /** * returns the children of this scope block - * + * * @return the scope blocks children */ public List<ScopeBlock> getChildren() { @@ -605,7 +607,7 @@ /** * returns the start of the block - * + * * @return the start of the block */ public int getStart() { @@ -614,7 +616,7 @@ /** * returns the end of the block - * + * * @return the end of the block */ public int getFinish() { @@ -623,7 +625,7 @@ /** * sets the start pc of the block - * + * * @param start * the start pc */ @@ -633,7 +635,7 @@ /** * sets the finish pc of the block - * + * * @param finish * the finish pc */ @@ -654,7 +656,7 @@ /** * returns whether this scope block is a loop - * + * * @returns whether this block is a loop */ public boolean isLoop() { @@ -670,7 +672,7 @@ /** * returns whether this block was caused from a goto - * + * * @returns whether this block was caused by a goto */ public boolean isGoto() { @@ -686,7 +688,7 @@ /** * returns whether this block was caused from a synchronized block - * + * * @returns whether this block was caused by a synchronized block */ public boolean isSync() { @@ -702,7 +704,7 @@ /** * returns whether this block was caused from a try block - * + * * @returns whether this block was caused by a try block */ public boolean isTry() { @@ -718,7 +720,7 @@ /** * returns whether this block was caused from a case block - * + * * @returns whether this block was caused by a case block */ public boolean isCase() { @@ -727,7 +729,7 @@ /** * adds the register as a store in this scope block - * + * * @param reg * the register that was stored * @param pc @@ -748,7 +750,7 @@ /** * removes stores to registers that where retrieved from method calls on * assocObject - * + * * @param assocObject * the object that a method call was just performed on */ @@ -768,7 +770,7 @@ /** * adds the register as a load in this scope block - * + * * @param reg * the register that was loaded * @param pc @@ -785,7 +787,7 @@ /** * adds a scope block to this subtree by finding the correct place in * the hierarchy to store it - * + * * @param newChild * the scope block to add to the tree */ @@ -795,8 +797,9 @@ if (children != null) { for (ScopeBlock child : children) { if ((newChild.startLocation > child.startLocation) && (newChild.startLocation < child.finishLocation)) { - if (newChild.finishLocation > child.finishLocation) + if (newChild.finishLocation > child.finishLocation) { newChild.finishLocation = child.finishLocation; + } child.addChild(newChild); return; } @@ -818,7 +821,7 @@ /** * removes a child from this node - * + * * @param child * the child to remove */ @@ -887,10 +890,10 @@ /** * 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) { @@ -945,7 +948,7 @@ return true; } - String key = clsName + "." + getNameConstantOperand() + getSigConstantOperand(); + String key = clsName + '.' + getNameConstantOperand() + getSigConstantOperand(); if (dangerousAssignmentMethodSources.contains(key)) { return true; } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConflictingTimeUnits.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConflictingTimeUnits.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/ConflictingTimeUnits.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -1,17 +1,17 @@ /* * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2015 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 @@ -91,7 +91,7 @@ /** * constructs a CTU detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ @@ -101,7 +101,7 @@ /** * overrides the visitor to reset the stack - * + * * @param classContext * the context object of the currently parsed class */ @@ -117,7 +117,7 @@ /** * overrides the visitor to resets the stack for this method. - * + * * @param obj * the context object for the currently parsed code block */ @@ -141,7 +141,7 @@ case INVOKEVIRTUAL: case INVOKEINTERFACE: case INVOKESTATIC: - String methodCall = getClassConstantOperand() + "." + getNameConstantOperand() + getSigConstantOperand(); + String methodCall = getClassConstantOperand() + '.' + getNameConstantOperand() + getSigConstantOperand(); unit = TIME_UNIT_GENERATING_METHODS.get(methodCall); if (unit == Units.CALLER) { int offset = Type.getArgumentTypes(getSigConstantOperand()).length; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CopiedOverriddenMethod.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -98,7 +98,7 @@ String methodName = m.getName(); if ((m.isPublic() || m.isProtected()) && (!m.isAbstract() && !m.isSynthetic() && (!Values.CONSTRUCTOR.equals(methodName) && !Values.STATIC_INITIALIZER.equals(methodName)))) { - String methodInfo = methodName + ":" + m.getSignature(); + String methodInfo = methodName + ':' + m.getSignature(); superclassCode.put(methodInfo, new CodeInfo(m.getCode(), m.getAccessFlags())); } } @@ -122,7 +122,7 @@ */ @Override public void visitMethod(Method obj) { - curMethodInfo = obj.getName() + ":" + obj.getSignature(); + curMethodInfo = obj.getName() + ':' + obj.getSignature(); } /** @@ -196,9 +196,11 @@ } } else { int expectedInstruction = getExpectedReturnInstruction(getMethod().getReturnType()); - if (seen == expectedInstruction) { + if ((seen == expectedInstruction) && (getNextPC() == getCode().getCode().length)) { bugReporter.reportBug( new BugInstance(this, BugType.COM_PARENT_DELEGATED_CALL.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this)); + } else { + ignore = true; } } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CustomBuiltXML.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -68,7 +68,7 @@ /** * constructs a CBX detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ @@ -138,7 +138,7 @@ if ("java/lang/StringBuffer".equals(clsName) || "java/lang/StringBuilder".equals(clsName)) { String methodName = getNameConstantOperand(); String methodSig = getSigConstantOperand(); - if (Values.CONSTRUCTOR.equals(methodName) && ("(Ljava/lang/String;)L" + clsName + ";").equals(methodSig)) { + if (Values.CONSTRUCTOR.equals(methodName) && ("(Ljava/lang/String;)L" + clsName + ';').equals(methodSig)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); strCon = (String) itm.getConstant(); @@ -150,7 +150,7 @@ if ("java/lang/StringBuffer".equals(clsName) || "java/lang/StringBuilder".equals(clsName)) { String methodName = getNameConstantOperand(); String methodSig = getSigConstantOperand(); - if ("append".equals(methodName) && ("(Ljava/lang/String;)L" + clsName + ";").equals(methodSig)) { + if ("append".equals(methodName) && ("(Ljava/lang/String;)L" + clsName + ';').equals(methodSig)) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); strCon = (String) itm.getConstant(); @@ -161,17 +161,20 @@ if (strCon != null) { strCon = strCon.trim(); - if (strCon.length() == 0) + if (strCon.length() == 0) { return; + } for (Map.Entry<Pattern, Boolean> entry : xmlPatterns.entrySet()) { Matcher m = entry.getKey().matcher(strCon); if (m.matches()) { xmlItemCount++; - if (entry.getValue().booleanValue()) + if (entry.getValue().booleanValue()) { xmlConfidentCount++; - if ((firstPC < 0) && (xmlConfidentCount > 0)) + } + if ((firstPC < 0) && (xmlConfidentCount > 0)) { firstPC = getPC(); + } break; } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/CyclomaticComplexity.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -1,17 +1,17 @@ /* * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2015 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 @@ -51,20 +51,21 @@ /** * constructs a CC detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ public CyclomaticComplexity(final BugReporter bugReporter) { this.bugReporter = bugReporter; Integer limit = Integer.getInteger(LIMIT_PROPERTY); - if (limit != null) + if (limit != null) { reportLimit = limit.intValue(); + } } /** * overrides the visitor to store the class context - * + * * @param context * the context object for the currently parsed class */ @@ -88,7 +89,7 @@ /** * overrides the visitor to navigate the basic block list to count branches - * + * * @param obj * the method of the currently parsed method */ @@ -96,19 +97,22 @@ public void visitMethod(final Method obj) { try { - if ((obj.getAccessFlags() & Constants.ACC_SYNTHETIC) != 0) + if ((obj.getAccessFlags() & Constants.ACC_SYNTHETIC) != 0) { return; + } Code code = obj.getCode(); - if (code == null) + if (code == null) { return; + } // There really is no valid relationship between reportLimit and // code // length, but it is good enough. If the method is small, don't // bother - if (code.getCode().length < (2 * reportLimit)) + if (code.getCode().length < (2 * reportLimit)) { return; + } BitSet exceptionNodeTargets = new BitSet(); @@ -144,7 +148,7 @@ bugReporter.reportBug(bug); } } catch (CFGBuilderException cbe) { - bugReporter.logError("Failure examining basic blocks for method " + classContext.getJavaClass().getClassName() + "." + obj.getName() + bugReporter.logError("Failure examining basic blocks for method " + classContext.getJavaClass().getClassName() + '.' + obj.getName() + " in Cyclomatic Complexity detector", cbe); } } Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -111,7 +111,7 @@ /** * constructs a DWI detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ @@ -128,8 +128,9 @@ */ @Override public void visitClassContext(ClassContext classContext) { - if ((collectionClass == null) || (iteratorClass == null)) + if ((collectionClass == null) || (iteratorClass == null)) { return; + } try { stack = new OpcodeStack(); @@ -207,9 +208,11 @@ if (loop != null) { int pc = getPC(); if (loop.hasPC(pc)) { - boolean breakFollows = breakFollows(loop, !"V".equals(Type.getReturnType(signature).getSignature())); + boolean needPop = !"V".equals(Type.getReturnType(signature).getSignature()); + boolean breakFollows = breakFollows(loop, needPop); + boolean returnFollows = breakFollows ? false : returnFollows(loop, needPop); - if (!breakFollows) { + if (!breakFollows && !returnFollows) { bugReporter.reportBug(new BugInstance(this, BugType.DWI_DELETING_WHILE_ITERATING.name(), NORMAL_PRIORITY) .addClass(this).addMethod(this).addSourceLine(this)); } @@ -247,8 +250,9 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); Integer id = (Integer) itm.getUserValue(); - if (id != null) + if (id != null) { groupId = id.intValue(); + } } } } else if ((seen == PUTFIELD) || (seen == PUTSTATIC)) { @@ -277,8 +281,9 @@ Integer regIt = Integer.valueOf(reg); Iterator<Integer> curIt = groupToIterator.values().iterator(); while (curIt.hasNext()) { - if (curIt.next().equals(regIt)) + if (curIt.next().equals(regIt)) { curIt.remove(); + } } groupToIterator.put(id, regIt); } @@ -320,12 +325,14 @@ int target = getBranchTarget(); int gotoAddr = target - 3; int ins = getCode().getCode()[gotoAddr]; - if (ins < 0) + if (ins < 0) { ins = 256 + ins; + } if ((ins == GOTO) || (ins == GOTO_W)) { Integer reg = groupToIterator.get(id); - if (reg != null) + if (reg != null) { loops.put(reg, new Loop(getPC(), gotoAddr)); + } } } } @@ -358,13 +365,46 @@ int gotoOp = CodeByteUtils.getbyte(code, nextPC); if ((gotoOp == Constants.GOTO) || (gotoOp == Constants.GOTO_W)) { int target = nextPC + CodeByteUtils.getshort(code, nextPC + 1); - if (target > loop.getLoopFinish()) + if (target > loop.getLoopFinish()) { return true; + } } return false; } + /* + * This attempts to see if there is some form of a return statement + * following the collection modifying statement in the loop. It is a bad + * cheat, because, we may allow a POP, or an ALOAD/ILOAD etc before the + * return. this is sloppy tho as it might be a multibyte instruction. It + * also might be a complex piece of code to load the return, or the method + * may not allow returns. But hopefully it's better than it was. + */ + private boolean returnFollows(Loop loop, boolean couldSeePop) { + + byte[] code = getCode().getCode(); + int nextPC = getNextPC(); + + int nextOp = CodeByteUtils.getbyte(code, nextPC++); + + if ((nextOp >= Constants.IRETURN) && (nextOp <= Constants.RETURN)) { + return true; + } else if ((couldSeePop) && (nextOp == Constants.POP)) { + nextOp = CodeByteUtils.getbyte(code, nextPC++); + if ((nextOp >= Constants.IRETURN) && (nextOp <= Constants.RETURN)) { + return true; + } + } + + nextOp = CodeByteUtils.getbyte(code, nextPC++); + if ((nextOp >= Constants.IRETURN) && (nextOp <= Constants.RETURN)) { + return true; + } + + return false; + } + private boolean isCollection(String className) { try { JavaClass cls = Repository.lookupClass(className); @@ -379,14 +419,15 @@ Comparable<?> groupElement = null; int reg = itm.getRegisterNumber(); - if (reg >= 0) + if (reg >= 0) { groupElement = Integer.valueOf(reg); - else { + } else { XField field = itm.getXField(); if (field != null) { int regLoad = itm.getFieldLoadedFromRegister(); - if (regLoad >= 0) - groupElement = field.getName() + ":{" + regLoad + "}"; + if (regLoad >= 0) { + groupElement = field.getName() + ":{" + regLoad + '}'; + } } } @@ -396,8 +437,9 @@ private int findCollectionGroup(OpcodeStack.Item itm, boolean addIfNotFound) { Integer id = (Integer) itm.getUserValue(); - if (id != null) + if (id != null) { return id.intValue(); + } Comparable<?> groupElement = getGroupElement(itm); if (groupElement != null) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/IncorrectInternalClassUse.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -44,11 +44,19 @@ static { internalPackages.add("com/sun/"); + internalPackages.add("org/apache/commons/digester/annotations/internal"); internalPackages.add("org/apache/xerces/"); internalPackages.add("org/apache/xalan/"); - externalPackages.add("com/sun/jersey"); - externalPackages.add("com/sun/mail"); - externalPackages.add("com/sun/xml/xsom"); + internalPackages.add("org/mockito/internal/"); + internalPackages.add("org/springframework/asm/"); + internalPackages.add("org/springframework/cglib/"); + internalPackages.add("org/springframework/objenesis/"); + internalPackages.add("com/sun/org/apache/xerces/"); + internalPackages.add("com/sun/org/apache/xalan/"); + internalPackages.add("com/sun/xml/internal/"); + externalPackages.add("com/sun/jersey/"); + externalPackages.add("com/sun/mail/"); + externalPackages.add("com/sun/xml/"); externalPackages.add("org/apache/xerces/xni/"); externalPackages.add("org/apache/xerces/xs/"); externalPackages.add("org/apache/xalan/extensions"); Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossiblyRedundantMethodCalls.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -125,6 +125,11 @@ riskyClassNames.add("java/io/DataInputStream"); riskyClassNames.add("java/io/ObjectInputStream"); riskyClassNames.add("java/util/Calendar"); + riskyClassNames.add("com/google/common/collect/Lists"); + riskyClassNames.add("com/google/common/collect/Sets"); + riskyClassNames.add("com/google/common/collect/Maps"); + riskyClassNames.add("com/google/common/collect/Queues"); + String userNameProp = System.getProperty(PRMC_RISKY_CLASS_USER_KEY); if (userNameProp != null) { String[] userNames = userNameProp.split("\\s*,\\s*"); @@ -143,7 +148,7 @@ /** * constructs a PRMC detector given the reporter to report bugs on - * + * * @param bugReporter * the sync of bug reports */ @@ -234,8 +239,9 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); fieldSource = (String) item.getUserValue(); - if (fieldSource == null) + if (fieldSource == null) { fieldSource = ""; + } } fieldMethodCalls.remove(fieldSource + ":" + getNameConstantOperand()); } else if (seen == GETFIELD) { @@ -288,8 +294,9 @@ mc = localMethodCalls.get(Integer.valueOf(reg)); } else if (field != null) { String fieldSource = (String) obj.getUserValue(); - if (fieldSource == null) + if (fieldSource == null) { fieldSource = ""; + } mc = fieldMethodCalls.get(fieldSource + ":" + field.getName()); } else { return; @@ -326,8 +333,9 @@ if (stack.getStackDepth() > 0) { OpcodeStack.Item item = stack.getStackItem(0); fieldSource = (String) item.getUserValue(); - if (fieldSource == null) + if (fieldSource == null) { fieldSource = ""; + } } fieldMethodCalls.remove(fieldSource + ":" + field.getName()); @@ -343,8 +351,9 @@ } else if (field != null) { OpcodeStack.Item obj = stack.getStackItem(parmCount); String fieldSource = (String) obj.getUserValue(); - if (fieldSource == null) + if (fieldSource == null) { fieldSource = ""; + } fieldMethodCalls.put(fieldSource + ":" + field.getName(), new MethodCall(methodName, signature, parmConstants, pc, ln)); } } @@ -364,7 +373,7 @@ /** * returns the bug priority based on metrics about the method - * + * * @param methodName * TODO * @param mi @@ -372,17 +381,21 @@ * @return the bug priority */ private static int getBugPriority(String methodName, MethodInfo mi) { - if ((mi.getNumBytes() >= highByteCountLimit) || (mi.getNumMethodCalls() >= highMethodCallLimit)) + if ((mi.getNumBytes() >= highByteCountLimit) || (mi.getNumMethodCalls() >= highMethodCallLimit)) { return HIGH_PRIORITY; + } - if (Values.STATIC_INITIALIZER.equals(methodName)) + if (Values.STATIC_INITIALIZER.equals(methodName)) { return LOW_PRIORITY; + } - if ((mi.getNumBytes() >= normalByteCountLimit) || (mi.getNumMethodCalls() >= normalMethodCallLimit)) + if ((mi.getNumBytes() >= normalByteCountLimit) || (mi.getNumMethodCalls() >= normalMethodCallLimit)) { return NORMAL_PRIORITY; + } - if ((mi.getNumBytes() == 0) || (mi.getNumMethodCalls() == 0)) + if ((mi.getNumBytes() == 0) || (mi.getNumMethodCalls() == 0)) { return LOW_PRIORITY; + } return EXP_PRIORITY; } @@ -414,22 +427,25 @@ /** * returns the source line number for the pc, or just the pc if the line * number table doesn't exist - * + * * @param pc * current pc * @return the line number */ private int getLineNumber(int pc) { LineNumberTable lnt = getMethod().getLineNumberTable(); - if (lnt == null) + if (lnt == null) { return pc; + } LineNumber[] lns = lnt.getLineNumberTable(); - if (lns == null) + if (lns == null) { return pc; + } - if (pc > lns[lns.length - 1].getStartPC()) + if (pc > lns[lns.length - 1].getStartPC()) { return lns[lns.length - 1].getLineNumber(); + } int lo = 0; int hi = lns.length - 2; Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/SillynessPotPourri.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -400,7 +400,7 @@ if (cmr instanceof ConstantMethodref) { ConstantMethodref toStringMR = (ConstantMethodref) cmr; String toStringCls = toStringMR.getClass(pool); - if (toStringCls.startsWith("java.lang.&&StringBu")) { + if (toStringCls.startsWith("java.lang.StringBu")) { int consIndex = CodeByteUtils.getbyte(bytes, lastPCs[2] + 1); Constant c = pool.getConstant(consIndex); if (c instanceof ConstantString) { Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2015-08-16 23:23:57 UTC (rev 1781) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/UseVarArgs.java 2015-08-22 22:14:18 UTC (rev 1782) @@ -1,17 +1,17 @@ /* * fb-contrib - Auxiliary detectors for Java programs * Copyright (C) 2005-2015 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 @@ -106,9 +106,9 @@ public void report() { } - private static boolean hasSimilarParms(Type[] argTypes) { + private static boolean hasSimilarParms(Type... argTypes) { - for (int i = 0; i < argTypes.length - 1; i++) { + for (int i = 0; i < (argTypes.length - 1); i++) { if (argTypes[i].getSignature().startsWith("[")) { return true; } @@ -119,7 +119,7 @@ baseType = baseType.substring(1); } - for (int i = 0; i < argTypes.length - 1; i++) { + for (int i = 0; i < (argTypes.length - 1); i++) { if (argTypes[i].getSignature().equals(baseType)) { return true; } @@ -131,14 +131,16 @@ private boolean isInherited(Method m) throws ClassNotFoundException { JavaClass[] infs = javaClass.getAllInterfaces(); for (JavaClass inf : infs) { - if (hasMethod(inf, m)) + if (hasMethod(inf, m)) { return true; + } } JavaClass[] sups = javaClass.getSuperClasses(); for (JavaClass sup : sups) { - if (hasMethod(sup, m)) + if (hasMethod(sup, m)) { return true; + } } return false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |