You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Alex Herbert <al...@gmail.com> on 2019/05/22 15:09:37 UTC

[rng] Suppress PMD violations

I'm trying to get pmd:check to be useful.

This means fixing all the PMD violations. To fix some would be a 
refactor of reference algorithms which I do not want to start doing. So 
I've opted for the easier fix of increasing the allowed complexity.

Some PMD cheks I had to disable were:

- AccessorMethodGeneration

This allows internal private classes to access private methods of the 
outer class and vice versa. It could instead be fixed by changing to 
package-private methods where appropriate.

- OnlyOneReturn

There are many code examples of fast exit from methods with multiple 
return statements.

- BeanMembersShouldSerialize

I do not think we intend to have the classes as Serializable.

- DataflowAnomalyAnalysis

This rule is not very reliable [1]. It does not like a lot of the 
algorithms in the code that are established.


For one violation in sampling it can either be suppressed, or fixed by 
promoting a private class constructor to package-private. I think that 
the promotion to a package private constructor is OK. It is for this class:

LargeMeanPoissonSampler.LargeMeanPoissonSamplerState

This class is used by the LargeMeanPoissonSamplerCache and is already 
package-private. So making the constructor package private seems reasonable.


The options to suppress violations [2] are:

1. Use annotations

2. Use // NOPMD comment at the end of the offending line

3. Add suppression to the pmd configuration xml.

So not wanting to litter the code with comments and annotations I have 
updated the PMD xml to exclude certain checks.

There does not appear to be a separate PMD exclusions file in the manner 
of spotbugs. The exclusions performed at the configuration file use 
regular expressions so can be configured. But it requires XPath and the 
syntax for regular expressions doesn't work with examples I have tried. 
I have fixed it with explicit 'or' statements for matching multiple 
classes. I have not found out how to match a class and a method in the 
same expression. This could be used to narrow the scope of exclusions.


All changes are in this PR [3]. Have a look and see if you don't agree 
with the changes required.


Alex


[1] https://github.com/pmd/pmd/issues/873

[2] https://pmd.github.io/latest/pmd_userdocs_suppressing_warnings.html

[3] https://github.com/apache/commons-rng/pull/45



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [rng] Suppress PMD violations

Posted by Gilles Sadowski <gi...@gmail.com>.
Hi Alex.

PR looks fine.

Thanks,
Gilles


Le mer. 22 mai 2019 à 17:09, Alex Herbert <al...@gmail.com> a écrit :
>
> I'm trying to get pmd:check to be useful.
>
> This means fixing all the PMD violations. To fix some would be a
> refactor of reference algorithms which I do not want to start doing. So
> I've opted for the easier fix of increasing the allowed complexity.
>
> Some PMD cheks I had to disable were:
>
> - AccessorMethodGeneration
>
> This allows internal private classes to access private methods of the
> outer class and vice versa. It could instead be fixed by changing to
> package-private methods where appropriate.
>
> - OnlyOneReturn
>
> There are many code examples of fast exit from methods with multiple
> return statements.
>
> - BeanMembersShouldSerialize
>
> I do not think we intend to have the classes as Serializable.
>
> - DataflowAnomalyAnalysis
>
> This rule is not very reliable [1]. It does not like a lot of the
> algorithms in the code that are established.
>
>
> For one violation in sampling it can either be suppressed, or fixed by
> promoting a private class constructor to package-private. I think that
> the promotion to a package private constructor is OK. It is for this class:
>
> LargeMeanPoissonSampler.LargeMeanPoissonSamplerState
>
> This class is used by the LargeMeanPoissonSamplerCache and is already
> package-private. So making the constructor package private seems reasonable.
>
>
> The options to suppress violations [2] are:
>
> 1. Use annotations
>
> 2. Use // NOPMD comment at the end of the offending line
>
> 3. Add suppression to the pmd configuration xml.
>
> So not wanting to litter the code with comments and annotations I have
> updated the PMD xml to exclude certain checks.
>
> There does not appear to be a separate PMD exclusions file in the manner
> of spotbugs. The exclusions performed at the configuration file use
> regular expressions so can be configured. But it requires XPath and the
> syntax for regular expressions doesn't work with examples I have tried.
> I have fixed it with explicit 'or' statements for matching multiple
> classes. I have not found out how to match a class and a method in the
> same expression. This could be used to narrow the scope of exclusions.
>
>
> All changes are in this PR [3]. Have a look and see if you don't agree
> with the changes required.
>
>
> Alex
>
>
> [1] https://github.com/pmd/pmd/issues/873
>
> [2] https://pmd.github.io/latest/pmd_userdocs_suppressing_warnings.html
>
> [3] https://github.com/apache/commons-rng/pull/45
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org