Merge branch 'master' into pmd/7.0.x

This commit is contained in:
Andreas Dangel
2022-06-24 16:00:03 +02:00
12 changed files with 412 additions and 172 deletions

View File

@ -6703,6 +6703,33 @@
"contributions": [
"doc"
]
},
{
"login": "lgemeinhardt",
"name": "lgemeinhardt",
"avatar_url": "https://avatars.githubusercontent.com/u/1395165?v=4",
"profile": "https://github.com/lgemeinhardt",
"contributions": [
"bug"
]
},
{
"login": "HaelC",
"name": "Haoliang Chen",
"avatar_url": "https://avatars.githubusercontent.com/u/16898273?v=4",
"profile": "https://haelchan.me/",
"contributions": [
"bug"
]
},
{
"login": "FSchliephacke",
"name": "FSchliephacke",
"avatar_url": "https://avatars.githubusercontent.com/u/10260493?v=4",
"profile": "https://github.com/FSchliephacke",
"contributions": [
"bug"
]
}
],
"contributorsPerLine": 7,

View File

@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar

File diff suppressed because it is too large Load Diff

View File

@ -23,9 +23,17 @@ This is a {{ site.pmd.release_type }} release.
* core
* [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list`
* [#4009](https://github.com/pmd/pmd/issues/4009): \[core] Cannot build PMD with Temurin 17
* java-bestpractices
* [#3824](https://github.com/pmd/pmd/issues/3824): \[java] UnusedPrivateField: Do not flag fields annotated with @<!-- -->Version
* [#3825](https://github.com/pmd/pmd/issues/3825): \[java] UnusedPrivateField: Do not flag fields annotated with @<!-- -->Id or @<!-- -->EmbeddedId
* java-design
* [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring)
* [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito)
* [#3823](https://github.com/pmd/pmd/issues/3823): \[java] ImmutableField: Do not flag fields in @<!-- -->Entity
* [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @<!-- -->Value (Spring)
* [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @<!-- -->Captor (Mockito)
* [#4004](https://github.com/pmd/pmd/issues/4004): \[java] ImmutableField reports fields annotated with @<!-- -->GwtMock (GwtMockito) and @<!-- -->Spy (Mockito)
* [#4008](https://github.com/pmd/pmd/issues/4008): \[java] ImmutableField not reporting fields that are only initialized in the declaration
* [#4011](https://github.com/pmd/pmd/issues/4011): \[java] ImmutableField: Do not flag fields annotated with @<!-- -->Inject
* [#4020](https://github.com/pmd/pmd/issues/4020): \[java] ImmutableField reports fields annotated with @<!-- -->FindBy and @<!-- -->FindBys (Selenium)
* java-errorprone
* [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class
* [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases
@ -35,7 +43,8 @@ This is a {{ site.pmd.release_type }} release.
### External Contributions
* [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota)
* [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007)
* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison)
* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @<!-- -->Value (Spring) or @<!-- -->Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison)
* [#4003](https://github.com/pmd/pmd/pull/4003): \[java] UnusedPrivateField - Ignore fields annotated with @<!-- -->Id/@<!-- -->EmbeddedId/@<!-- -->Version (JPA) or @<!-- -->Mock/@<!-- -->Spy/@<!-- -->MockBean (Mockito/Spring) - [@jjlharrison](https://github.com/jjlharrison)
* [#4006](https://github.com/pmd/pmd/pull/4006): \[doc] Fix eclipse plugin update site URL - [@shiomiyan](https://github.com/shiomiyan)
* [#4010](https://github.com/pmd/pmd/pull/4010): \[core] Bump kotlin to version 1.7.0 - [@maikelsteneker](https://github.com/maikelsteneker)

View File

@ -11,18 +11,18 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import org.apache.commons.io.FilenameUtils;
import org.junit.Before;
import org.junit.Test;
import net.sourceforge.pmd.lang.apex.ApexLanguageModule;
import net.sourceforge.pmd.util.IOUtil;
public class ApexCpdTest {
private File testdir;
@Before
public void setUp() {
String path = FilenameUtils.normalize("src/test/resources/net/sourceforge/pmd/cpd/issue427");
String path = IOUtil.normalizePath("src/test/resources/net/sourceforge/pmd/cpd/issue427");
testdir = new File(path);
}

View File

@ -15,12 +15,11 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import org.junit.Test;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.util.IOUtil;
public class ApexParserTest extends ApexParserTestBase {
@ -156,7 +155,7 @@ public class ApexParserTest extends ApexParserTestBase {
for (File file : fList) {
if (file.isFile() && file.getName().endsWith(".cls")) {
String sourceCode = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
String sourceCode = IOUtil.readFileToString(file, StandardCharsets.UTF_8);
Assert.assertNotNull(parse(sourceCode));
}
}
@ -168,7 +167,7 @@ public class ApexParserTest extends ApexParserTestBase {
*/
@Test
public void parseInheritedSharingClass() throws IOException {
String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("InheritedSharing.cls"),
String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("InheritedSharing.cls"),
StandardCharsets.UTF_8);
parse(source);
}
@ -180,7 +179,7 @@ public class ApexParserTest extends ApexParserTestBase {
*/
@Test
public void stackOverflowDuringClassParsing() throws Exception {
String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("StackOverflowClass.cls"),
String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("StackOverflowClass.cls"),
StandardCharsets.UTF_8);
ASTUserClassOrInterface<?> rootNode = parse(source);
@ -190,7 +189,7 @@ public class ApexParserTest extends ApexParserTestBase {
@Test
public void verifyLineColumnNumbersInnerClasses() throws Exception {
String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("InnerClassLocations.cls"),
String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("InnerClassLocations.cls"),
StandardCharsets.UTF_8);
source = source.replaceAll("\r\n", "\n");
ASTUserClassOrInterface<?> rootNode = parse(source);

View File

@ -37,7 +37,16 @@ public class UnusedPrivateFieldRule extends AbstractJavaRulechainRule {
"lombok.Getter",
"java.lang.Deprecated",
"lombok.experimental.Delegate",
"javafx.fxml.FXML"
"javafx.fxml.FXML",
"javax.persistence.Id",
"javax.persistence.EmbeddedId",
"javax.persistence.Version",
"jakarta.persistence.Id",
"jakarta.persistence.EmbeddedId",
"jakarta.persistence.Version",
"org.mockito.Mock",
"org.mockito.Spy",
"org.springframework.boot.test.mock.mockito.MockBean"
);
private static final PropertyDescriptor<List<String>> IGNORED_FIELD_NAMES =

View File

@ -9,9 +9,9 @@ import static org.junit.Assert.assertTrue;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import org.apache.commons.io.FileUtils;
import org.junit.AfterClass;
import org.junit.Rule;
import org.junit.Test;
@ -20,6 +20,7 @@ import org.junit.rules.ExternalResource;
import org.junit.rules.TestRule;
import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration;
import net.sourceforge.pmd.util.IOUtil;
public class PMDTaskTest extends AbstractAntTestHelper {
@ -142,7 +143,7 @@ public class PMDTaskTest extends AbstractAntTestHelper {
setDefaultCharset("cp1252");
executeTarget("testFormatterEncodingWithXML");
String report = FileUtils.readFileToString(currentTempFile(), "UTF-8");
String report = IOUtil.readFileToString(currentTempFile(), StandardCharsets.UTF_8);
assertTrue(report.contains("someVariableWithÜmlaut"));
}

View File

@ -14,7 +14,6 @@ import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Rule;
@ -27,6 +26,7 @@ import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.LanguageVersion;
import net.sourceforge.pmd.lang.java.JavaLanguageModule;
import net.sourceforge.pmd.util.IOUtil;
public class PMDCoverageTest {
@ -80,7 +80,7 @@ public class PMDCoverageTest {
System.err.println("Running PMD with: " + Arrays.toString(args));
PMD.runPmd(args);
report = FileUtils.readFileToString(f, StandardCharsets.UTF_8);
report = IOUtil.readFileToString(f, StandardCharsets.UTF_8);
assertEquals("Nothing should be output to stdout", 0, output.getLog().length());

View File

@ -687,6 +687,65 @@ public class Foo {
}
}
}
}
]]></code>
</test-code>
<test-code>
<description>#3824 #3825 Do not flag fields annotated with @Id, @EmbeddedId, or @Version</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;
@Entity
@Table(name = "my_table")
public class MyTable implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", nullable = false)
private long m_id;
@Version
@Column(name = "optimistic_lock", nullable = false)
private short m_optimisticLock;
public MyTable() {
// nothing to do
}
}
]]></code>
</test-code>
<test-code>
<description>Do not flag Mockito fields that are injected into test target</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import org.mockito.Spy;
import org.mockito.Mock;
import org.mockito.InjectMocks;
import org.springframework.boot.test.mock.mockito.MockBean;
public class MyTest {
@Mock
private Object mock;
@MockBean
private Object bean;
@Spy
private Object spy;
@InjectMocks
private Object target;
void test() {
target.methodToTest();
}
}
]]></code>
</test-code>

View File

@ -706,4 +706,108 @@ public class ExampleImmutableField {
}
]]></code>
</test-code>
<test-code>
<description>#4008 FN with field assigned only in initializer</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
private String variable = "hello";
public Goo() {
}
public String getVariable() {
return variable;
}
}
]]></code>
</test-code>
<test-code>
<description>#4008 FN with field assigned only in initializer (no ctor)</description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
private String variable = "hello";
public String getVariable() {
return variable;
}
}
]]></code>
</test-code>
<test-code>
<description>[java] ImmutableField: Do not flag fields annotated with @Inject #4011</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import javax.inject.Inject;
public class Foo {
@Inject
private MyService service;
}
interface MyService {}
]]></code>
</test-code>
<test-code>
<description>[java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) #4020</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class SomePage {
@org.openqa.selenium.support.FindBy(id = "id1")
private WebElement field1;
@org.openqa.selenium.support.FindBys(value = {@org.openqa.selenium.support.FindByFindBy(id = "id2"),
@org.openqa.selenium.support.FindBy(xpath = "//div/table")})
private WebElement table;
}
]]></code>
</test-code>
<test-code>
<description>[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) #4004</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class SomeTest {
@com.google.gwtmockito.GwtMock
private String someMock;
@org.mockito.Spy
private String someSpy;
}
]]></code>
</test-code>
<test-code>
<description>[java] ImmutableField: Do not flag fields in @Entity #3823</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Id;
import javax.persistence.Column;
@Entity
@Table(name = "my_table")
public class MyTable implements Serializable
{
private static final long serialVersionUID = 1L;
@Id
@Column(name = "directory", nullable = false)
private long m_id; // PMD Violation: ImmutableField
// other fields
/**
* For JPA
*/
public MyTable()
{
// nothing to do
}
public long getId()
{
return m_id;
}
}
]]></code>
</test-code>
</test-data>

29
pom.xml
View File

@ -901,6 +901,15 @@
<artifactId>kotest-runner-junit5-jvm</artifactId>
<version>${kotest.version}</version>
<scope>test</scope>
<exclusions>
<!-- exclude transitive dependency to fix CVE-2021-29425
kotest 4.4.3 depends on commons-io 2.6
-->
<exclusion>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.kotest</groupId>
@ -927,6 +936,26 @@
<version>13.0</version>
<scope>test</scope>
</dependency>
<!-- transitive dependency through io.kotest/kotest-runner-junit5-jvm@4.4.3
upgrade to 4.8.112 to fix [sonatype-2021-1074] CWE-611: Improper Restriction of XML External Entity Reference ('XXE')
https://github.com/classgraph/classgraph/releases/tag/classgraph-4.8.112
-->
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.112</version>
</dependency>
<!-- transitive dependency through org.scalameta:trees_2.13
upgrade to 3.16.1 to fix CVE-2021-22569 A potential Denial of Service issue in protobuf-java
https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-wrvw-hg22-4m67
-->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.16.1</version>
</dependency>
</dependencies>
</dependencyManagement>