Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[automation] Allow returning null from supplier function in ValueCache #4427

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public ValueCacheImpl(String scriptIdentifier) {
}

@Override
public Object get(String key, Supplier<Object> supplier) {
return Objects.requireNonNull(cache.computeIfAbsent(key, k -> supplier.get()));
public @Nullable Object get(String key, Supplier<Object> supplier) {
return cache.computeIfAbsent(key, k -> supplier.get());
}

private Collection<Object> values() {
Expand Down Expand Up @@ -231,11 +231,11 @@ public TrackingValueCacheImpl(String scriptIdentifier) {
}

@Override
public Object get(String key, Supplier<Object> supplier) {
public @Nullable Object get(String key, Supplier<Object> supplier) {
cacheLock.lock();
try {
rememberAccessToKey(key);
Object value = Objects.requireNonNull(sharedCache.computeIfAbsent(key, k -> supplier.get()));
Object value = sharedCache.computeIfAbsent(key, k -> supplier.get());

logger.trace("GET with supplier to cache from '{}': '{}' -> '{}'", scriptIdentifier, key, value);
return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ public interface ValueCache {
* Get a value from the cache or create a new key-value-pair from the given supplier
*
* @param key the key of the requested value
* @param supplier a supplier that returns a non-null value to be used if the key was not present
* @param supplier a supplier that returns a value to be used if the key was not present
* @return the value associated with the key
*/
@Nullable
Object get(String key, Supplier<Object> supplier);
}