Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] UseVarargs: do not flag public static void main(String[]), ignore @Override #79

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pmd-java/src/main/resources/rulesets/java/design.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1845,6 +1845,15 @@ having to deal with the creation of an array.
[not (./Type/ReferenceType[@Array='true'][PrimitiveType[@Image='byte']])]
[not (./Type/ReferenceType[ClassOrInterfaceType[@Image='Byte']])]
[not (./Type/PrimitiveType[@Image='byte'])]
[not (ancestor::MethodDeclaration/preceding-sibling::Annotation/*/Name[@Image='Override'])]
[not(
ancestor::MethodDeclaration
[@Public='true' and @Static='true']
[child::ResultType[@Void='true']] and
ancestor::MethodDeclarator[@Image='main'] and
..[@ParameterCount='1'] and
./Type/ReferenceType[ClassOrInterfaceType[@Image='String']]
)]
]]></value>
</property>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@ method, do not varargs, allow Byte[] as not varargs
public class Foo {
public void bar(File file, Byte[] data) { }
public void bar2(File file, Byte data[]) { }
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
method, do not varargs, allow @Override
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
@Override
protected void bar(String[] args) { }
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
method, do not varargs, allow public static void main(String[]) as not varargs
]]></description>
<expected-problems>0</expected-problems>
<code><![CDATA[
public class Foo {
public static void main(String[] args) { }
}
]]></code>
</test-code>
<test-code>
<description><![CDATA[
method, use varargs, deviation from exact main signature flagged
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
public static void main(int i, String[] args) { }
}
]]></code>
</test-code>
Expand Down