Skip to content

Commit 5d39923

Browse files
committed
[core] Don't log warning about skipLexicalErrors twice (#5102)
Merge pull request #5102 from adangel:issue-5091-skipLexicalErrors
2 parents a3f9d4a + 9bf476a commit 5d39923

8 files changed

Lines changed: 20 additions & 16 deletions

File tree

docs/pages/release_notes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ This is a {{ site.pmd.release_type }} release.
5252
* [#5088](https://github.com/pmd/pmd/pull/5088): \[plsql] Add support for 'DEFAULT' clause on the arguments of some oracle functions
5353
* cli
5454
* [#5120](https://github.com/pmd/pmd/issues/5120): \[cli] Can't start designer under Windows
55+
* core
56+
* [#5091](https://github.com/pmd/pmd/issues/5091): \[core] PMD CPD v7.3.0 gives deprecation warning for skipLexicalErrors even when not used
5557

5658
### 🚨 API Changes
5759

pmd-ant/src/main/java/net/sourceforge/pmd/ant/CPDTask.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ public void execute() throws BuildException {
111111
+ "Use failOnError=\"false\" to not fail the build.", Project.MSG_WARN);
112112
}
113113

114-
// implicitly enable skipLexicalErrors, so that we can fail the build at the end. A report is created in any case.
115-
config.setSkipLexicalErrors(true);
116-
117114
config.setIgnoreAnnotations(ignoreAnnotations);
118115
config.setIgnoreLiterals(ignoreLiterals);
119116
config.setIgnoreIdentifiers(ignoreIdentifiers);

pmd-cli/src/main/java/net/sourceforge/pmd/cli/commands/internal/CpdCommand.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ protected CPDConfiguration toConfiguration() {
124124
configuration.setRendererName(rendererName);
125125
configuration.setSkipBlocksPattern(skipBlocksPattern);
126126
configuration.setSkipDuplicates(skipDuplicates);
127-
configuration.setSkipLexicalErrors(skipLexicalErrors);
128127
configuration.setSourceEncoding(encoding.getEncoding());
129128
configuration.setInputUri(uri);
130129

@@ -133,9 +132,6 @@ protected CPDConfiguration toConfiguration() {
133132
configuration.setFailOnError(false);
134133
}
135134

136-
// implicitly enable skipLexicalErrors, so that we can fail the build at the end. A report is created in any case.
137-
configuration.setSkipLexicalErrors(true);
138-
139135
return configuration;
140136
}
141137

pmd-cli/src/test/java/net/sourceforge/pmd/cli/BaseCliTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
package net.sourceforge.pmd.cli;
66

77
import static org.hamcrest.MatcherAssert.assertThat;
8-
import static org.hamcrest.Matchers.equalTo;
8+
import static org.hamcrest.Matchers.emptyString;
99
import static org.junit.jupiter.api.Assertions.assertEquals;
1010

1111
import java.io.ByteArrayOutputStream;
@@ -146,7 +146,7 @@ public void checkFailed() {
146146
}
147147

148148
public void checkNoErrorOutput() {
149-
checkStdErr(equalTo(""));
149+
checkStdErr(emptyString());
150150
}
151151

152152
public void checkStdOut(Matcher<? super String> matcher) {

pmd-cli/src/test/java/net/sourceforge/pmd/cli/CpdCliTest.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,24 @@ void testSkipLexicalErrors() throws Exception {
239239
"--skip-lexical-errors")
240240
.verify(r -> {
241241
r.checkStdErr(containsPattern("Skipping file: Lexical error in file .*?BadFile\\.java"));
242+
r.checkStdErr(containsString("--skip-lexical-errors is deprecated. Use --no-fail-on-error instead."));
242243
r.checkStdOut(containsString("Found a 5 line (13 tokens) duplication"));
243244
});
244245
}
245246

247+
/**
248+
* @see <a href="https://github.com/pmd/pmd/issues/5091">[core] PMD CPD v7.3.0 gives deprecation warning for skipLexicalErrors even when not used #5091</a>
249+
* @throws Exception
250+
*/
251+
@Test
252+
void noWarningsWithoutSkipLexicalErrors() throws Exception {
253+
runCliSuccessfully("--minimum-tokens", "340", "--language", "java", "--dir", SRC_DIR, "--format", "text")
254+
.verify(r -> {
255+
r.checkNoErrorOutput();
256+
r.checkStdOut(emptyString());
257+
});
258+
}
259+
246260
@Test
247261
void testExitCodeWithLexicalErrors() throws Exception {
248262
runCli(RECOVERED_ERRORS_OR_VIOLATIONS,

pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public class CPDConfiguration extends AbstractConfiguration {
6767
private boolean ignoreIdentifierAndLiteralSequences = false;
6868

6969
@Deprecated
70-
private boolean skipLexicalErrors = false;
70+
// Note: The default value was false until up to 7.3.0 and is true since 7.4.0
71+
private boolean skipLexicalErrors = true;
7172

7273
private boolean noSkipBlocks = false;
7374

pmd-core/src/main/java/net/sourceforge/pmd/cpd/CpdAnalysis.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ public void performAnalysis() {
153153

154154
@SuppressWarnings("PMD.CloseResource")
155155
public void performAnalysis(Consumer<CPDReport> consumer) {
156-
if (configuration.isSkipLexicalErrors()) {
157-
LOGGER.warn("The option skipLexicalErrors is deprecated. Use failOnError instead.");
158-
}
159-
160156
try (SourceManager sourceManager = new SourceManager(files.getCollectedFiles())) {
161157
Map<Language, CpdLexer> tokenizers =
162158
sourceManager.getTextFiles().stream()

pmd-core/src/test/java/net/sourceforge/pmd/cpd/CpdAnalysisTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ void reportShouldContainProcessingErrors() throws IOException {
223223
PmdReporter reporter = mock(PmdReporter.class);
224224
config.setReporter(reporter);
225225

226-
config.setSkipLexicalErrors(true); // must be true, otherwise CPD is aborted with first processing error
227226
try (CpdAnalysis cpd = CpdAnalysis.create(config)) {
228227
assertTrue(cpd.files().addSourceFile(FileId.fromPathLikeString("foo.dummy"), DummyLanguageModule.CPD_THROW_LEX_EXCEPTION));
229228
assertTrue(cpd.files().addSourceFile(FileId.fromPathLikeString("foo2.dummy"), DummyLanguageModule.CPD_THROW_MALFORMED_SOURCE_EXCEPTION));
@@ -252,7 +251,6 @@ void testSkipLexicalErrors() throws IOException {
252251
PmdReporter reporter = mock(PmdReporter.class);
253252
config.setReporter(reporter);
254253

255-
config.setSkipLexicalErrors(true);
256254
try (CpdAnalysis cpd = CpdAnalysis.create(config)) {
257255
assertTrue(cpd.files().addSourceFile(FileId.fromPathLikeString("foo.dummy"), DummyLanguageModule.CPD_THROW_LEX_EXCEPTION));
258256
assertTrue(cpd.files().addSourceFile(FileId.fromPathLikeString("foo2.dummy"), DummyLanguageModule.CPD_THROW_MALFORMED_SOURCE_EXCEPTION));

0 commit comments

Comments
 (0)