Skip to content

Commit b328b00

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

File tree

7 files changed

+31
-31
lines changed

7 files changed

+31
-31
lines changed

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

Lines changed: 3 additions & 3 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,7 +60,7 @@ 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();
@@ -92,7 +92,7 @@ public Metadata getMetadata() {
9292

9393
@Override
9494
public List<Hook> getProviderHooks() {
95-
return this.hooks;
95+
return new ArrayList<>(this.hooks);
9696
}
9797

9898
@Override

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

Lines changed: 4 additions & 6 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
*
@@ -139,7 +138,6 @@ public GoFeatureFlagResponse evaluateFlag(final String key, final EvaluationCont
139138
}
140139
}
141140

142-
143141
/**
144142
* retrieveFlagConfiguration is calling the GO Feature Flag relay proxy to retrieve the flags'
145143
* configuration.
@@ -246,7 +244,8 @@ private FlagConfigResponse handleFlagConfigurationSuccess(final Response respons
246244
Date lastUpdated;
247245
try {
248246
val headerValue = response.header(Const.HTTP_HEADER_LAST_MODIFIED);
249-
lastUpdated = headerValue != null ? Const.LAST_MODIFIED_HEADER_FORMATTER.parse(headerValue) : null;
247+
val lastModifiedHeaderFormatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");
248+
lastUpdated = headerValue != null ? lastModifiedHeaderFormatter.parse(headerValue) : null;
250249
} catch (Exception e) {
251250
log.debug("Error parsing Last-Modified header: {}", e.getMessage());
252251
lastUpdated = null;
@@ -282,5 +281,4 @@ private <T> Request.Builder prepareHttpRequest(final HttpUrl url, final T reques
282281

283282
return reqBuilder;
284283
}
285-
286284
}

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

Lines changed: 1 addition & 1 deletion
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. */

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: 0 additions & 7 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();
3327
public static final ObjectMapper SERIALIZE_WASM_MAPPER = new ObjectMapper()
3428
.setSerializationInclusion(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL);
35-
3629
}

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import dev.openfeature.sdk.Reason;
1919
import java.io.File;
2020
import java.net.URL;
21+
import java.nio.charset.StandardCharsets;
2122
import java.nio.file.Files;
2223
import java.nio.file.Path;
2324
import java.nio.file.Paths;
@@ -28,7 +29,7 @@
2829
* EvaluationWasm is a class that represents the evaluation of a feature flag
2930
* it calls an external WASM module to evaluate the feature flag.
3031
*/
31-
public class EvaluationWasm {
32+
public final class EvaluationWasm {
3233
private final Instance instance;
3334
private final ExportFunction evaluate;
3435
private final ExportFunction malloc;
@@ -99,22 +100,20 @@ private HostFunction getProcExitFunc() {
99100
});
100101
}
101102

102-
103103
/**
104104
* preWarmWasm is a function that is called to pre-warm the WASM module
105105
* It calls the malloc function to allocate memory for the WASM module
106106
* and then calls the free function to free the memory.
107107
*/
108108
public void preWarmWasm() {
109-
val message = "".getBytes();
109+
val message = "".getBytes(StandardCharsets.UTF_8);
110110
Memory memory = this.instance.memory();
111111
int len = message.length;
112112
int ptr = (int) malloc.apply(len)[0];
113113
memory.write(ptr, message);
114114
this.free.apply(ptr, len);
115115
}
116116

117-
118117
/**
119118
* Evaluate is a function that evaluates the feature flag using the WASM module.
120119
*

providers/go-feature-flag/src/test/java/dev/openfeature/contrib/providers/gofeatureflag/GoFeatureFlagProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void shouldResolveAValidObjectFlagWithTargetingMatchReason() {
411411
val got = client.getObjectDetails("object_key",
412412
Value.objectToValue(new MutableStructure().add("default", "true")),
413413
TestUtils.defaultEvaluationContext);
414-
val want = FlagEvaluationDetails.<Object>builder()
414+
val want = FlagEvaluationDetails.builder()
415415
.value(Value.objectToValue(new MutableStructure().add("test", "false")))
416416
.variant("varB")
417417
.flagKey("object_key")

0 commit comments

Comments
 (0)