commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Phil Steitz (JIRA)" <>
Subject [jira] Commented: (MATH-349) Dangerous code in "PoissonDistributionImpl"
Date Sat, 06 Mar 2010 15:50:27 GMT


Phil Steitz commented on MATH-349:

The reason this constructor exists is to allow users to plug in an alternative normal distribution
implementation to be used in computing normal approximations.  I don't see 1) as a serious
issue, but I am +1 on deprecating the setters with aim to make this class immutable in 3.0.
 2) is a harder problem, as there is no requirement that a NormalDistribution be clonable.
  I see three solutions, none of which are particularly appealing:

1) leave as is and specify in the javadoc that z is going to be modified
2) change the implementation to avoid changing the parameters of z 
3) deprecate the constructor altogether

I vote for 1) + 3) - update the javadoc, but deprecate.  If we get complaints before 3.0,
we can reconsider; otherwise eliminate in 3.0

> Dangerous code in "PoissonDistributionImpl"
> -------------------------------------------
>                 Key: MATH-349
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Gilles
>            Priority: Minor
> In the following excerpt from class "PoissonDistributionImpl":
> ---CUT---
>     public PoissonDistributionImpl(double p, NormalDistribution z) {
>         super();
>         setNormal(z);
>         setMean(p);
>     }
> ---CUT---
> (1) Overridable methods are called within the constructor.
> (2) The reference "z" is stored and modified within the class.
> I've encountered problem (1) in several classes while working on issue 348. In those
cases, in order to remove potential problems, I copied/pasted the body of the "setter" methods
inside the constructor but I think that a more elegant solution would be to remove the "setters"
altogether (i.e. make the classes immutable).
> Problem (2) can also create unexpected behaviour. Is it really necessary to pass the
"NormalDistribution" object; can't it be always created within the class?

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message