Skip to content

Commit cc73673

Browse files
aepfliclaude
andcommitted
refactor: Complete POJO immutability cleanup and remove unnecessary exception handling
## EvaluationEvent Immutability - Remove public constructors - use builder() instead - Remove public setters (setName, setAttributes) - objects are now immutable - Make fields final for thread safety - Add comprehensive Javadoc with proper formatting - Maintain same builder pattern API for seamless migration ## InMemoryProvider Cleanup - Remove unnecessary try-catch block in getObjectEvaluation method - The getEvaluation method only throws OpenFeatureError (runtime exceptions) - Eliminates redundant exception wrapping that added no value ## Results - All 319 tests passing ✅ - Zero checkstyle violations - Complete POJO immutability across entire codebase - Cleaner exception handling in providers This completes the immutability refactor - all POJOs now follow consistent builder-only patterns with no public constructors or setters. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 026395f commit cc73673

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

openfeature-api/src/main/java/dev/openfeature/api/EvaluationEvent.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,39 @@
66

77
/**
88
* Represents an evaluation event.
9+
* This class is immutable and thread-safe.
910
*/
1011
public class EvaluationEvent {
1112

12-
private String name;
13-
private Map<String, Object> attributes;
13+
private final String name;
14+
private final Map<String, Object> attributes;
1415

15-
public EvaluationEvent() {
16-
this.attributes = new HashMap<>();
17-
}
18-
19-
public EvaluationEvent(String name, Map<String, Object> attributes) {
16+
/**
17+
* Private constructor - use builder() to create instances.
18+
*/
19+
private EvaluationEvent(String name, Map<String, Object> attributes) {
2020
this.name = name;
2121
this.attributes = attributes != null ? new HashMap<>(attributes) : new HashMap<>();
2222
}
2323

24+
/**
25+
* Gets the name of the evaluation event.
26+
*
27+
* @return the event name
28+
*/
2429
public String getName() {
2530
return name;
2631
}
2732

28-
public void setName(String name) {
29-
this.name = name;
30-
}
31-
33+
/**
34+
* Gets a copy of the event attributes.
35+
*
36+
* @return a new map containing the event attributes
37+
*/
3238
public Map<String, Object> getAttributes() {
3339
return new HashMap<>(attributes);
3440
}
3541

36-
public void setAttributes(Map<String, Object> attributes) {
37-
this.attributes = attributes != null ? new HashMap<>(attributes) : new HashMap<>();
38-
}
39-
4042
public static Builder builder() {
4143
return new Builder();
4244
}

openfeature-sdk/src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,7 @@ public ProviderEvaluation<Double> getDoubleEvaluation(
124124
@Override
125125
public ProviderEvaluation<Value> getObjectEvaluation(
126126
String key, Value defaultValue, EvaluationContext evaluationContext) {
127-
try {
128-
return getEvaluation(key, evaluationContext, Value.class);
129-
} catch (OpenFeatureError e) {
130-
throw e;
131-
} catch (Exception e) {
132-
throw new RuntimeException(e);
133-
}
127+
return getEvaluation(key, evaluationContext, Value.class);
134128
}
135129

136130
private <T> ProviderEvaluation<T> getEvaluation(

0 commit comments

Comments
 (0)