[infinispan-issues] [JBoss JIRA] (ISPN-11249) Unexpected functionality added by Java8 default interface methods
Will Burns (Jira)
issues at jboss.org
Wed Feb 19 09:37:00 EST 2020
[ https://issues.redhat.com/browse/ISPN-11249?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13976480#comment-13976480 ]
Will Burns commented on ISPN-11249:
-----------------------------------
For now I will just add in UnsupportedOperationException, however compute is more than doable with an override of the following:
```
@Override
public V compute(K key, BiFunction<? super K, ? super V, ? extends V> remappingFunction, long lifespan, TimeUnit lifespanUnit, long maxIdleTime, TimeUnit maxIdleTimeUnit) {
V newValue;
while (true) {
MetadataValue<V> metadataValue = getWithMetadata(key);
V oldValue;
long version;
if (metadataValue != null) {
oldValue = metadataValue.getValue();
version = metadataValue.getVersion();
} else {
oldValue = null;
version = -1;
}
newValue = remappingFunction.apply(key, oldValue);
boolean done;
if (newValue != null) {
if (oldValue != null) {
done = replaceWithVersion(key, newValue, version, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit);
} else {
done = putIfAbsent(key, newValue, lifespan, lifespanUnit, maxIdleTime, maxIdleTimeUnit) != null;
}
} else {
done = removeWithVersion(key, version);
}
if (done) {
break;
}
}
return newValue;
}
```
> Unexpected functionality added by Java8 default interface methods
> -----------------------------------------------------------------
>
> Key: ISPN-11249
> URL: https://issues.redhat.com/browse/ISPN-11249
> Project: Infinispan
> Issue Type: Bug
> Reporter: Wolf-Dieter Fink
> Priority: Critical
>
> With Java8 there are interfaces which implement default methods.
> Those defaults are available if not overridden, but the function behind might not be correct because the method was not meant to be implemented.
> There are issues with the transaction and locking because of the remote invocation, so the conditional operation will not work consistent.
> Such methods need to be checked and throw a UnsupportedOperation.
> This appears for the compute(...) methods
> compute(key, BiFunct) -> default to java.util.concurrent.ConcurrentMap interface
> compute() methods with expiration will throw an UnsupportedOperationException as expected.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)
More information about the infinispan-issues
mailing list