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

pmd / pmd / 682

22 Jul 2026 02:59PM UTC coverage: 79.215% (+0.02%) from 79.199%
682

push

github

web-flow
[apex] Fix #6478: Bump apex-parser from 5.0.0 to 5.1.0 (#6862)

* [apex] Fix #6478: Bump apex-parser from 5.0.0 to 5.1.0

* [apex] Bump Summit AST from 2.4.0 to 3.0.0

* [apex] Support Multiline String Literals

* [doc] Update release notes (#6478)

* Fix integration test

* [apex] fix: Support anonymous blocks

* Fix imports (checkstyle)

* [doc] Update release notes (#6887)

19348 of 25391 branches covered (76.2%)

Branch coverage included in aggregate %.

29 of 32 new or added lines in 6 files covered. (90.63%)

2 existing lines in 1 file now uncovered.

42021 of 52080 relevant lines covered (80.69%)

0.82 hits per line

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

76.47
/pmd-core/src/main/java/net/sourceforge/pmd/util/BaseResultProducingCloseable.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.util;
6

7
import java.io.Closeable;
8
import java.util.function.Consumer;
9

10
/**
11
 * Base class for a class that produces a result once it has
12
 * been closed. None of the methods of this class are synchronized.
13
 *
14
 * @param <T> Type of the result
15
 */
16
// TODO: PMD 8: remove implements AutoCloseable.
17
// Implementing AutoCloseable implies that the class is intended to be used with try-with-resources.
18
// A BaseResultProducingCloseable is supposed to produce a result AFTER it has been closed,
19
// which won't work inside a try-with-resources. At that point is has gone out of scope.
20
public abstract class BaseResultProducingCloseable<T> implements AutoCloseable {
1✔
21

22
    private boolean closed;
23

24
    protected final void ensureOpen() {
UNCOV
25
        AssertionUtil.validateState(!closed, "Listener has been closed");
×
UNCOV
26
    }
×
27

28
    /**
29
     * Returns the result.
30
     *
31
     * @throws IllegalStateException If this instance has not been closed yet
32
     */
33
    public final T getResult() {
34
        AssertionUtil.validateState(closed, "Cannot get result before listener is closed");
1✔
35

36
        return getResultImpl();
1✔
37
    }
38

39
    /** Produce the final result. */
40
    protected abstract T getResultImpl();
41

42
    /**
43
     * Close this object. Idempotent.
44
     *
45
     * @implNote Override {@link #closeImpl()} instead.
46
     */
47
    @Override
48
    public final void close() {
49
        if (!closed) {
1✔
50
            closed = true;
1✔
51
            closeImpl();
1✔
52
        }
53
    }
1✔
54

55
    /**
56
     * Close this closeable as per the contract of {@link Closeable#close()}.
57
     * Called exactly once.
58
     * @implSpec This implementation is empty.
59
     */
60
    protected void closeImpl() {
61
        // override
62
    }
1✔
63

64
    public static <U, C extends BaseResultProducingCloseable<U>> U using(C closeable, Consumer<? super C> it) {
65
        try {
66
            it.accept(closeable);
1✔
67
        } finally {
68
            closeable.close();
1✔
69
        }
70
        return closeable.getResult();
1✔
71
    }
72
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc