Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 73688b8

Browse files
committedNov 19, 2024·
refactor: deprecate ManagedDependentResourceContext#put
The javadoc declares it returns Optional and the implementation returns Optional, but the method declares it returns T. put is replaced by putOrRemove with a consistent signature. Signed-off-by: Robert Young <[email protected]>
1 parent d492ff6 commit 73688b8

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed
 

Diff for: ‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/DefaultManagedDependentResourceContext.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ public <T> Optional<T> get(Object key, Class<T> expectedType) {
2121

2222
@Override
2323
@SuppressWarnings("unchecked")
24+
@Deprecated(forRemoval = true)
2425
public <T> T put(Object key, T value) {
25-
if (value == null) {
26-
return (T) Optional.ofNullable(attributes.remove(key));
27-
}
28-
return (T) Optional.ofNullable(attributes.put(key, value));
26+
return (T) putOrRemove(key, value);
2927
}
3028

3129
@Override

Diff for: ‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/managed/ManagedDependentResourceContext.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ public interface ManagedDependentResourceContext {
3636
* associated with the specified key
3737
* @return an Optional containing the previous value associated with the key or
3838
* {@link Optional#empty()} if none existed
39+
* @deprecated use {@link #putOrRemove(Object, Object)} instead
3940
*/
4041
@SuppressWarnings("unchecked")
42+
@Deprecated(forRemoval = true)
4143
<T> T put(Object key, T value);
4244

4345
/**
@@ -52,7 +54,6 @@ public interface ManagedDependentResourceContext {
5254
* @return an Optional containing the previous value associated with the key or
5355
* {@link Optional#empty()} if none existed
5456
*/
55-
@SuppressWarnings("unchecked")
5657
<T> Optional<T> putOrRemove(Object key, T value);
5758

5859
/**

Diff for: ‎operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/workflow/DefaultWorkflow.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public WorkflowReconcileResult reconcile(P primary, Context<P> context) {
9393
new WorkflowReconcileExecutor<>(this, primary, context);
9494
var result = workflowReconcileExecutor.reconcile();
9595
context.managedDependentResourceContext()
96-
.put(DefaultManagedDependentResourceContext.RECONCILE_RESULT_KEY, result);
96+
.putOrRemove(DefaultManagedDependentResourceContext.RECONCILE_RESULT_KEY, result);
9797
if (throwExceptionAutomatically) {
9898
result.throwAggregateExceptionIfErrorsPresent();
9999
}
@@ -106,7 +106,7 @@ public WorkflowCleanupResult cleanup(P primary, Context<P> context) {
106106
new WorkflowCleanupExecutor<>(this, primary, context);
107107
var result = workflowCleanupExecutor.cleanup();
108108
context.managedDependentResourceContext()
109-
.put(DefaultManagedDependentResourceContext.CLEANUP_RESULT_KEY, result);
109+
.putOrRemove(DefaultManagedDependentResourceContext.CLEANUP_RESULT_KEY, result);
110110
if (throwExceptionAutomatically) {
111111
result.throwAggregateExceptionIfErrorsPresent();
112112
}

0 commit comments

Comments
 (0)
Please sign in to comment.