Skip to content

Commit efc1c04

Browse files
committed
Add spotbugs & pmd for static analysis
Also move internal state validation into DoSomethingProvider since that sits in test code
1 parent df1a083 commit efc1c04

File tree

13 files changed

+106
-21
lines changed

13 files changed

+106
-21
lines changed

pom.xml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
<scope>provided</scope>
5555
</dependency>
5656

57+
<dependency>
58+
<!-- used so that lombok can generate suppressions for spotbugs. It needs to find it on the relevant classpath -->
59+
<groupId>com.github.spotbugs</groupId>
60+
<artifactId>spotbugs</artifactId>
61+
<version>4.7.1</version>
62+
</dependency>
63+
5764
<dependency>
5865
<groupId>org.slf4j</groupId>
5966
<artifactId>slf4j-api</artifactId>
@@ -132,6 +139,7 @@
132139
</argLine>
133140
</configuration>
134141
</plugin>
142+
135143
<plugin>
136144
<groupId>org.apache.maven.plugins</groupId>
137145
<artifactId>maven-failsafe-plugin</artifactId>
@@ -263,6 +271,54 @@
263271
</plugin>
264272
<!-- end sign -->
265273

274+
<plugin>
275+
<groupId>org.apache.maven.plugins</groupId>
276+
<artifactId>maven-pmd-plugin</artifactId>
277+
<version>3.13.0</version>
278+
<executions>
279+
<execution>
280+
<id>run-pmd</id>
281+
<phase>verify</phase>
282+
<goals>
283+
<goal>check</goal>
284+
</goals>
285+
</execution>
286+
</executions>
287+
</plugin>
288+
289+
<plugin>
290+
<groupId>com.github.spotbugs</groupId>
291+
<artifactId>spotbugs-maven-plugin</artifactId>
292+
<version>4.7.0.0</version>
293+
<configuration>
294+
<excludeFilterFile>spotbugs-exclusions.xml</excludeFilterFile>
295+
<plugins>
296+
<plugin>
297+
<groupId>com.h3xstream.findsecbugs</groupId>
298+
<artifactId>findsecbugs-plugin</artifactId>
299+
<version>1.12.0</version>
300+
</plugin>
301+
</plugins>
302+
</configuration>
303+
<dependencies>
304+
<!-- overwrite dependency on spotbugs if you want to specify the version of spotbugs -->
305+
<dependency>
306+
<groupId>com.github.spotbugs</groupId>
307+
<artifactId>spotbugs</artifactId>
308+
<version>4.7.1</version>
309+
</dependency>
310+
</dependencies>
311+
<executions>
312+
<execution>
313+
<id>run-spotbugs</id>
314+
<phase>verify</phase>
315+
<goals>
316+
<goal>check</goal>
317+
</goals>
318+
</execution>
319+
</executions>
320+
</plugin>
321+
266322
</plugins>
267323
</build>
268324

spotbugs-exclusions.xml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<FindBugsFilter
3+
xmlns="https://github.com/spotbugs/filter/3.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
6+
7+
<!-- I'm reasonably confident that the singleton pattern isn't exposing internal representation -->
8+
<And>
9+
<Class name="dev.openfeature.javasdk.OpenFeatureAPI"/>
10+
<Bug pattern="MS_EXPOSE_REP"/>
11+
</And>
12+
<!-- similarly, client using the singleton doesn't seem bad -->
13+
<And>
14+
<Class name="dev.openfeature.javasdk.OpenFeatureClient"/>
15+
<Bug pattern="EI_EXPOSE_REP2"/>
16+
</And>
17+
18+
<!-- Test class that should be excluded -->
19+
<Match>
20+
<Class name="dev.openfeature.javasdk.DoSomethingProvider"/>
21+
</Match>
22+
<!-- All bugs in test classes, except for JUnit-specific bugs -->
23+
<Match>
24+
<Class name="~.*\.*Test" />
25+
<Not>
26+
<Bug code="IJU" />
27+
</Not>
28+
</Match>
29+
</FindBugsFilter>

src/lombok.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
lombok.addLombokGeneratedAnnotation = true
2-
2+
lombok.extern.findbugs.addSuppressFBWarnings = true

src/main/java/dev/openfeature/javasdk/EvaluationContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
1313
public class EvaluationContext {
1414
@Setter @Getter private String targetingKey;
15-
private final Map<String, dev.openfeature.javasdk.internal.Pair<FlagValueType, Object>> attributes;
15+
private final Map<String, Pair<FlagValueType, Object>> attributes;
1616

1717
public EvaluationContext() {
1818
this.targetingKey = "";

src/main/java/dev/openfeature/javasdk/Metadata.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
* Holds identifying information about a given entity
55
*/
66
public interface Metadata {
7-
public String getName();
7+
String getName();
88
}

src/main/java/dev/openfeature/javasdk/NoOpProvider.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,6 @@ public class NoOpProvider implements FeatureProvider {
99
public static final String PASSED_IN_DEFAULT = "Passed in default";
1010
@Getter
1111
private final String name = "No-op Provider";
12-
private EvaluationContext ctx;
13-
14-
public EvaluationContext getMergedContext() {
15-
return ctx;
16-
}
17-
1812
@Override
1913
public Metadata getMetadata() {
2014
return new Metadata() {
@@ -27,7 +21,6 @@ public String getName() {
2721

2822
@Override
2923
public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
30-
this.ctx = ctx;
3124
return ProviderEvaluation.<Boolean>builder()
3225
.value(defaultValue)
3326
.variant(PASSED_IN_DEFAULT)
@@ -37,7 +30,6 @@ public ProviderEvaluation<Boolean> getBooleanEvaluation(String key, Boolean defa
3730

3831
@Override
3932
public ProviderEvaluation<String> getStringEvaluation(String key, String defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
40-
this.ctx = ctx;
4133
return ProviderEvaluation.<String>builder()
4234
.value(defaultValue)
4335
.variant(PASSED_IN_DEFAULT)
@@ -47,7 +39,6 @@ public ProviderEvaluation<String> getStringEvaluation(String key, String default
4739

4840
@Override
4941
public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
50-
this.ctx = ctx;
5142
return ProviderEvaluation.<Integer>builder()
5243
.value(defaultValue)
5344
.variant(PASSED_IN_DEFAULT)
@@ -56,7 +47,6 @@ public ProviderEvaluation<Integer> getIntegerEvaluation(String key, Integer defa
5647
}
5748
@Override
5849
public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double defaultValue, EvaluationContext ctx, FlagEvaluationOptions options) {
59-
this.ctx = ctx;
6050
return ProviderEvaluation.<Double>builder()
6151
.value(defaultValue)
6252
.variant(PASSED_IN_DEFAULT)
@@ -65,7 +55,6 @@ public ProviderEvaluation<Double> getDoubleEvaluation(String key, Double default
6555
}
6656
@Override
6757
public <T> ProviderEvaluation<T> getObjectEvaluation(String key, T defaultValue, EvaluationContext invocationContext, FlagEvaluationOptions options) {
68-
this.ctx = ctx;
6958
return ProviderEvaluation.<T>builder()
7059
.value(defaultValue)
7160
.variant(PASSED_IN_DEFAULT)

src/main/java/dev/openfeature/javasdk/exceptions/FlagNotFoundError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
@StandardException
88
public class FlagNotFoundError extends OpenFeatureError {
9-
private static long serialVersionUID = 1L;
9+
private static final long serialVersionUID = 1L;
1010
@Getter private final ErrorCode errorCode = ErrorCode.GENERAL;
1111
}

src/main/java/dev/openfeature/javasdk/exceptions/GeneralError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66

77
@StandardException
88
public class GeneralError extends OpenFeatureError{
9-
private static long serialVersionUID = 1L;
9+
private static final long serialVersionUID = 1L;
1010
@Getter private final ErrorCode errorCode = ErrorCode.GENERAL;
1111
}

src/main/java/dev/openfeature/javasdk/exceptions/OpenFeatureError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
@StandardException
77
public abstract class OpenFeatureError extends RuntimeException {
8-
private static long serialVersionUID = 1L;
8+
private static final long serialVersionUID = 1L;
99
public abstract ErrorCode getErrorCode();
1010
}

src/main/java/dev/openfeature/javasdk/exceptions/ParseError.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@StandardException
88
public class ParseError extends OpenFeatureError {
9-
private static long serialVersionUID = 1L;
9+
private static final long serialVersionUID = 1L;
1010

1111
@Getter private final ErrorCode errorCode = ErrorCode.PARSE_ERROR;
1212

0 commit comments

Comments
 (0)