Skip to content

Commit e7d1385

Browse files
Fix some linting issues
Signed-off-by: Thomas Poignant <[email protected]>
1 parent 19f8d21 commit e7d1385

File tree

19 files changed

+333
-405
lines changed

19 files changed

+333
-405
lines changed

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/GoFeatureFlagProvider.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* GoFeatureFlagProvider is the JAVA provider implementation for the feature flag solution GO Feature Flag.
3939
*/
4040
@Slf4j
41-
public class GoFeatureFlagProvider extends EventProvider implements Tracking {
41+
public final class GoFeatureFlagProvider extends EventProvider implements Tracking {
4242
/** Options to configure the provider. */
4343
private final GoFeatureFlagProviderOptions options;
4444
/** Service to evaluate the flags. */
@@ -60,15 +60,14 @@ public class GoFeatureFlagProvider extends EventProvider implements Tracking {
6060
* @param options - options to configure the provider
6161
* @throws InvalidOptions - if options are invalid
6262
*/
63-
public GoFeatureFlagProvider(GoFeatureFlagProviderOptions options) throws InvalidOptions {
63+
public GoFeatureFlagProvider(final GoFeatureFlagProviderOptions options) throws InvalidOptions {
6464
Validator.providerOptions(options);
6565
this.options = options;
6666
this.api = GoFeatureFlagApi.builder().options(options).build();
6767
this.evalService = new EvaluationService(getEvaluator(this.api));
6868

69-
long flushIntervalMs = (options.getFlushIntervalMs() == null)
70-
? Const.DEFAULT_FLUSH_INTERVAL_MS
71-
: options.getFlushIntervalMs();
69+
long flushIntervalMs =
70+
(options.getFlushIntervalMs() == null) ? Const.DEFAULT_FLUSH_INTERVAL_MS : options.getFlushIntervalMs();
7271
int maxPendingEvents = (options.getMaxPendingEvents() == null)
7372
? Const.DEFAULT_MAX_PENDING_EVENTS
7473
: options.getMaxPendingEvents();
@@ -92,7 +91,7 @@ public Metadata getMetadata() {
9291

9392
@Override
9493
public List<Hook> getProviderHooks() {
95-
return this.hooks;
94+
return new ArrayList<>(this.hooks);
9695
}
9796

9897
@Override
@@ -132,8 +131,7 @@ public void initialize(EvaluationContext evaluationContext) throws Exception {
132131
this.hooks.add(new EnrichEvaluationContextHook(this.options.getExporterMetadata()));
133132
// In case of remote evaluation, we don't need to send the data to the collector
134133
// because the relay-proxy will collect events directly server side.
135-
if (!this.options.isDisableDataCollection()
136-
&& this.options.getEvaluationType() != EvaluationType.REMOTE) {
134+
if (!this.options.isDisableDataCollection() && this.options.getEvaluationType() != EvaluationType.REMOTE) {
137135
this.dataCollectorHook = new DataCollectorHook(DataCollectorHookOptions.builder()
138136
.eventsPublisher(this.eventsPublisher)
139137
.collectUnCachedEvaluation(true)

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/api/GoFeatureFlagApi.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import dev.openfeature.sdk.exceptions.OpenFeatureError;
2727
import java.io.IOException;
2828
import java.net.HttpURLConnection;
29+
import java.text.SimpleDateFormat;
2930
import java.util.Collections;
3031
import java.util.Date;
3132
import java.util.List;
@@ -46,7 +47,7 @@
4647
* GoFeatureFlagApi is the class to contact the GO Feature Flag relay proxy.
4748
*/
4849
@Slf4j
49-
public class GoFeatureFlagApi {
50+
public final class GoFeatureFlagApi {
5051
/** apiKey contains the token to use while calling GO Feature Flag relay proxy. */
5152
private final String apiKey;
5253

@@ -56,7 +57,6 @@ public class GoFeatureFlagApi {
5657
/** parsedEndpoint is the endpoint of the GO Feature Flag relay proxy. */
5758
private final HttpUrl parsedEndpoint;
5859

59-
6060
/**
6161
* GoFeatureFlagController is the constructor of the controller to contact the GO Feature Flag
6262
* relay proxy.
@@ -92,7 +92,6 @@ private GoFeatureFlagApi(final GoFeatureFlagProviderOptions options) throws Inva
9292
.build();
9393
}
9494

95-
9695
/**
9796
* evaluateFlag is calling the GO Feature Flag relay proxy to evaluate the feature flag.
9897
*
@@ -113,7 +112,9 @@ public GoFeatureFlagResponse evaluateFlag(final String key, final EvaluationCont
113112
.addEncodedPathSegment(key)
114113
.build();
115114

116-
val requestBody = OfrepRequest.builder().context(evaluationContext.asObjectMap()).build();
115+
val requestBody = OfrepRequest.builder()
116+
.context(evaluationContext.asObjectMap())
117+
.build();
117118
val reqBuilder = prepareHttpRequest(url, requestBody);
118119
try (Response response = this.httpClient.newCall(reqBuilder.build()).execute()) {
119120
val responseBody = response.body();
@@ -139,7 +140,6 @@ public GoFeatureFlagResponse evaluateFlag(final String key, final EvaluationCont
139140
}
140141
}
141142

142-
143143
/**
144144
* retrieveFlagConfiguration is calling the GO Feature Flag relay proxy to retrieve the flags'
145145
* configuration.
@@ -182,12 +182,10 @@ public FlagConfigResponse retrieveFlagConfiguration(final String etag, final Lis
182182
"retrieve flag configuration error: unexpected http code " + body);
183183
}
184184
} catch (final IOException e) {
185-
throw new ImpossibleToRetrieveConfiguration(
186-
"retrieve flag configuration error", e);
185+
throw new ImpossibleToRetrieveConfiguration("retrieve flag configuration error", e);
187186
}
188187
} catch (final JsonProcessingException e) {
189-
throw new ImpossibleToRetrieveConfiguration(
190-
"retrieve flag configuration error", e);
188+
throw new ImpossibleToRetrieveConfiguration("retrieve flag configuration error", e);
191189
}
192190
}
193191

@@ -225,8 +223,7 @@ public void sendEventToDataCollector(final List<IEvent> eventsList, final Map<St
225223
}
226224
}
227225
} catch (final IOException e) {
228-
throw new ImpossibleToSendEventsException(
229-
"Error while sending data for relay-proxy exporter", e);
226+
throw new ImpossibleToSendEventsException("Error while sending data for relay-proxy exporter", e);
230227
}
231228
}
232229

@@ -246,7 +243,8 @@ private FlagConfigResponse handleFlagConfigurationSuccess(final Response respons
246243
Date lastUpdated;
247244
try {
248245
val headerValue = response.header(Const.HTTP_HEADER_LAST_MODIFIED);
249-
lastUpdated = headerValue != null ? Const.LAST_MODIFIED_HEADER_FORMATTER.parse(headerValue) : null;
246+
val lastModifiedHeaderFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
247+
lastUpdated = headerValue != null ? lastModifiedHeaderFormatter.parse(headerValue) : null;
250248
} catch (Exception e) {
251249
log.debug("Error parsing Last-Modified header: {}", e.getMessage());
252250
lastUpdated = null;
@@ -282,5 +280,4 @@ private <T> Request.Builder prepareHttpRequest(final HttpUrl url, final T reques
282280

283281
return reqBuilder;
284282
}
285-
286283
}

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/api/bean/FlagConfigApiResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ public class FlagConfigApiResponse {
1919
FlagConfigApiResponse() {
2020
// Default constructor
2121
}
22-
2322
}

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/api/bean/OfrepResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ public GoFeatureFlagResponse toGoFeatureFlagResponse() {
5050
}
5151
return goff;
5252
}
53-
5453
}

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/bean/IEvent.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
/**
44
* Interface for all events that are sent to the GO Feature Flag server.
55
*/
6-
public interface IEvent {
7-
}
6+
public interface IEvent {}

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/evaluator/InProcessEvaluator.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ public class InProcessEvaluator implements IEvaluator {
6060
* @param options - options to configure the provider
6161
* @param emitProviderConfigurationChanged - method to call when we have a configuration change
6262
*/
63-
public InProcessEvaluator(GoFeatureFlagApi api, GoFeatureFlagProviderOptions options,
63+
public InProcessEvaluator(
64+
GoFeatureFlagApi api,
65+
GoFeatureFlagProviderOptions options,
6466
Consumer<ProviderEventDetails> emitProviderConfigurationChanged) {
6567
this.api = api;
6668
this.flags = Collections.emptyMap();
@@ -101,8 +103,7 @@ public boolean isFlagTrackable(final String flagKey) {
101103

102104
@Override
103105
public void init() {
104-
val configFlags = api.retrieveFlagConfiguration(
105-
this.etag, options.getEvaluationFlagList());
106+
val configFlags = api.retrieveFlagConfiguration(this.etag, options.getEvaluationFlagList());
106107
this.flags = configFlags.getFlags();
107108
this.etag = configFlags.getEtag();
108109
this.lastUpdate = configFlags.getLastUpdated();
@@ -126,12 +127,10 @@ public void destroy() {
126127
*
127128
* @return Disposable - the subscription to the observable
128129
*/
129-
@NotNull
130-
private Disposable startCheckFlagConfigurationChangesDaemon() {
131-
long pollingIntervalMs =
132-
options.getFlagChangePollingIntervalMs() != null
133-
? options.getFlagChangePollingIntervalMs()
134-
: Const.DEFAULT_POLLING_CONFIG_FLAG_CHANGE_INTERVAL_MS;
130+
@NotNull private Disposable startCheckFlagConfigurationChangesDaemon() {
131+
long pollingIntervalMs = options.getFlagChangePollingIntervalMs() != null
132+
? options.getFlagChangePollingIntervalMs()
133+
: Const.DEFAULT_POLLING_CONFIG_FLAG_CHANGE_INTERVAL_MS;
135134

136135
PublishSubject<Object> stopSignal = PublishSubject.create();
137136
Observable<Long> intervalObservable = Observable.interval(pollingIntervalMs, TimeUnit.MILLISECONDS);
@@ -170,8 +169,8 @@ private Disposable startCheckFlagConfigurationChangesDaemon() {
170169
.build();
171170
this.emitProviderConfigurationChanged.accept(changeDetails);
172171
},
173-
throwable -> log.error("error while calling flag configuration API, error: {}",
174-
throwable.getMessage()));
172+
throwable ->
173+
log.error("error while calling flag configuration API, error: {}", throwable.getMessage()));
175174
}
176175

177176
/**
@@ -181,8 +180,8 @@ private Disposable startCheckFlagConfigurationChangesDaemon() {
181180
* @param newFlags - list of new flags
182181
* @return - list of flags that have changed
183182
*/
184-
private List<String> findFlagConfigurationChanges(final Map<String, Flag> originalFlags,
185-
final Map<String, Flag> newFlags) {
183+
private List<String> findFlagConfigurationChanges(
184+
final Map<String, Flag> originalFlags, final Map<String, Flag> newFlags) {
186185
// this function should return a list of flags that have changed between the two maps
187186
// it should contain all updated, added and removed flags
188187
List<String> changedFlags = new ArrayList<>();
@@ -207,5 +206,4 @@ private List<String> findFlagConfigurationChanges(final Map<String, Flag> origin
207206

208207
return changedFlags;
209208
}
210-
211209
}

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/evaluator/RemoteEvaluator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public RemoteEvaluator(GoFeatureFlagApi api) {
2323
this.api = api;
2424
}
2525

26-
2726
@Override
2827
public GoFeatureFlagResponse evaluate(String key, Object defaultValue, EvaluationContext evaluationContext) {
2928
return this.api.evaluateFlag(key, evaluationContext);

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/hook/DataCollectorHook.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* Flag.
2020
*/
2121
@Slf4j
22-
public class DataCollectorHook implements Hook<HookContext<String>> {
22+
public final class DataCollectorHook implements Hook<HookContext<String>> {
2323
/** options contains all the options of this hook. */
2424
private final DataCollectorHookOptions options;
2525
/** eventsPublisher is the system collecting all the information to send to GO Feature Flag. */
@@ -40,12 +40,11 @@ public DataCollectorHook(final DataCollectorHookOptions options) throws InvalidO
4040
this.options = options;
4141
}
4242

43-
4443
@Override
4544
public void after(HookContext ctx, FlagEvaluationDetails details, Map hints) {
4645
if (!this.evalService.isFlagTrackable(ctx.getFlagKey())
4746
|| (!Boolean.TRUE.equals(this.options.getCollectUnCachedEvaluation())
48-
&& !Reason.CACHED.name().equals(details.getReason()))) {
47+
&& !Reason.CACHED.name().equals(details.getReason()))) {
4948
return;
5049
}
5150

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/service/EvaluationService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ public <T> ProviderEvaluation<T> getEvaluation(
8080
T flagValue = convertValue(goffResp.getValue(), expectedType);
8181

8282
if (flagValue.getClass() != expectedType) {
83-
throw new TypeMismatchError(
84-
String.format("Flag value %s had unexpected type %s, expected %s.", flagKey, flagValue.getClass(),
85-
expectedType));
83+
throw new TypeMismatchError(String.format(
84+
"Flag value %s had unexpected type %s, expected %s.", flagKey, flagValue.getClass(), expectedType));
8685
}
8786

8887
return ProviderEvaluation.<T>builder()

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/service/EventsPublisher.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.concurrent.locks.ReentrantReadWriteLock;
1616
import java.util.function.Consumer;
1717
import lombok.extern.slf4j.Slf4j;
18-
import lombok.val;
1918

2019
/**
2120
* Events publisher.
@@ -24,7 +23,7 @@
2423
* @author Liran Mendelovich
2524
*/
2625
@Slf4j
27-
public class EventsPublisher<T> {
26+
public final class EventsPublisher<T> {
2827
public final AtomicBoolean isShutdown = new AtomicBoolean(false);
2928
private final int maxPendingEvents;
3029
private final Consumer<List<T>> publisher;
@@ -34,7 +33,7 @@ public class EventsPublisher<T> {
3433
private final Lock writeLock = readWriteLock.writeLock();
3534

3635
private final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(1);
37-
private List<T> eventsList;
36+
private final List<T> eventsList;
3837

3938
/**
4039
* Constructor.
@@ -64,17 +63,28 @@ public void add(T event) {
6463
log.error("This object was shut down. Omitting event.");
6564
return;
6665
}
67-
readLock.lock();
68-
val shouldPublish = (eventsList != null) && (eventsList.size() >= maxPendingEvents);
69-
readLock.unlock();
66+
67+
var shouldPublish = false;
68+
try {
69+
readLock.lock();
70+
shouldPublish = (eventsList != null) && (eventsList.size() >= maxPendingEvents);
71+
} finally {
72+
readLock.unlock();
73+
}
7074

7175
if (shouldPublish) {
7276
log.warn("events collection is full. Publishing before adding new events.");
7377
publish();
7478
}
75-
writeLock.lock();
76-
eventsList.add(event);
77-
writeLock.unlock();
79+
80+
try {
81+
writeLock.lock();
82+
if (eventsList != null) {
83+
eventsList.add(event);
84+
}
85+
} finally {
86+
writeLock.unlock();
87+
}
7888
}
7989

8090
/**

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/util/Const.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.fasterxml.jackson.databind.DeserializationFeature;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5-
import java.text.DateFormat;
6-
import java.text.SimpleDateFormat;
75
import java.time.Duration;
86

97
/**
@@ -18,19 +16,14 @@ public class Const {
1816
public static final String HTTP_HEADER_ETAG = "ETag";
1917
public static final String HTTP_HEADER_IF_NONE_MATCH = "If-None-Match";
2018
public static final String HTTP_HEADER_LAST_MODIFIED = "Last-Modified";
21-
public static final DateFormat LAST_MODIFIED_HEADER_FORMATTER =
22-
new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
23-
2419
// DEFAULT VALUES
2520
public static final long DEFAULT_POLLING_CONFIG_FLAG_CHANGE_INTERVAL_MS = 2L * 60L * 1000L;
2621
public static final long DEFAULT_FLUSH_INTERVAL_MS = Duration.ofMinutes(1).toMillis();
2722
public static final int DEFAULT_MAX_PENDING_EVENTS = 10000;
28-
2923
// MAPPERS
3024
public static final ObjectMapper DESERIALIZE_OBJECT_MAPPER =
3125
new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
3226
public static final ObjectMapper SERIALIZE_OBJECT_MAPPER = new ObjectMapper();
33-
public static final ObjectMapper SERIALIZE_WASM_MAPPER = new ObjectMapper()
34-
.setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL);
35-
27+
public static final ObjectMapper SERIALIZE_WASM_MAPPER =
28+
new ObjectMapper().setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL);
3629
}

providers/go-feature-flag/src/main/java/dev/openfeature/contrib/providers/gofeatureflag/validator/Validator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ public static void providerOptions(GoFeatureFlagProviderOptions options) throws
3131
if (options.getExporterMetadata() != null) {
3232
val acceptableExporterMetadataTypes = List.of("String", "Boolean", "Integer", "Double");
3333
for (Map.Entry<String, Object> entry : options.getExporterMetadata().entrySet()) {
34-
if (!acceptableExporterMetadataTypes.contains(entry.getValue().getClass().getSimpleName())) {
34+
if (!acceptableExporterMetadataTypes.contains(
35+
entry.getValue().getClass().getSimpleName())) {
3536
throw new InvalidExporterMetadata(
3637
"exporterMetadata can only contain String, Boolean, Integer or Double");
3738
}

0 commit comments

Comments
 (0)