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

ben-manes / caffeine / #5173

29 Dec 2025 05:27AM UTC coverage: 0.0% (-100.0%) from 100.0%
#5173

push

github

ben-manes
speed up development ci build

0 of 3838 branches covered (0.0%)

0 of 7869 relevant lines covered (0.0%)

0.0 hits per line

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

0.0
/caffeine/src/main/java/com/github/benmanes/caffeine/cache/stats/GuardedStatsCounter.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.cache.stats;
17

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

20
import java.lang.System.Logger;
21
import java.lang.System.Logger.Level;
22

23
import com.github.benmanes.caffeine.cache.RemovalCause;
24

25
/**
26
 * A {@link StatsCounter} implementation that suppresses and logs any exception thrown by the
27
 * delegate <code>statsCounter</code>.
28
 *
29
 * @author ben.manes@gmail.com (Ben Manes)
30
 */
31
final class GuardedStatsCounter implements StatsCounter {
32
  static final Logger logger = System.getLogger(GuardedStatsCounter.class.getName());
×
33

34
  final StatsCounter delegate;
35

36
  GuardedStatsCounter(StatsCounter delegate) {
×
37
    this.delegate = requireNonNull(delegate);
×
38
  }
×
39

40
  @Override
41
  public void recordHits(int count) {
42
    try {
43
      delegate.recordHits(count);
×
44
    } catch (Throwable t) {
×
45
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
46
    }
×
47
  }
×
48

49
  @Override
50
  public void recordMisses(int count) {
51
    try {
52
      delegate.recordMisses(count);
×
53
    } catch (Throwable t) {
×
54
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
55
    }
×
56
  }
×
57

58
  @Override
59
  public void recordLoadSuccess(long loadTime) {
60
    try {
61
      delegate.recordLoadSuccess(loadTime);
×
62
    } catch (Throwable t) {
×
63
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
64
    }
×
65
  }
×
66

67
  @Override
68
  public void recordLoadFailure(long loadTime) {
69
    try {
70
      delegate.recordLoadFailure(loadTime);
×
71
    } catch (Throwable t) {
×
72
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
73
    }
×
74
  }
×
75

76
  @Override
77
  public void recordEviction(int weight, RemovalCause cause) {
78
    requireNonNull(cause);
×
79
    try {
80
      delegate.recordEviction(weight, cause);
×
81
    } catch (Throwable t) {
×
82
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
83
    }
×
84
  }
×
85

86
  @Override
87
  public CacheStats snapshot() {
88
    try {
89
      return delegate.snapshot();
×
90
    } catch (Throwable t) {
×
91
      logger.log(Level.WARNING, "Exception thrown by stats counter", t);
×
92
      return CacheStats.empty();
×
93
    }
94
  }
95

96
  @Override
97
  public String toString() {
98
    return delegate.toString();
×
99
  }
100
}
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