From f67dbb85f66716188061c1b5fca7c62f7b7c619b Mon Sep 17 00:00:00 2001 From: Matt Benson Date: Mon, 14 Dec 2015 15:22:28 -0600 Subject: [PATCH 1/2] do not flag public static void main(String[]) as UseVarargs; ignore @Override for UseVarargs --- .../main/resources/rulesets/java/design.xml | 9 +++++ .../lang/java/rule/design/xml/UseVarargs.xml | 34 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/pmd-java/src/main/resources/rulesets/java/design.xml b/pmd-java/src/main/resources/rulesets/java/design.xml index 76f312421b..3ca0d6c755 100644 --- a/pmd-java/src/main/resources/rulesets/java/design.xml +++ b/pmd-java/src/main/resources/rulesets/java/design.xml @@ -1775,6 +1775,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']] + )] ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseVarargs.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseVarargs.xml index 169b9cdd37..4e0ee4fd69 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseVarargs.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/UseVarargs.xml @@ -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[]) { } +} + ]]> + + + + 0 + + + + + 0 + + + + + 1 + From 985ed57c52197bc9fed3501b5f183d6d83da6e08 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 7 Jan 2016 10:20:47 +0100 Subject: [PATCH 2/2] Update changelog --- src/site/markdown/overview/changelog.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/site/markdown/overview/changelog.md b/src/site/markdown/overview/changelog.md index 023c1af7e2..307a2b7cca 100644 --- a/src/site/markdown/overview/changelog.md +++ b/src/site/markdown/overview/changelog.md @@ -8,8 +8,13 @@ **New/Modified/Deprecated Rules:** +* java-design/UseVargs: public static void main method is ignored now and so are methods, that are annotated + with Override. See [PR#79](https://github.com/pmd/pmd/pull/79). + **Pull Requests:** +* [#79](https://github.com/pmd/pmd/pull/79): do not flag public static void main(String[]) as UseVarargs; ignore @Override for UseVarargs + **Bugfixes:** **API Changes:**