[Fb-contrib-commit] SF.net SVN: fb-contrib:[1817] trunk/fb-contrib
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2017-04-14 23:56:40
|
Revision: 1817
http://sourceforge.net/p/fb-contrib/code/1817
Author: dbrosius
Date: 2017-04-14 23:56:37 +0000 (Fri, 14 Apr 2017)
Log Message:
-----------
sync from github
Modified Paths:
--------------
trunk/fb-contrib/build.xml
trunk/fb-contrib/etc/bugrank.txt
trunk/fb-contrib/etc/findbugs.xml
trunk/fb-contrib/etc/messages.xml
trunk/fb-contrib/htdocs/index.shtml
trunk/fb-contrib/htdocs/repository.html
trunk/fb-contrib/pom.xml
trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/IOIssues.java
trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/ImmatureClass.java
trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java
trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/utils/BugType.java
trunk/fb-contrib/src/samples/java/ex/IMC_Sample.java
trunk/fb-contrib/src/samples/java/ex/IOI_Sample.java
Added Paths:
-----------
trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/UnnecessaryApiConversion.java
trunk/fb-contrib/src/samples/java/ex/UAC_Sample.java
Modified: trunk/fb-contrib/build.xml
===================================================================
--- trunk/fb-contrib/build.xml 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/build.xml 2017-04-14 23:56:37 UTC (rev 1817)
@@ -31,7 +31,7 @@
<property name="javac.debug" value="on" />
<property name="test_reports.dir" value="${target.dir}/reports/test"/>
- <property name="fb-contrib.version" value="6.9.0-SNAPSHOT" />
+ <property name="fb-contrib.version" value="7.0.0" />
<property name="sonatype.dir" value="${user.home}/.fb-contrib-${fb-contrib.version}-sonatype" />
Modified: trunk/fb-contrib/etc/bugrank.txt
===================================================================
--- trunk/fb-contrib/etc/bugrank.txt 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/etc/bugrank.txt 2017-04-14 23:56:37 UTC (rev 1817)
@@ -69,8 +69,10 @@
+0 BugPattern IMC_IMMATURE_CLASS_NO_PACKAGE
+2 BugPattern IMC_IMMATURE_CLASS_NO_TOSTRING
+0 BugPattern IMC_IMMATURE_CLASS_PRINTSTACKTRACE
++0 BugPattern IMC_IMMATURE_CLASS_WRONG_FIELD_ORDER
+0 BugPattern IOI_COPY_WITH_READER
+0 BugPattern IOI_DOUBLE_BUFFER_COPY
++0 BugPattern IOI_USE_OF_FILE_STREAM_CONSTRUCTORS
+0 BugPattern IPU_IMPROPER_PROPERTIES_USE
+0 BugPattern IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY
+0 BugPattern ISB_EMPTY_STRING_APPENDING
@@ -232,6 +234,8 @@
+0 BugPattern TBP_TRISTATE_BOOLEAN_PATTERN
+0 BugPattern TR_TAIL_RECURSION
+0 BugPattern UAA_USE_ADD_ALL
++0 BugPattern UAC_UNNECESSARY_API_CONVERSION_DATE_TO_INSTANT
++0 BugPattern UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH
+0 BugPattern UCC_UNRELATED_COLLECTION_CONTENTS
+0 BugPattern UCPM_USE_CHARACTER_PARAMETERIZED_METHOD
+0 BugPattern UEC_USE_ENUM_COLLECTIONS
Modified: trunk/fb-contrib/etc/findbugs.xml
===================================================================
--- trunk/fb-contrib/etc/findbugs.xml 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/etc/findbugs.xml 2017-04-14 23:56:37 UTC (rev 1817)
@@ -20,7 +20,7 @@
<!-- Detectors -->
-<!-- COMMENT OUT FOR RELEASE -->
+<!-- COMMENT OUT FOR RELEASE
<Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger" speed="fast"/>
@@ -30,7 +30,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedAssignmentScope" speed="fast" reports="BAS_BLOATED_ASSIGNMENT_SCOPE" hidden="true" />
-<!-- COMMENT OUT FOR RELEASE -->
+ COMMENT OUT FOR RELEASE -->
<Detector class="com.mebigfatguy.fbcontrib.collect.CollectStatistics" speed="fast" reports="" hidden="true" />
@@ -77,7 +77,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.NeedlessAutoboxing" speed="fast"
reports="NAB_NEEDLESS_AUTOBOXING_CTOR,NAB_NEEDLESS_BOXING_STRING_CTOR,NAB_NEEDLESS_AUTOBOXING_VALUEOF,NAB_NEEDLESS_BOXING_PARSE,NAB_NEEDLESS_BOXING_VALUEOF,NAB_NEEDLESS_BOX_TO_UNBOX,NAB_NEEDLESS_BOX_TO_CAST,NAB_NEEDLESS_BOOLEAN_CONSTANT_CONVERSION" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn" speed="fast" reports="USBR_UNNECESSARY_STORE_BEFORE_RETURN" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryStoreBeforeReturn" speed="fast" reports="USBR_UNNECESSARY_STORE_BEFORE_RETURN,UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH" />
<Detector class="com.mebigfatguy.fbcontrib.detect.CopiedOverriddenMethod" speed="fast" reports="COM_COPIED_OVERRIDDEN_METHOD,COM_PARENT_DELEGATED_CALL" />
@@ -285,7 +285,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.StringifiedTypes" speed="fast" reports="STT_STRING_PARSING_A_FIELD,STT_TOSTRING_STORED_IN_FIELD" />
- <Detector class="com.mebigfatguy.fbcontrib.detect.ImmatureClass" speed="moderate" reports="IMC_IMMATURE_CLASS_NO_EQUALS,IMC_IMMATURE_CLASS_NO_HASHCODE,IMC_IMMATURE_CLASS_NO_PACKAGE,IMC_IMMATURE_CLASS_NO_TOSTRING,IMC_IMMATURE_CLASS_IDE_GENERATED_PARAMETER_NAMES,IMC_IMMATURE_CLASS_PRINTSTACKTRACE" />
+ <Detector class="com.mebigfatguy.fbcontrib.detect.ImmatureClass" speed="moderate" reports="IMC_IMMATURE_CLASS_NO_EQUALS,IMC_IMMATURE_CLASS_NO_HASHCODE,IMC_IMMATURE_CLASS_NO_PACKAGE,IMC_IMMATURE_CLASS_NO_TOSTRING,IMC_IMMATURE_CLASS_IDE_GENERATED_PARAMETER_NAMES,IMC_IMMATURE_CLASS_PRINTSTACKTRACE,IMC_IMMATURE_CLASS_WRONG_FIELD_ORDER" />
<Detector class="com.mebigfatguy.fbcontrib.detect.JAXRSIssues" speed="fast" reports="JXI_GET_ENDPOINT_CONSUMES_CONTENT,JXI_INVALID_CONTEXT_PARAMETER_TYPE,JXI_PARM_PARAM_NOT_FOUND_IN_PATH,JXI_UNDEFINED_PARAMETER_SOURCE_IN_ENDPOINT" />
@@ -295,7 +295,7 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.SuboptimalExpressionOrder" speed="fast" reports="SEO_SUBOPTIMAL_EXPRESSION_ORDER"/>
- <Detector class="com.mebigfatguy.fbcontrib.detect.IOIssues" speed="fast" reports="IOI_DOUBLE_BUFFER_COPY,IOI_COPY_WITH_READER"/>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.IOIssues" speed="fast" reports="IOI_DOUBLE_BUFFER_COPY,IOI_COPY_WITH_READER,IOI_USE_OF_FILE_STREAM_CONSTRUCTORS"/>
<Detector class="com.mebigfatguy.fbcontrib.detect.DubiousMapCollection" speed="fast" reports="DMC_DUBIOUS_MAP_COLLECTION"/>
@@ -305,10 +305,6 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.ConcurrentCollectionIssues" speed="fast" reports="CCI_CONCURRENT_COLLECTION_ISSUES_USE_PUT_IS_RACY"/>
- <!-- COMMENT OUT FOR POINT RELEASE -->
-
- <Detector class="com.mebigfatguy.fbcontrib.detect.UseTryWithResources" speed="fast" reports="UTWR_USE_TRY_WITH_RESOURCES"/>
-
<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousShadedClassUse" speed="fast" reports="SSCU_SUSPICIOUS_SHADED_CLASS_USE"/>
<Detector class="com.mebigfatguy.fbcontrib.detect.UnsynchronizedSingletonFieldWrites" speed="fast" reports="USFW_UNSYNCHRONIZED_SINGLETON_FIELD_WRITES"/>
@@ -315,8 +311,14 @@
<Detector class="com.mebigfatguy.fbcontrib.detect.OptionalIssues" speed="fast" reports="OI_OPTIONAL_ISSUES_USES_IMMEDIATE_EXECUTION,OI_OPTIONAL_ISSUES_USES_DELAYED_EXECUTION,OI_OPTIONAL_ISSUES_CHECKING_REFERENCE,OI_OPTIONAL_ISSUES_PRIMITIVE_VARIANT_PREFERRED"/>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryApiConversion" speed="fast" reports="UAC_UNNECESSARY_API_CONVERSION_DATE_TO_INSTANT"/>
+
<!-- COMMENT OUT FOR POINT RELEASE -->
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UseTryWithResources" speed="fast" reports="UTWR_USE_TRY_WITH_RESOURCES"/>
+
+ <!-- COMMENT OUT FOR POINT RELEASE -->
+
<!-- BugPattern -->
<BugPattern abbrev="ISB" type="ISB_INEFFICIENT_STRING_BUFFERING" category="PERFORMANCE" />
@@ -567,6 +569,7 @@
<BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_NO_PACKAGE" category="STYLE" />
<BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_NO_TOSTRING" category="STYLE" />
<BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_PRINTSTACKTRACE" category="STYLE" />
+ <BugPattern abbrev="IMC" type="IMC_IMMATURE_CLASS_WRONG_FIELD_ORDER" category="STYLE" />
<BugPattern abbrev="JXI" type="JXI_GET_ENDPOINT_CONSUMES_CONTENT" category="CORRECTNESS" />
<BugPattern abbrev="JXI" type="JXI_INVALID_CONTEXT_PARAMETER_TYPE" category="CORRECTNESS" />
<BugPattern abbrev="JXI" type="JXI_PARM_PARAM_NOT_FOUND_IN_PATH" category="CORRECTNESS" />
@@ -581,6 +584,7 @@
<BugPattern abbrev="SEO" type="SEO_SUBOPTIMAL_EXPRESSION_ORDER" category="PERFORMANCE"/>
<BugPattern abbrev="IOI" type="IOI_DOUBLE_BUFFER_COPY" category="PERFORMANCE"/>
<BugPattern abbrev="IOI" type="IOI_COPY_WITH_READER" category="PERFORMANCE"/>
+ <BugPattern abbrev="IOI" type="IOI_USE_OF_FILE_STREAM_CONSTRUCTORS"/>
<BugPattern abbrev="DMC" type="DMC_DUBIOUS_MAP_COLLECTION" category="CORRECTNESS"/>
<BugPattern abbrev="BL" type="BL_BURYING_LOGIC" category="STYLE"/>
<BugPattern abbrev="WI" type="WI_DUPLICATE_WIRED_TYPES" category="CORRECTNESS"/>
@@ -592,4 +596,6 @@
<BugPattern abbrev="OI" type="OI_OPTIONAL_ISSUES_USES_DELAYED_EXECUTION" category="CORRECTNESS" experimental="true"/>
<BugPattern abbrev="OI" type="OI_OPTIONAL_ISSUES_CHECKING_REFERENCE" category="CORRECTNESS" experimental="true"/>
<BugPattern abbrev="OI" type="OI_OPTIONAL_ISSUES_PRIMITIVE_VARIANT_PREFERRED" category="CORRECTNESS" experimental="true"/>
+ <BugPattern abbrev="UAC" type="UAC_UNNECESSARY_API_CONVERSION_DATE_TO_INSTANT" category="CORRECTNESS" experimental="true"/>
+ <BugPattern abbrev="UAC" type="UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH" category="CORRECTNESS" experimental="true"/>
</FindbugsPlugin>
Modified: trunk/fb-contrib/etc/messages.xml
===================================================================
--- trunk/fb-contrib/etc/messages.xml 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/etc/messages.xml 2017-04-14 23:56:37 UTC (rev 1817)
@@ -1685,7 +1685,18 @@
</Details>
</Detector>
+ <Detector class="com.mebigfatguy.fbcontrib.detect.UnnecessaryApiConversion">
+ <Details>
+ <![CDATA[
+ <p>Looks for code that appears to be using two forms of similar apis, an older one, and a new one.
+ It finds code that creates newer api objects by first instantiating older api objects, and converting
+ them into the new form. It is simpler just to create the new object directly.</p>
+ <p>It is a fast detector</p>
+ ]]>
+ </Details>
+ </Detector>
+
<Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger">
<Details></Details>
</Detector>
@@ -5415,6 +5426,20 @@
</Details>
</BugPattern>
+ <BugPattern type="IMC_IMMATURE_CLASS_WRONG_FIELD_ORDER">
+ <ShortDescription>Class orders instance fields before static fields</ShortDescription>
+ <LongDescription>Class {0} orders instance fields before static fields</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This class adds fields to the class in an order that is confusing, and not expected by
+ other developers. The standard is for static fields to be listed first, followed by instance
+ fields. when fields are listed out of order, developers may make assumptions about their
+ behaviour that is incorrect and lead to bugs.</p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+
<BugPattern type="JXI_GET_ENDPOINT_CONSUMES_CONTENT">
<ShortDescription>JAX-RS Method implements a GET request but consumes input</ShortDescription>
<LongDescription>JAX-RS Method {1} implements a GET request but consumes input</LongDescription>
@@ -5617,6 +5642,26 @@
</Details>
</BugPattern>
+ <BugPattern type="IOI_USE_OF_FILE_STREAM_CONSTRUCTORS">
+ <ShortDescription>Method uses a FileInputStream or FileOutputStream constructor</ShortDescription>
+ <LongDescription>Method {1} uses a FileInputStream or FileOutputStream constructor</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates and uses a java.io.FileInputStream or java.io.FileOutputStream object. Unfortunately both
+ of these classes implement a finalize method, which means that objects created will likely hang around until a
+ full garbage collection occurs, which will leave excessive garbage on the heap for longer, and potentially much
+ longer than expected. Java 7 introduced two ways to create streams for reading and writing files that do not have this concern.
+ You should consider switching from these above classes to
+ <code>
+ InputStream is = java.nio.file.Files.newInputStream(myfile.toPath());
+ OutputStream os = java.nio.file.Files.newOutputStream(myfile.toPath());
+ </code>
+ </p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+
<BugPattern type="DMC_DUBIOUS_MAP_COLLECTION">
<ShortDescription>Class holds a map-type field, but uses it as only a List</ShortDescription>
<LongDescription>Class {0} holds a map-type field {1}, but uses it as only a List</LongDescription>
@@ -5772,6 +5817,32 @@
]]>
</Details>
</BugPattern>
+
+ <BugPattern type="UAC_UNNECESSARY_API_CONVERSION_DATE_TO_INSTANT">
+ <ShortDescription>Method constructs a Date object, merely to convert it to an Instant object</ShortDescription>
+ <LongDescription>Method {1} constructs a Date object, merely to convert it to an Instant object</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates a java.time.Instant object by first creating a java.util.Date object, and then calling
+ toInstant() on it. It is simpler to just construct the Instant object directly, say by using
+ {@code Instant.now()} to get the current time, of by using {@code Instant.parse(CharSequence)} to convert a String.
+ </p>
+ ]]>
+ </Details>
+ </BugPattern>
+
+ <BugPattern type="UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH">
+ <ShortDescription>Method constructs a File object, merely to convert it to a Path object</ShortDescription>
+ <LongDescription>Method {1} constructs a File object, merely to convert it to a Path object</LongDescription>
+ <Details>
+ <![CDATA[
+ <p>This method creates a java.nio.file.Path object by first creating a java.io.File object, and then calling
+ toPath() on it. It is simpler to just construct the Path object directly, say by using
+ {@code Path.get(String...)}.
+ </p>
+ ]]>
+ </Details>
+ </BugPattern>
<!-- BugCode -->
@@ -5914,4 +5985,5 @@
<BugCode abbrev="SSCU">Suspicious Shaded Class Use</BugCode>
<BugCode abbrev="USFW">Unsynchronized Singleton Field Writes</BugCode>
<BugCode abbrev="OI">Optional Issues</BugCode>
+ <BugCode abbrev="UAC">Unnecessary Api Conversion</BugCode>
</MessageCollection>
Modified: trunk/fb-contrib/htdocs/index.shtml
===================================================================
--- trunk/fb-contrib/htdocs/index.shtml 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/htdocs/index.shtml 2017-04-14 23:56:37 UTC (rev 1817)
@@ -68,7 +68,7 @@
</li>
</ul>
</p>
- <p style="font-weight: bold;">The latest version of fb-contrib is 6.8.4 available for download
+ <p style="font-weight: bold;">The latest version of fb-contrib is 7.0.0 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
@@ -77,13 +77,20 @@
</div>
<hr/>
- <img id="git_image" src="flip2.gif" onClick="toggleBlock('git', 'git_image');" align="top"/>
+ <img id="git_image" src="flip1.gif" onClick="toggleBlock('git', 'git_image');" align="top"/>
Detectors added in git<br/>
- <div id="git" style="display:block;">
- <ul>
+ <div id="git" style="display:none;">
+ <ul>
<li><b>[UTWR] Use Try With Resources</b><br/>
Looks for try/finally blocks that manage resources, without using try-with-resources.
</li>
+ </ul>
+ </div>
+ <hr/>
+ <img id="v7_0_0_image" src="flip2.gif" onClick="toggleBlock('v7_0_0', 'v7_0_0_image');" align="top"/>
+ Detectors added in v7.0.0<br/>
+ <div id="v7_0_0" style="display:block;">
+ <ul>
<li><b>[SSCU] Suspicious Shaded Class Use</b><br/>
Looks for use of classes that have been shaded into 3rdparty jars, rather than using the
real class, from the real jar.
@@ -94,6 +101,11 @@
<li><b>[OI] Optional Issues</b><br/>
Looks for various issues around use of java.util.Optional
</li>
+ <li><b>[UAC] Unnecessary Api Conversion</b><br/>
+ Looks for code that appears to be using two forms of similar apis, an older one, and a new one.
+ It finds code that creates newer api objects by first instantiating older api objects, and converting
+ them into the new form. It is simpler just to create the new object directly.
+ </li>
</ul>
</div>
<hr/>
Modified: trunk/fb-contrib/htdocs/repository.html
===================================================================
--- trunk/fb-contrib/htdocs/repository.html 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/htdocs/repository.html 2017-04-14 23:56:37 UTC (rev 1817)
@@ -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.8.4</td></tr>
+ <tr><td><b>Version:</b></td><td>7.0.0</td></tr>
</table>
</div>
Modified: trunk/fb-contrib/pom.xml
===================================================================
--- trunk/fb-contrib/pom.xml 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/pom.xml 2017-04-14 23:56:37 UTC (rev 1817)
@@ -8,7 +8,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.fb-contrib</groupId>
<artifactId>fb-contrib</artifactId>
- <version>6.9.0-SNAPSHOT</version>
+ <version>7.0.0</version>
<prerequisites>
<maven>2.2.1</maven>
Modified: trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/IOIssues.java
===================================================================
--- trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/IOIssues.java 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/IOIssues.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -20,6 +20,7 @@
import java.util.Set;
+import org.apache.bcel.Constants;
import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.JavaClass;
@@ -73,6 +74,7 @@
private BugReporter bugReporter;
private OpcodeStack stack;
+ private int clsVersion;
/**
* constructs a IOI detector given the reporter to report bugs on
@@ -102,6 +104,7 @@
try {
stack = new OpcodeStack();
+ clsVersion = clsContext.getJavaClass().getMajor();
super.visitClassContext(clsContext);
} finally {
stack = null;
@@ -124,7 +127,8 @@
/**
* implements the visitor to look for common api copy utilities to copy streams where the passed in Stream is Buffered. Since these libraries already handle
* the buffering, you are just slowing them down by the extra copy. Also look for copies where the source is a Reader, as this is just wasteful. Can't wrap
- * my head around whether a Writer output is sometime valid, might be, so for now ignoring that.
+ * my head around whether a Writer output is sometime valid, might be, so for now ignoring that. Also reports uses of java.io.FileInputStream and
+ * java.io.FileOutputStream on {@code java >= 1.7} as those classes have finalize methods that junk up gc.
*
* @param seen
* the currently parsed opcode
@@ -164,6 +168,11 @@
String clsName = getDottedClassConstantOperand();
if (BUFFERED_CLASSES.contains(clsName)) {
return IOIUserValue.BUFFER;
+ } else if ("java.io.FileInputStream".equals(clsName) || "java.io.FileOutputStream".equals(clsName)) {
+ if (clsVersion >= Constants.MAJOR_1_7) {
+ bugReporter.reportBug(new BugInstance(this, BugType.IOI_USE_OF_FILE_STREAM_CONSTRUCTORS.name(), NORMAL_PRIORITY).addClass(this)
+ .addMethod(this).addSourceLine(this));
+ }
} else if (readerClass != null) {
JavaClass cls = Repository.lookupClass(clsName);
if (cls.instanceOf(readerClass)) {
Modified: trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/ImmatureClass.java
===================================================================
--- trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/ImmatureClass.java 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/ImmatureClass.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -36,7 +36,12 @@
NOT_NEEDED, UNKNOWN, NEEDED
};
+ enum FieldStatus {
+ NONE, SAW_INSTANCE, REPORTED
+ }
+
private BugReporter bugReporter;
+ private FieldStatus fieldStatus = FieldStatus.NONE;
public ImmatureClass(BugReporter reporter) {
bugReporter = reporter;
@@ -51,6 +56,7 @@
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass cls = classContext.getJavaClass();
+ fieldStatus = FieldStatus.NONE;
if (cls.getPackageName().isEmpty()) {
bugReporter.reportBug(new BugInstance(this, BugType.IMC_IMMATURE_CLASS_NO_PACKAGE.name(), LOW_PRIORITY).addClass(cls));
@@ -112,6 +118,30 @@
super.visitClassContext(classContext);
}
+ @Override
+ public void visitField(Field f) {
+ if (!f.isSynthetic() && !f.getName().contains("$")) {
+ switch (fieldStatus) {
+ case NONE:
+ if (!f.isStatic()) {
+ fieldStatus = FieldStatus.SAW_INSTANCE;
+ }
+ break;
+
+ case SAW_INSTANCE:
+ if (f.isStatic()) {
+ bugReporter.reportBug(
+ new BugInstance(this, BugType.IMC_IMMATURE_CLASS_WRONG_FIELD_ORDER.name(), LOW_PRIORITY).addClass(this).addField(this));
+ fieldStatus = FieldStatus.REPORTED;
+ }
+ break;
+
+ case REPORTED:
+ break;
+ }
+ }
+ }
+
/**
* implements the visitor to check for calls to Throwable.printStackTrace()
*
Modified: trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java
===================================================================
--- trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/SpoiledChildInterfaceImplementor.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -20,8 +20,6 @@
import java.util.BitSet;
import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
import java.util.Set;
import org.apache.bcel.Constants;
@@ -131,22 +129,6 @@
}
/**
- * removes all methods from the map that are synthetic
- *
- * @param methods
- * the methods to check
- */
- private void removeSyntheticMethods(Map<QMethod, Boolean> methods) {
- Iterator<Map.Entry<QMethod, Boolean>> it = methods.entrySet().iterator();
- while (it.hasNext()) {
- Map.Entry<QMethod, Boolean> entry = it.next();
- if (entry.getValue().booleanValue()) {
- it.remove();
- }
- }
- }
-
- /**
* builds a set of all non constructor or static initializer method/signatures
*
* @param cls
Added: trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/UnnecessaryApiConversion.java
===================================================================
--- trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/UnnecessaryApiConversion.java (rev 0)
+++ trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/UnnecessaryApiConversion.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -0,0 +1,108 @@
+/*
+ * fb-contrib - Auxiliary detectors for Java programs
+ * Copyright (C) 2005-2017 Dave Brosius
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package com.mebigfatguy.fbcontrib.detect;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.bcel.classfile.Code;
+
+import com.mebigfatguy.fbcontrib.utils.BugType;
+import com.mebigfatguy.fbcontrib.utils.FQMethod;
+
+import edu.umd.cs.findbugs.BugInstance;
+import edu.umd.cs.findbugs.BugReporter;
+import edu.umd.cs.findbugs.BytecodeScanningDetector;
+import edu.umd.cs.findbugs.OpcodeStack;
+import edu.umd.cs.findbugs.ba.ClassContext;
+import edu.umd.cs.findbugs.ba.XMethod;
+
+/**
+ * looks for code that appears to be using two forms of similar apis, an older one, and a new one. It finds code that creates newer api objects by first
+ * instantiating older api objects, and converting them into the new form. It is simpler just to create the new object directly.
+ */
+public class UnnecessaryApiConversion extends BytecodeScanningDetector {
+
+ private static Map<FQMethod, LegacyInfo> conversions = new HashMap<>();
+
+ static {
+ conversions.put(new FQMethod("java/util/Date", "toInstant", "()Ljava/time/Instant;"),
+ new LegacyInfo("<init>", BugType.UAC_UNNECESSARY_API_CONVERSION_DATE_TO_INSTANT));
+ conversions.put(new FQMethod("java/io/File", "toPath", "()Ljava/nio/file/Path;"),
+ new LegacyInfo("<init>", BugType.UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH));
+
+ }
+
+ private BugReporter bugReporter;
+ private OpcodeStack stack;
+
+ public UnnecessaryApiConversion(BugReporter bugReporter) {
+ this.bugReporter = bugReporter;
+ }
+
+ @Override
+ public void visitClassContext(ClassContext classContext) {
+ try {
+ stack = new OpcodeStack();
+ super.visitClassContext(classContext);
+ } finally {
+ stack = null;
+ }
+ }
+
+ @Override
+ public void visitCode(Code obj) {
+ stack.resetForMethodEntry(this);
+ super.visitCode(obj);
+ }
+
+ @Override
+ public void sawOpcode(int seen) {
+
+ try {
+ switch (seen) {
+ case INVOKEVIRTUAL:
+ FQMethod conversionMethod = new FQMethod(getClassConstantOperand(), getNameConstantOperand(), getSigConstantOperand());
+ LegacyInfo legacyInfo = conversions.get(conversionMethod);
+ if ((legacyInfo != null) && (stack.getStackDepth() > 0)) {
+ OpcodeStack.Item itm = stack.getStackItem(0);
+ XMethod xm = itm.getReturnValueOf();
+ if ((xm != null) && (xm.getName().equals(legacyInfo.methodName)
+ && (xm.getClassName().equals(conversionMethod.getClassName().replace('/', '.'))))) {
+ bugReporter.reportBug(
+ new BugInstance(this, legacyInfo.bugType.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
+ }
+ }
+ break;
+ }
+ } finally {
+ stack.sawOpcode(this, seen);
+ }
+ }
+
+ static class LegacyInfo {
+ String methodName;
+ BugType bugType;
+
+ public LegacyInfo(String methodName, BugType bugType) {
+ this.methodName = methodName;
+ this.bugType = bugType;
+ }
+ }
+}
Property changes on: trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/detect/UnnecessaryApiConversion.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/utils/BugType.java
===================================================================
--- trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/utils/BugType.java 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/src/main/java/com/mebigfatguy/fbcontrib/utils/BugType.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -100,8 +100,10 @@
IMC_IMMATURE_CLASS_NO_PACKAGE,
IMC_IMMATURE_CLASS_NO_TOSTRING,
IMC_IMMATURE_CLASS_PRINTSTACKTRACE,
+ IMC_IMMATURE_CLASS_WRONG_FIELD_ORDER,
IOI_COPY_WITH_READER,
IOI_DOUBLE_BUFFER_COPY,
+ IOI_USE_OF_FILE_STREAM_CONSTRUCTORS,
IPU_IMPROPER_PROPERTIES_USE,
IPU_IMPROPER_PROPERTIES_USE_SETPROPERTY,
ISB_EMPTY_STRING_APPENDING,
@@ -272,6 +274,8 @@
TR_TAIL_RECURSION,
UAA_USE_ADD_ALL,
+ UAC_UNNECESSARY_API_CONVERSION_DATE_TO_INSTANT,
+ UAC_UNNECESSARY_API_CONVERSION_FILE_TO_PATH,
UCC_UNRELATED_COLLECTION_CONTENTS,
UCPM_USE_CHARACTER_PARAMETERIZED_METHOD,
UEC_USE_ENUM_COLLECTIONS,
Modified: trunk/fb-contrib/src/samples/java/ex/IMC_Sample.java
===================================================================
--- trunk/fb-contrib/src/samples/java/ex/IMC_Sample.java 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/src/samples/java/ex/IMC_Sample.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -1,4 +1,5 @@
package ex;
+
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
@@ -17,6 +18,8 @@
private String reportMe;
+ private static final int OUT_OF_PLACE_STATIC = 0;
+
@SuperSecret
class FPClassIMC {
private String dontReportMe;
@@ -26,7 +29,7 @@
@SuperSecret
private String dontReportMe;
}
-
+
public void psf(File f) {
try (InputStream is = new FileInputStream(f)) {
is.read();
Modified: trunk/fb-contrib/src/samples/java/ex/IOI_Sample.java
===================================================================
--- trunk/fb-contrib/src/samples/java/ex/IOI_Sample.java 2017-04-09 22:42:29 UTC (rev 1816)
+++ trunk/fb-contrib/src/samples/java/ex/IOI_Sample.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -1,11 +1,14 @@
package ex;
+
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import org.apache.commons.io.IOUtils;
@@ -28,4 +31,17 @@
return baos.toByteArray();
}
}
+
+ public void copy(String inName, String outName) throws IOException {
+ byte[] buf = new byte[1024];
+
+ try (InputStream is = new FileInputStream(inName); OutputStream os = new FileOutputStream(outName);) {
+
+ int size = is.read(buf);
+ while (size >= 0) {
+ os.write(buf, 0, size);
+ size = is.read(buf);
+ }
+ }
+ }
}
Added: trunk/fb-contrib/src/samples/java/ex/UAC_Sample.java
===================================================================
--- trunk/fb-contrib/src/samples/java/ex/UAC_Sample.java (rev 0)
+++ trunk/fb-contrib/src/samples/java/ex/UAC_Sample.java 2017-04-14 23:56:37 UTC (rev 1817)
@@ -0,0 +1,18 @@
+package ex;
+
+import java.io.File;
+import java.nio.file.Path;
+import java.time.Instant;
+import java.util.Date;
+
+public class UAC_Sample {
+
+ public Instant getInstant() {
+ return new Date().toInstant();
+ }
+
+ public Path getPath() {
+
+ return new File("hello.world").toPath();
+ }
+}
Property changes on: trunk/fb-contrib/src/samples/java/ex/UAC_Sample.java
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|