• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ben-manes / caffeine / #5612

11 Jul 2026 03:47PM UTC coverage: 71.292% (-28.7%) from 100.0%
#5612

push

github

ben-manes
Preserve timestamps on a raced same-instance refresh

The automatic refreshIfNeeded path checked for an equal-value reload
before the ABA/ownership check and returned without preserving the
timestamps, so a reload completing after a concurrent put(k,
sameInstance) did a full update — shifting the entry's expiration
forward by the reload's in-flight duration and stomping the write.
Mirror the explicit-refresh fix: check ownership first. An owned
reload installs the value (refreshing metadata even for a same
instance), while a raced reload preserves the write's timestamps and
only notifies REPLACED when the value differs.

2957 of 4134 branches covered (71.53%)

3 of 3 new or added lines in 1 file covered. (100.0%)

2408 existing lines in 53 files now uncovered.

5980 of 8388 relevant lines covered (71.29%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jcache/src/main/java/com/github/benmanes/caffeine/jcache/processor/EntryProcessorEntry.java
1
/*
2
 * Copyright 2015 Ben Manes. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package com.github.benmanes.caffeine.jcache.processor;
17

18
import static java.util.Objects.requireNonNull;
19

20
import java.util.Optional;
21

22
import javax.cache.integration.CacheLoader;
23
import javax.cache.processor.EntryProcessor;
24
import javax.cache.processor.MutableEntry;
25

26
import org.jspecify.annotations.Nullable;
27

28
/**
29
 * An entry that is consumed by an {@link EntryProcessor}. The updates to the entry are replayed
30
 * on the cache when the processor completes.
31
 *
32
 * @author ben.manes@gmail.com (Ben Manes)
33
 */
34
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
35
public final class EntryProcessorEntry<K, V> implements MutableEntry<K, V> {
36
  private final boolean hasEntry;
37
  private final K key;
38

39
  private Action action;
40
  private @Nullable V value;
41
  private Optional<CacheLoader<K, V>> cacheLoader;
42

UNCOV
43
  public EntryProcessorEntry(K key, @Nullable V value, Optional<CacheLoader<K, V>> cacheLoader) {
×
UNCOV
44
    this.hasEntry = (value != null);
×
UNCOV
45
    this.cacheLoader = cacheLoader;
×
UNCOV
46
    this.action = Action.NONE;
×
UNCOV
47
    this.value = value;
×
UNCOV
48
    this.key = key;
×
UNCOV
49
  }
×
50

51
  @Override
52
  public boolean exists() {
UNCOV
53
    return (action == Action.NONE) ? hasEntry : (value != null);
×
54
  }
55

56
  @Override
57
  public K getKey() {
UNCOV
58
    return key;
×
59
  }
60

61
  @Override
62
  @SuppressWarnings("ConstantValue")
63
  public @Nullable V getValue() {
UNCOV
64
    if (action != Action.NONE) {
×
UNCOV
65
      return value;
×
UNCOV
66
    } else if (value != null) {
×
UNCOV
67
      action = Action.READ;
×
UNCOV
68
    } else if (cacheLoader.isPresent()) {
×
UNCOV
69
      value = cacheLoader.orElseThrow().load(key);
×
UNCOV
70
      cacheLoader = Optional.empty();
×
UNCOV
71
      if (value != null) {
×
UNCOV
72
        action = Action.LOADED;
×
73
      }
74
    }
UNCOV
75
    return value;
×
76
  }
77

78
  @Override
79
  public void remove() {
UNCOV
80
    action = (action == Action.CREATED) ? Action.NONE : Action.DELETED;
×
UNCOV
81
    if (value != null) {
×
UNCOV
82
      value = null;
×
83
    }
UNCOV
84
  }
×
85

86
  @Override
87
  public void setValue(V value) {
UNCOV
88
    requireNonNull(value);
×
UNCOV
89
    if (action != Action.CREATED) {
×
UNCOV
90
      action = hasEntry ? Action.UPDATED : Action.CREATED;
×
91
    }
UNCOV
92
    this.value = value;
×
UNCOV
93
  }
×
94

95
  /** Returns the dominant action performed by the processor on the entry. */
96
  public Action getAction() {
UNCOV
97
    return action;
×
98
  }
99

100
  @Override
101
  public <T> T unwrap(Class<T> clazz) {
UNCOV
102
    if (!clazz.isInstance(this)) {
×
UNCOV
103
      throw new IllegalArgumentException("Class " + clazz + " is unknown to this implementation");
×
104
    }
105
    @SuppressWarnings("unchecked")
UNCOV
106
    var castedEntry = (T) this;
×
UNCOV
107
    return castedEntry;
×
108
  }
109

110
  @Override
111
  public String toString() {
UNCOV
112
    return key + "=" + value;
×
113
  }
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc