Skip to content

CacheEntryEvent.getValue and getOldValue #391

@vbekiaris

Description

@vbekiaris

Observations from Joe Fialli on CacheEntryEvent following the resolution of #362 :

Here is the change that I noticed inconsistencies in.

public abstract class CacheEntryEvent<K, V> extends EventObject
    implements Cache.Entry<K, V>
<deleted>
/**
 * Returns the value stored in the cache when this entry was created.
 * <p>
 * The value will be available
 * for {@link CacheEntryCreatedListener}, {@link CacheEntryExpiredListener}
 * and {@link CacheEntryRemovedListener}
 * if {@link CacheEntryListenerConfiguration#isOldValueRequired()} is true.
 *
 * @return the value corresponding to this entry
 */
public abstract V getValue();

Comments on current changes:

  1. Since getValue method is overriding a method defined in Cache.Entry, an @Override annotation is missing.

  2. getValue() is defined for {@link CacheEntryUpdateListener}, but that is not listed. Is the intent that getValue() always has a value for all CacheEntryUpdateListener, but its value being set for all other Listeners is based on CacheEntryListenerConfiguration#isOldValueRequired() being true?

    (2a). If answer to 2 is yes, I definitely agree that previous value for entry is not returned in CacheEntryExpiredListener and CacheEntryRemovedListener when isOldValueRequired is false. However, getValue() should always return entry's current value for CacheEntryCreatedListener regardless of CacheEntryListenerConfiguration.isOldValueRequired()

  3. Current solution contradicts terminology for an existing Cache API remove method
    /**

    • Atomically removes the mapping for a key only if currently mapped to the
    • given value.
      ....
    • @param key key whose mapping is to be removed from the cache
    • @param oldValue value expected to be associated with the specified key
      */
      boolean javax.cache.Cache.remove(K key, V oldValue).

    In this existing method, the documentation refers to the value as oldValue (when it should for all intents be just "value"). This is a condition for the operation to occur. So the above parameter definitely should be "value" just as in a "Removed" or "Expired" Listener, the value should be considered the previous or "oldValue" prior to the entry no longer being associated with the cache.

  4. The undocumented exception UnsupportedOperationExceotion that is thrown by the RI but not documented in spec or javadoc. This issue was raised in issue and not addressed before it was closed.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions