Skip to content

Commit

Permalink
duplicate akka detector into pekko detector
Browse files Browse the repository at this point in the history
  • Loading branch information
mebigfatguy committed Dec 3, 2023
1 parent 87998b5 commit 52fd735
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
1 change: 1 addition & 0 deletions etc/bugrank.txt
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@
+2 BugPattern PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS
+0 BugPattern PDP_POORLY_DEFINED_PARAMETER
+0 BugPattern PIS_POSSIBLE_INCOMPLETE_SERIALIZATION
+0 BugPattern PKI_SUPERFLUOUS_ROUTE_SPECIFICATION
+0 BugPattern PL_PARALLEL_LISTS
+0 BugPattern PMB_INSTANCE_BASED_THREAD_LOCAL
+0 BugPattern PMB_LOCAL_BASED_JAXB_CONTEXT
Expand Down
4 changes: 3 additions & 1 deletion etc/findbugs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@

<Detector class="com.mebigfatguy.fbcontrib.detect.EnumIssues" speed="fast" reports="ENMI_EQUALS_ON_ENUM,ENMI_NULL_ENUM_VALUE,ENMI_ONE_ENUM_VALUE" />

<Detector class="com.mebigfatguy.fbcontrib.detect.AkkaIssues" speed="fast" reports="AKI_SUPERFLUOUS_ROUTE_SPECIFICATION" />
<Detector class="com.mebigfatguy.fbcontrib.detect.AkkaIssues" speed="fast" reports="AKI_SUPERFLUOUS_ROUTE_SPECIFICATION,PKI_SUPERFLUOUS_ROUTE_SPECIFICATION" />

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

Expand Down Expand Up @@ -655,4 +656,5 @@
<BugPattern abbrev="ENMI" type="ENMI_ONE_ENUM_VALUE" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="ENMI" type="ENMI_EQUALS_ON_ENUM" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="AKI" type="AKI_SUPERFLUOUS_ROUTE_SPECIFICATION" category="CORRECTNESS" experimental="true" />
<BugPattern abbrev="PKI" type="PKI_SUPERFLUOUS_ROUTE_SPECIFICATION" category="CORRECTNESS" experimental="true" />
</FindbugsPlugin>
13 changes: 13 additions & 0 deletions etc/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6598,6 +6598,18 @@ if (shouldCalcHalting && (calculateHaltingProbability() &gt; 0) { }
]]>
</Details>
</BugPattern>

<BugPattern type="PKI_SUPERFLUOUS_ROUTE_SPECIFICATION">
<ShortDescription>Method specifies superfluous routes thru route() or concat()</ShortDescription>
<LongDescription>Method {1} specifies superfluous routes thru route() or concat()</LongDescription>
<Details>
<![CDATA[
<p>This method uses the route() or concat() method to build optional routes but only passes 1 route to the method.
This just causes an extra route specification to be created for no reason. Only use route() or concat() when you have more than
one route to combine into one.
]]>
</Details>
</BugPattern>

<!-- BugCode -->

Expand Down Expand Up @@ -6750,4 +6762,5 @@ if (shouldCalcHalting && (calculateHaltingProbability() &gt; 0) { }
<BugCode abbrev="SAT">Suspicious Argument Types</BugCode>
<BugCode abbrev="ENMI">Enum Issues</BugCode>
<BugCode abbrev="AKI">Akka Issues</BugCode>
<BugCode abbrev="PKI">Akka Issues</BugCode>
</MessageCollection>
29 changes: 22 additions & 7 deletions src/main/java/com/mebigfatguy/fbcontrib/detect/AkkaIssues.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ public class AkkaIssues extends BytecodeScanningDetector {

private BugReporter bugReporter;
private OpcodeStack stack;
private JavaClass routeDirectivesClass;
private JavaClass akkaRouteDirectivesClass;
private JavaClass pekkoRouteDirectivesClass;
private boolean hasAkka;
private boolean hasPekko;

/**
* constructs a AKI detector given the reporter to report bugs on
Expand All @@ -51,16 +53,23 @@ public AkkaIssues(BugReporter bugReporter) {
this.bugReporter = bugReporter;

try {
routeDirectivesClass = Repository.lookupClass("akka.http.javadsl.server.directives.RouteDirectives");
akkaRouteDirectivesClass = Repository.lookupClass("akka.http.javadsl.server.directives.RouteDirectives");
hasAkka = true;
} catch (ClassNotFoundException e) {
hasAkka = false;
}
try {
pekkoRouteDirectivesClass = Repository
.lookupClass("org.apache.pekko.http.javadsl.server.directives.RouteDirectives");
hasPekko = true;
} catch (ClassNotFoundException e) {
hasPekko = false;
}
}

@Override
public void visitClassContext(ClassContext classContext) {
if (!hasAkka) {
if (!hasAkka && !hasPekko) {
return;
}

Expand Down Expand Up @@ -89,7 +98,7 @@ public void sawOpcode(int seen) {
if ("route".equals(methodName) || "concat".equals(methodName)) {
String clsName = getClassConstantOperand();
JavaClass cls = Repository.lookupClass(clsName);
if (cls.instanceOf(routeDirectivesClass)) {
if (cls.instanceOf(akkaRouteDirectivesClass) || cls.instanceOf(pekkoRouteDirectivesClass)) {
OpcodeStack.Item itm = null;
int bogusSize = -1;
if ("route".equals(methodName)) {
Expand All @@ -107,9 +116,15 @@ public void sawOpcode(int seen) {
if (itm != null) {
Integer size = (Integer) itm.getUserValue();
if (size != null && size.intValue() == bogusSize) {
bugReporter.reportBug(
new BugInstance(this, BugType.AKI_SUPERFLUOUS_ROUTE_SPECIFICATION.name(),
NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this));
if (hasAkka) {
bugReporter.reportBug(new BugInstance(this,
BugType.AKI_SUPERFLUOUS_ROUTE_SPECIFICATION.name(), NORMAL_PRIORITY)
.addClass(this).addMethod(this).addSourceLine(this));
} else if (hasPekko) {
bugReporter.reportBug(new BugInstance(this,
BugType.PKI_SUPERFLUOUS_ROUTE_SPECIFICATION.name(), NORMAL_PRIORITY)
.addClass(this).addMethod(this).addSourceLine(this));
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/mebigfatguy/fbcontrib/utils/BugType.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public enum BugType {
PCOA_PARTIALLY_CONSTRUCTED_OBJECT_ACCESS,
PDP_POORLY_DEFINED_PARAMETER,
PIS_POSSIBLE_INCOMPLETE_SERIALIZATION,
PKI_SUPERFLUOUS_ROUTE_SPECIFICATION,
PL_PARALLEL_LISTS,
PMB_INSTANCE_BASED_THREAD_LOCAL,
PMB_LOCAL_BASED_JAXB_CONTEXT,
Expand Down

0 comments on commit 52fd735

Please sign in to comment.