Fix handling of varargs
This commit is contained in:
2 files changed
+22
-2
No files matched your search
+3
@@ -1047,6 +1047,9 @@ public final class ConstructorCallsOverridableMethodRule extends AbstractJavaRul
|
||||
JavaTypeDefinition typeDefinition = type.getTypeDefinition();
|
||||
if (typeDefinition != null) {
|
||||
typeDefinition = typeDefinition.withDimensions(varId.getArrayDepth());
|
||||
if (p.isVarargs()) {
|
||||
typeDefinition = typeDefinition.withDimensions(1);
|
||||
}
|
||||
parameterTypes.add(typeDefinition.getType().getName());
|
||||
} else {
|
||||
parameterTypes.add("ref");
|
||||
|
||||
+19
-2
@@ -322,9 +322,12 @@ import java.lang.annotation.*;
|
||||
</test-code>
|
||||
<test-code>
|
||||
<description>[java] ConstructorCallsOverridableMethod should consider method calls with var access #4099</description>
|
||||
<expected-problems>7</expected-problems>
|
||||
<expected-linenumbers>4,11,18,25,32,39,46</expected-linenumbers>
|
||||
<expected-problems>9</expected-problems>
|
||||
<expected-linenumbers>7,14,21,28,35,42,49,56,63</expected-linenumbers>
|
||||
<code><![CDATA[
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
class Foo1 {
|
||||
final boolean tag = true;
|
||||
public Foo1() {
|
||||
@@ -374,6 +377,20 @@ class Foo7 {
|
||||
}
|
||||
public void bar(String s[]) {} // note, the different array notation!
|
||||
}
|
||||
|
||||
class Foo8 {
|
||||
public Foo8(String[] arg) {
|
||||
bar(arg); // should report a warning at this line
|
||||
}
|
||||
public void bar(String... s) {} // vararg
|
||||
}
|
||||
|
||||
class Foo9<E> {
|
||||
public Foo9(Set<E> arg) {
|
||||
bar(arg); // should report a warning at this line
|
||||
}
|
||||
public void bar(Collection<E> s) {} // base type
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
<test-code>
|
||||
|
||||
Reference in new issue
Block a user