Merge branch 'master' into pmd/7.0.x

This commit is contained in:
Andreas Dangel
2022-05-26 15:52:20 +02:00
6 changed files with 169 additions and 92 deletions

View File

@ -6675,6 +6675,15 @@
"contributions": [
"code"
]
},
{
"login": "filipponova",
"name": "Filippo Nova",
"avatar_url": "https://avatars.githubusercontent.com/u/12506636?v=4",
"profile": "https://github.com/filipponova",
"contributions": [
"bug"
]
}
],
"contributorsPerLine": 7,

File diff suppressed because it is too large Load Diff

View File

@ -41,10 +41,10 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details.
### Fixed Issues
* core
* [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425)
* cli
* [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters
* core
* [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425)
* cs (c#)
* [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations)
* go
@ -57,6 +57,9 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details.
* [#3954](https://github.com/pmd/pmd/issues/3954): \[java] NPE in UseCollectionIsEmptyRule when .size() is called in a record
* java-design
* [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito)
* java-performance
* [#3379](https://github.com/pmd/pmd/issues/3379): \[java] UseArraysAsList must ignore primitive arrays
* [#3965](https://github.com/pmd/pmd/issues/3965): \[java] UseArraysAsList false positive with non-trivial loops
* javascript
* [#2605](https://github.com/pmd/pmd/issues/2605): \[js] Support unicode characters
* [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal

View File

@ -697,12 +697,12 @@ public class Test {
public void foo(Integer[] ints) {
// could just use Arrays.asList(ints)
List<Integer> l = new ArrayList<>(100);
for (int i = 0; i < 100; i++) {
for (int i = 0; i < ints.length; i++) {
l.add(ints[i]);
}
List<Integer> anotherList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
for (int i = 0; i < ints.length; i++) {
anotherList.add(ints[i].toString()); // won't trigger the rule
}
}

View File

@ -14,9 +14,9 @@ import java.util.List;
public class Bar {
void foo() {
Integer[] ints = new Integer(10);
List l = new ArrayList(10);
for (int i = 0; i < 100; i++) {
Integer[] ints = new Integer[10];
List l = new ArrayList(ints.length);
for (int i = 0; i < ints.length; i++) {
l.add(ints[i]);
}
}
@ -114,11 +114,13 @@ public class Test {
public void foo(Integer[] ints) {
// could just use Arrays.asList(ints)
List l = new ArrayList(10);
for (int i = 0; i < 100; i++) {
for (int i = 0; i < ints.length; i++) {
l.add(ints[i]);
}
for (int i = 0; i < 100; i++) {
l.add(a[i].toString()); // won't trigger the rule
List l2 = new ArrayList(10);
for (int i = 0; i < ints.length; i++) {
l2.add(ints[i].toString()); // won't trigger the rule
}
}
}
@ -179,15 +181,77 @@ public class Test {
public void foo(Integer[] ints) {
// could just use Arrays.asList(ints)
List<Integer> l = new ArrayList<>(100);
for (int i = 0; i < 100; i++) {
for (int i = 0; i < ints.length; i++) {
l.add(ints[i]); // line 9, here is the violation
}
List<Integer> anotherList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
for (int i = 0; i < ints.length; i++) {
anotherList.add(ints[i].toString()); // line 13 - false positive
}
}
}
]]></code>
</test-code>
<test-code>
<description>[java] UseArraysAsList false positive with non-trivial loops #3965</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Test {
public void foo(Integer[] ints) {
List<Integer> l = new ArrayList<>(100);
for (int i = 0; i < 100; i++) {
switch (lookup(ints[i])) {
case 1: l.add(ints[i]); break; // line 10 - false positive
case 2: l.addAll(getInts(i)); break;
}
}
List<Integer> anotherList = new ArrayList<>();
for (int i : ints) {
switch (lookup(i)) {
case 1: anotherList.add(i); break; // line 18 - false positive
case 2: anotherList.addAll(getInts(i)); break;
}
}
}
int lookup(int a) {
return a;
}
List<Integer> getInts(int a) {
return Arrays.asList(a);
}
}
]]></code>
</test-code>
<test-code>
<description>[java] UseArraysAsList must ignore primitive arrays #3379</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
import java.util.ArrayList;
import java.util.List;
class Test {
public void convert(Object value) {
short[] array = (short[]) value;
List<Short> arrayList = new ArrayList<>(array.length);
for (short v : array) {
arrayList.add(v); // line 9 - false positive
}
List<Short> arrayList2 = new ArrayList<>(array.length);
for (int i = 0; i < array.length; i++) {
arrayList2.add(array[i]); // line 14 - false positive
}
}
}
]]></code>
</test-code>
</test-data>

View File

@ -85,8 +85,8 @@
<kotlin.compiler.jvmTarget>${maven.compiler.test.target}</kotlin.compiler.jvmTarget>
<kotlin.version>1.4.10</kotlin.version>
<kotest.version>4.3.1</kotest.version>
<kotlin.version>1.4.32</kotlin.version>
<kotest.version>4.4.3</kotest.version>
<dokka.version>1.4.32</dokka.version>