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

pmd / pmd / 827

25 Sep 2026 07:43AM UTC coverage: 79.731% (+0.005%) from 79.726%
827

push

github

web-flow
[doc] Update release notes for 7.28.0 (#7106)

* [html] Fix typos
* [doc] Release notes: Add missing issues
* [doc] Release notes: Update issue titles
* [doc] Release notes: Reformat kotlin xpath
* [java] TypeNameMismatchRule: Add @since javadoc tag
* Update quickstart rulesets with new rules
* [doc] Release notes: Improve wording, consistency

20252 of 26446 branches covered (76.58%)

Branch coverage included in aggregate %.

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

61 existing lines in 2 files now uncovered.

43589 of 53624 relevant lines covered (81.29%)

0.82 hits per line

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

92.06
/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/internal/JavaLanguageProcessor.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.internal;
6

7
import java.nio.file.Path;
8
import java.util.ArrayList;
9
import java.util.List;
10
import java.util.Objects;
11

12
import org.checkerframework.checker.nullness.qual.NonNull;
13
import org.slf4j.Logger;
14
import org.slf4j.LoggerFactory;
15

16
import net.sourceforge.pmd.lang.JvmLanguagePropertyBundle;
17
import net.sourceforge.pmd.lang.LanguageVersionHandler;
18
import net.sourceforge.pmd.lang.ast.Parser;
19
import net.sourceforge.pmd.lang.impl.BatchLanguageProcessor;
20
import net.sourceforge.pmd.lang.java.ast.JavaParser;
21
import net.sourceforge.pmd.lang.java.internal.JavaLanguageProperties.InferenceLoggingVerbosity;
22
import net.sourceforge.pmd.lang.java.rule.xpath.internal.BaseContextNodeTestFun;
23
import net.sourceforge.pmd.lang.java.rule.xpath.internal.GetCommentOnFunction;
24
import net.sourceforge.pmd.lang.java.rule.xpath.internal.GetModifiersFun;
25
import net.sourceforge.pmd.lang.java.rule.xpath.internal.MatchesSignatureFunction;
26
import net.sourceforge.pmd.lang.java.rule.xpath.internal.MetricFunction;
27
import net.sourceforge.pmd.lang.java.rule.xpath.internal.NodeIsFunction;
28
import net.sourceforge.pmd.lang.java.types.TypeSystem;
29
import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger;
30
import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger.SimpleLogger;
31
import net.sourceforge.pmd.lang.java.types.internal.infer.TypeInferenceLogger.VerboseLogger;
32
import net.sourceforge.pmd.lang.metrics.LanguageMetricsProvider;
33
import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler;
34
import net.sourceforge.pmd.reporting.ViolationDecorator;
35
import net.sourceforge.pmd.reporting.ViolationSuppressor;
36
import net.sourceforge.pmd.util.AuxClasspathLoader;
37
import net.sourceforge.pmd.util.designerbindings.DesignerBindings;
38
import net.sourceforge.pmd.util.internal.AuxClasspathUtil;
39
import net.sourceforge.pmd.util.log.internal.LogUtil;
40

41
/**
42
 * @author Clément Fournier
43
 */
44
public class JavaLanguageProcessor extends BatchLanguageProcessor<JavaLanguageProperties>
45
    implements LanguageVersionHandler {
46

47
    private static final Logger LOG = LoggerFactory.getLogger(JavaLanguageProcessor.class);
1✔
48

49
    private final LanguageMetricsProvider myMetricsProvider = new JavaMetricsProvider();
1✔
50
    private final JavaParser parser;
51
    private final JavaParser parserWithoutProcessing;
52
    private final boolean firstClassLombok;
53
    private TypeSystem typeSystem;
54
    private AuxClasspathLoader auxClasspathLoader;
55

56
    public JavaLanguageProcessor(JavaLanguageProperties properties) {
57
        super(properties);
1✔
58

59
        initTypeSystem(properties);
1✔
60

61
        String suppressMarker = properties.getSuppressMarker();
1✔
62
        this.parser = new JavaParser(suppressMarker, this, true);
1✔
63
        this.parserWithoutProcessing = new JavaParser(suppressMarker, this, false);
1✔
64
        this.firstClassLombok = properties.getProperty(JavaLanguageProperties.FIRST_CLASS_LOMBOK);
1✔
65
    }
1✔
66

67
    private void initTypeSystem(JavaLanguageProperties properties) {
68
        ClassLoader externallyConfiguredClassLoader = properties.getExternalClassLoader();
1✔
69
        if (externallyConfiguredClassLoader != null) {
1✔
70
            LOG.debug("Using externally configured classloader as analysis classloader: {}", externallyConfiguredClassLoader);
1✔
71
            this.typeSystem = TypeSystem.usingClassLoaderClasspath(externallyConfiguredClassLoader);
1✔
72
        } else {
73
            String rawAuxClasspath = properties.getProperty(JvmLanguagePropertyBundle.AUX_CLASSPATH);
1✔
74
            List<Path> auxClasspath = new ArrayList<>(AuxClasspathUtil.expandClasspath(rawAuxClasspath));
1✔
75

76
            Boolean disableWarnings = properties.getProperty(JavaLanguageProperties.DISABLE_AUX_CLASSPATH_WARNINGS);
1✔
77
            LogUtil.WarnOrDebugLogger warnOrDebugLogger = LogUtil.createWarnOrDebugLogger(!disableWarnings,
1✔
78
                    "Set env var PMD_JAVA_DISABLE_AUX_CLASSPATH_WARNINGS=true to disable this warning.");
79
            if (!AuxClasspathUtil.containsPlatformClasspath(auxClasspath)) {
1✔
80
                Path platformClasspath = AuxClasspathUtil.getPlatformClasspath();
1✔
81

82
                warnOrDebugLogger.log(LOG, "Adding current platform {} to auxClasspath, which could be the wrong java version. "
1✔
83
                                + "Please add the correct jrt-fs.jar explicitly to the auxClasspath. "
84
                                + "See https://docs.pmd-code.org/latest/pmd_languages_java.html#providing-the-auxiliary-classpath",
85
                        platformClasspath);
86
                auxClasspath.add(platformClasspath);
1✔
87
            }
88
            String expandedAuxClasspath = AuxClasspathUtil.toRawClasspath(auxClasspath);
1✔
89
            LOG.debug("Using auxClasspath as analysis classloader: {}", expandedAuxClasspath);
1✔
90
            this.auxClasspathLoader = AuxClasspathLoader.create(expandedAuxClasspath, warnOrDebugLogger);
1✔
91
            this.typeSystem = TypeSystem.usingClasspath(name -> auxClasspathLoader.findResource(name));
1✔
92
        }
93
    }
1✔
94

95
    @Override
96
    public @NonNull LanguageVersionHandler services() {
97
        return this;
1✔
98
    }
99

100
    @Override
101
    public Parser getParser() {
102
        return parser;
1✔
103
    }
104

105
    public JavaParser getParserWithoutProcessing() {
106
        return parserWithoutProcessing;
1✔
107
    }
108

109
    public TypeSystem getTypeSystem() {
110
        return typeSystem;
1✔
111
    }
112

113
    public boolean hasFirstClassLombokSupport() {
114
        return firstClassLombok;
1✔
115
    }
116

117
    TypeInferenceLogger newTypeInfLogger() {
118
        InferenceLoggingVerbosity verbosity = getProperties().getProperty(JavaLanguageProperties.INTERNAL_INFERENCE_LOGGING_VERBOSITY);
1✔
119
        if (verbosity == InferenceLoggingVerbosity.VERBOSE) {
1!
UNCOV
120
            return new VerboseLogger(System.err);
×
121
        } else if (verbosity == InferenceLoggingVerbosity.SIMPLE) {
1!
UNCOV
122
            return new SimpleLogger(System.err);
×
123
        } else {
124
            return TypeInferenceLogger.noop();
1✔
125
        }
126
    }
127

128
    @Override
129
    public DesignerBindings getDesignerBindings() {
UNCOV
130
        return JavaDesignerBindings.INSTANCE;
×
131
    }
132

133
    @Override
134
    public XPathHandler getXPathHandler() {
135
        return XPATH_HANDLER;
1✔
136
    }
137

138
    @Override
139
    public List<ViolationSuppressor> getExtraViolationSuppressors() {
140
        return JavaAnnotationSuppressor.ALL_JAVA_SUPPRESSORS;
1✔
141
    }
142

143
    @Override
144
    public ViolationDecorator getViolationDecorator() {
145
        return JavaViolationDecorator.INSTANCE;
1✔
146
    }
147

148
    @Override
149
    public LanguageMetricsProvider getLanguageMetricsProvider() {
150
        return myMetricsProvider;
1✔
151
    }
152

153
    private static final XPathHandler XPATH_HANDLER =
1✔
154
        XPathHandler.getHandlerForFunctionDefs(
1✔
155
            BaseContextNodeTestFun.TYPE_IS_EXACTLY,
156
            BaseContextNodeTestFun.TYPE_IS,
157
            BaseContextNodeTestFun.HAS_ANNOTATION,
158
            MatchesSignatureFunction.INSTANCE,
159
            NodeIsFunction.INSTANCE,
160
            GetModifiersFun.GET_EFFECTIVE,
161
            GetModifiersFun.GET_EXPLICIT,
162
            MetricFunction.INSTANCE,
163
            GetCommentOnFunction.INSTANCE
164
        );
165

166
    public void setTypeSystem(TypeSystem ts) {
167
        this.typeSystem = Objects.requireNonNull(ts);
1✔
168
    }
1✔
169

170
    @Override
171
    public void close() throws Exception {
172
        this.typeSystem.logStats();
1✔
173
        if (this.auxClasspathLoader != null) {
1✔
174
            this.auxClasspathLoader.close();
1✔
175
        }
176
        super.close();
1✔
177
    }
1✔
178
}
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