Skip to content

Commit

Permalink
Merge branch 'findbugs' into spotbugs
Browse files Browse the repository at this point in the history
 Conflicts:
	build.xml
	pom.xml
	src/main/java/com/mebigfatguy/fbcontrib/detect/WiringIssues.java
	src/main/java/com/mebigfatguy/fbcontrib/utils/BugType.java
  • Loading branch information
mebigfatguy committed Nov 17, 2019
2 parents da03b0d + 1bc5af3 commit 42a1c7e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<property name="javac.debug" value="on" />
<property name="test_reports.dir" value="${target.dir}/reports/test"/>

<property name="sb-contrib.version" value="7.4.7" />
<property name="fb-contrib.version" value="7.4.8-SNAPSHOT" />

<property name="sonatype.dir" value="${user.home}/.sb-contrib-${sb-contrib.version}-sonatype" />

Expand Down
1 change: 1 addition & 0 deletions etc/bugrank.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,5 +306,6 @@
+0 BugPattern WEM_WEAK_EXCEPTION_MESSAGING
+0 BugPattern WI_DUPLICATE_WIRED_TYPES
+0 BugPattern WI_MANUALLY_ALLOCATING_AN_AUTOWIRED_BEAN
+0 BugPattern WI_WIRING_OF_STATIC_FIELD
+0 BugPattern WOC_WRITE_ONLY_COLLECTION_FIELD
+0 BugPattern WOC_WRITE_ONLY_COLLECTION_LOCAL
11 changes: 6 additions & 5 deletions etc/findbugs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

<!-- Detectors -->

<!-- COMMENT OUT FOR RELEASE
<!-- COMMENT OUT FOR RELEASE -->

<Detector class="com.mebigfatguy.fbcontrib.debug.OCSDebugger" speed="fast"/>

<Detector class="com.mebigfatguy.fbcontrib.detect.BloatedSynchronizedBlock" speed="fast" reports="BSB_BLOATED_SYNCHRONIZED_BLOCK" hidden="true" />

<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" />

Expand Down Expand Up @@ -302,7 +302,7 @@

<Detector class="com.mebigfatguy.fbcontrib.detect.BuryingLogic" speed="fast" reports="BL_BURYING_LOGIC"/>

<Detector class="com.mebigfatguy.fbcontrib.detect.WiringIssues" speed="fast" reports="WI_DUPLICATE_WIRED_TYPES,WI_MANUALLY_ALLOCATING_AN_AUTOWIRED_BEAN"/>
<Detector class="com.mebigfatguy.fbcontrib.detect.WiringIssues" speed="fast" reports="WI_DUPLICATE_WIRED_TYPES,WI_MANUALLY_ALLOCATING_AN_AUTOWIRED_BEAN,WI_WIRING_OF_STATIC_FIELD"/>

<Detector class="com.mebigfatguy.fbcontrib.detect.ConcurrentCollectionIssues" speed="fast" reports="CCI_CONCURRENT_COLLECTION_ISSUES_USE_PUT_IS_RACY"/>

Expand Down Expand Up @@ -332,11 +332,11 @@

<Detector class="com.mebigfatguy.fbcontrib.detect.ClassEnvy" speed="slow" reports="CE_CLASS_ENVY" />

<!-- COMMENT OUT FOR POINT RELEASE
<!-- COMMENT OUT FOR POINT RELEASE -->

<Detector class="com.mebigfatguy.fbcontrib.detect.SuspiciousArgumentTypes" speed="fast" reports="SAT_SUSPICIOUS_ARGUMENT_TYPES" />

COMMENT OUT FOR POINT RELEASE -->
<!-- COMMENT OUT FOR POINT RELEASE -->

<!-- BugPattern -->

Expand Down Expand Up @@ -616,6 +616,7 @@
<BugPattern abbrev="BL" type="BL_BURYING_LOGIC" category="STYLE"/>
<BugPattern abbrev="WI" type="WI_DUPLICATE_WIRED_TYPES" category="CORRECTNESS"/>
<BugPattern abbrev="WI" type="WI_MANUALLY_ALLOCATING_AN_AUTOWIRED_BEAN" category="CORRECTNESS"/>
<BugPattern abbrev="WI" type="WI_WIRING_OF_STATIC_FIELD" category="CORRECTNESS"/>
<BugPattern abbrev="CCI" type="CCI_CONCURRENT_COLLECTION_ISSUES_USE_PUT_IS_RACY" category="CORRECTNESS"/>
<BugPattern abbrev="UTWR" type="UTWR_USE_TRY_WITH_RESOURCES" category="STYLE" experimental="true"/>
<BugPattern abbrev="SSCU" type="SSCU_SUSPICIOUS_SHADED_CLASS_USE" category="CORRECTNESS"/>
Expand Down
13 changes: 13 additions & 0 deletions etc/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5950,6 +5950,19 @@ if (shouldCalcHalting && (calculateHaltingProbability() &gt; 0) { }
]]>
</Details>
</BugPattern>

<BugPattern type="WI_WIRING_OF_STATIC_FIELD">
<ShortDescription>Static field is autowired</ShortDescription>
<LongDescription>Static Field {1} is autowired</LongDescription>
<Details>
<![CDATA[
<p>Autowiring of static fields does not work using simple @Autowire annotations, not should you attempt to do
so as it's an anti pattern. Use PostConstruct methods to initialize static fields if you must do something
like this.</p>
]]>
</Details>

</BugPattern>

<BugPattern type="CCI_CONCURRENT_COLLECTION_ISSUES_USE_PUT_IS_RACY">
<ShortDescription>Method gets and sets a value of a ConcurrentHashMap in a racy manner</ShortDescription>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.mebigfatguy.sb-contrib</groupId>
<artifactId>sb-contrib</artifactId>
<version>7.4.7</version>
<version>7.4.8-SNAPSHOT</version>

<!-- TODO: Oss parent is obsolete, define items directly for releasing -->
<parent>
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/mebigfatguy/fbcontrib/detect/WiringIssues.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ public void visitClassContext(ClassContext classContext) {
}
}

@Override
public void visitField(Field obj) {
if (obj.isStatic()) {
for (AnnotationEntry entry : obj.getAnnotationEntries()) {
if (SPRING_AUTOWIRED.equals(entry.getAnnotationType())) {
bugReporter
.reportBug(new BugInstance(this, BugType.WI_WIRING_OF_STATIC_FIELD.name(), NORMAL_PRIORITY)
.addClass(this).addField(this));
break;
}
}
}
}

@Override
public void visitCode(Code obj) {
Method m = getMethod();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/mebigfatguy/fbcontrib/utils/BugType.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public enum BugType {
UTAO_TESTNG_ASSERTION_ODDITIES_NO_ASSERT, UTA_USE_TO_ARRAY, UVA_USE_VAR_ARGS, UTWR_USE_TRY_WITH_RESOURCES,

WEM_OBSCURING_EXCEPTION, WEM_WEAK_EXCEPTION_MESSAGING, WI_DUPLICATE_WIRED_TYPES,
WI_MANUALLY_ALLOCATING_AN_AUTOWIRED_BEAN, WOC_WRITE_ONLY_COLLECTION_FIELD, WOC_WRITE_ONLY_COLLECTION_LOCAL;
WI_MANUALLY_ALLOCATING_AN_AUTOWIRED_BEAN, WOC_WRITE_ONLY_COLLECTION_FIELD, WOC_WRITE_ONLY_COLLECTION_LOCAL,
WI_WIRING_OF_STATIC_FIELD,
// @formatter:on
}

0 comments on commit 42a1c7e

Please sign in to comment.