[
https://issues.apache.org/jira/browse/MATH-1134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14052634#comment-14052634
]
Phil Steitz commented on MATH-1134:
-----------------------------------
I agree that ISE would be better, but I think the API is a little awkward. The
r1607434 code does clearly document preconditions so the RTE would not be
"unexpected" but I think the current code forces users to think about the
constructor flag when we can just fix the code to be threadsafe. I think we
should strive to make our APIs as simple as possible, avoiding situations where
you have to provide special constructor arguments for instance methods to work
when we can.
I think we should either get rid of the partials caching, have the flag control
that (meaning false means do not cache partials), or just make the cache
initialization threadsafe (the patch I provided is one way to do this).
> unsafe initialization in BicubicSplineInterpolatingFunction
> -----------------------------------------------------------
>
> Key: MATH-1134
> URL: https://issues.apache.org/jira/browse/MATH-1134
> Project: Commons Math
> Issue Type: Bug
> Affects Versions: 3.3
> Reporter: Derek Scherger
> Priority: Minor
> Attachments: MATH-1134.patch
>
>
> The lazy initialization of the internal array of partialDerivatives in
> BicubicSplineInterpolatingFunction is not thread safe. If multiple threads
> call any of the partialDerivative functions concurrently one thread may start
> the initialization and others will see the array is non-null and assume it is
> fully initialized. If the internal array of partial derivatives was
> initialized in the constructor this would not be a problem.
> i.e. the following check in partialDerivative(which, x, y)
> if (partialDerivatives == null) {
> computePartialDerivatives();
> }
> will start the initialization. However in computePartialDerivatives()
> partialDerivatives = new BivariateFunction[5][lastI][lastJ];
> makes it appear to other threads as the the initialization has completed when
> it may not have.
--
This message was sent by Atlassian JIRA
(v6.2#6252)