[jira] [Closed] (MATH-942) DiscreteDistribution.sample(int) may throw an exception if first element of singletons of sub-class type

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Closed] (MATH-942) DiscreteDistribution.sample(int) may throw an exception if first element of singletons of sub-class type

ASF GitHub Bot (Jira)

     [ https://issues.apache.org/jira/browse/MATH-942?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Luc Maisonobe closed MATH-942.
------------------------------


Closing issue as version 3.2 has been released on 2013-04-06.
               

> DiscreteDistribution.sample(int) may throw an exception if first element of singletons of sub-class type
> --------------------------------------------------------------------------------------------------------
>
>                 Key: MATH-942
>                 URL: https://issues.apache.org/jira/browse/MATH-942
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Piotr Wydrych
>             Fix For: 3.2
>
>         Attachments: DiscreteDistribution.java.patch
>
>
> Creating an array with {{Array.newInstance(singletons.get(0).getClass(), sampleSize)}} in DiscreteDistribution.sample(int) is risky. An exception will be thrown if:
> * {{singleons.get(0)}} is of type T1, an sub-class of T, and
> * {{DiscreteDistribution.sample()}} returns an object which is of type T, but not of type T1.
> To reproduce:
> {code}
> List<Pair<Object,Double>> list = new ArrayList<Pair<Object, Double>>();
> list.add(new Pair<Object, Double>(new Object() {}, new Double(0)));
> list.add(new Pair<Object, Double>(new Object() {}, new Double(1)));
> new DiscreteDistribution<Object>(list).sample(1);
> {code}
> Attaching a patch.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira