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

pmd / pmd / #3722

pending completion
#3722

push

github actions

adangel
Suppress MissingOverride for Chars::isEmpty (#4291)

67270 of 127658 relevant lines covered (52.7%)

0.53 hits per line

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

78.05
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/ParseLock.java
1
/*
2
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3
 */
4

5
package net.sourceforge.pmd.lang.java.symbols.internal.asm;
6

7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9

10
/**
11
 * A simple double-checked initializer, that parses something (a class,
12
 * or a type signature).
13
 */
14
@SuppressWarnings({"PMD.AvoidUsingVolatile", "PMD.AvoidCatchingThrowable"})
1✔
15
abstract class ParseLock {
1✔
16

17
    private static final Logger LOG = LoggerFactory.getLogger(ParseLock.class);
1✔
18

19
    private volatile ParseStatus status = ParseStatus.NOT_PARSED;
1✔
20

21
    public void ensureParsed() {
22
        getFinalStatus();
1✔
23
    }
1✔
24

25
    private ParseStatus getFinalStatus() {
26
        ParseStatus status = this.status;
1✔
27
        if (!status.isFinished) {
1✔
28
            synchronized (this) {
1✔
29
                status = this.status;
1✔
30
                if (status == ParseStatus.NOT_PARSED) {
1✔
31
                    this.status = ParseStatus.BEING_PARSED;
1✔
32
                    try {
33
                        boolean success = doParse();
1✔
34
                        status = success ? ParseStatus.FULL : ParseStatus.FAILED;
1✔
35
                        this.status = status;
1✔
36
                        finishParse(!success);
1✔
37
                    } catch (Throwable t) {
×
38
                        status = ParseStatus.FAILED;
×
39
                        this.status = status;
×
40
                        LOG.error(t.toString(), t);
×
41
                        finishParse(true);
×
42
                    }
1✔
43
                    assert status.isFinished : "Inconsistent status " + status;
1✔
44
                    assert postCondition() : "Post condition not satisfied after parsing sig " + this;
1✔
45
                } else if (status == ParseStatus.BEING_PARSED && !canReenter()) {
1✔
46
                    throw new IllegalStateException("Thread is reentering the parse lock");
×
47
                }
48
            }
1✔
49
        }
50
        return status;
1✔
51
    }
52

53
    protected boolean canReenter() {
54
        return false;
×
55
    }
56

57
    public boolean isFailed() {
58
        return getFinalStatus() == ParseStatus.FAILED;
1✔
59
    }
60

61
    // will be called in the critical section after parse is done
62
    protected void finishParse(boolean failed) {
63
        // by default do nothing
64
    }
1✔
65

66
    /** Returns true if parse is successful. */
67
    protected abstract boolean doParse() throws Throwable; // SUPPRESS CHECKSTYLE IllegalThrows
68

69
    /** Checked by an assert after parse. */
70
    protected boolean postCondition() {
71
        return true;
×
72
    }
73

74
    @Override
75
    public String toString() {
76
        return "ParseLock{status=" + status + '}';
×
77
    }
78

79
    private enum ParseStatus {
1✔
80
        NOT_PARSED(false),
1✔
81
        BEING_PARSED(false),
1✔
82
        FULL(true),
1✔
83
        FAILED(true);
1✔
84

85
        final boolean isFinished;
86

87
        ParseStatus(boolean finished) {
1✔
88
            this.isFinished = finished;
1✔
89
        }
1✔
90
    }
91
}
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