Repository: commons-math Updated Branches: refs/heads/MATH_3_X 978f89c75 -> fe23c9b04
[MATH-1294] Fix potential race condition in PolynomialUtils. Thanks to Kamil WÅodarczyk Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/fe23c9b0 Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/fe23c9b0 Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/fe23c9b0 Branch: refs/heads/MATH_3_X Commit: fe23c9b04aff89b3c6da20b4769157b8c577d071 Parents: 978f89c Author: Thomas Neidhart <thomas.neidh...@gmail.com> Authored: Mon Nov 23 23:16:58 2015 +0100 Committer: Thomas Neidhart <thomas.neidh...@gmail.com> Committed: Mon Nov 23 23:16:58 2015 +0100 ---------------------------------------------------------------------- src/changes/changes.xml | 5 +++++ .../math3/analysis/polynomials/PolynomialsUtils.java | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-math/blob/fe23c9b0/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7dfacc5..3448c23 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -51,6 +51,11 @@ If the output is not quite correct, check for invisible trailing spaces! </properties> <body> <release version="3.6" date="XXXX-XX-XX" description=""> + <action dev="tn" type="fix" issue="MATH-1294" due-to="Kamil WÅodarczyk"> + Fixed potential race condition in PolynomialUtils#buildPolynomial in + case polynomials are generated from multiple threads. Furthermore, the + synchronization is now performed on the coefficient list instead of the class. + </action> <action dev="psteitz" type="update" issue="MATH-1246"> Added bootstrap method to KolmogorovSmirnov test. </action> http://git-wip-us.apache.org/repos/asf/commons-math/blob/fe23c9b0/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialsUtils.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialsUtils.java b/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialsUtils.java index 5604149..2efa07d 100644 --- a/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialsUtils.java +++ b/src/main/java/org/apache/commons/math3/analysis/polynomials/PolynomialsUtils.java @@ -107,6 +107,7 @@ public class PolynomialsUtils { /** Fixed recurrence coefficients. */ private final BigFraction[] coeffs = { BigFraction.ZERO, BigFraction.TWO, BigFraction.ONE }; /** {@inheritDoc} */ + @Override public BigFraction[] generate(int k) { return coeffs; } @@ -131,6 +132,7 @@ public class PolynomialsUtils { return buildPolynomial(degree, HERMITE_COEFFICIENTS, new RecurrenceCoefficientsGenerator() { /** {@inheritDoc} */ + @Override public BigFraction[] generate(int k) { return new BigFraction[] { BigFraction.ZERO, @@ -157,6 +159,7 @@ public class PolynomialsUtils { return buildPolynomial(degree, LAGUERRE_COEFFICIENTS, new RecurrenceCoefficientsGenerator() { /** {@inheritDoc} */ + @Override public BigFraction[] generate(int k) { final int kP1 = k + 1; return new BigFraction[] { @@ -184,6 +187,7 @@ public class PolynomialsUtils { return buildPolynomial(degree, LEGENDRE_COEFFICIENTS, new RecurrenceCoefficientsGenerator() { /** {@inheritDoc} */ + @Override public BigFraction[] generate(int k) { final int kP1 = k + 1; return new BigFraction[] { @@ -234,6 +238,7 @@ public class PolynomialsUtils { return buildPolynomial(degree, JACOBI_COEFFICIENTS.get(key), new RecurrenceCoefficientsGenerator() { /** {@inheritDoc} */ + @Override public BigFraction[] generate(int k) { k++; final int kvw = k + v + w; @@ -359,9 +364,8 @@ public class PolynomialsUtils { private static PolynomialFunction buildPolynomial(final int degree, final List<BigFraction> coefficients, final RecurrenceCoefficientsGenerator generator) { - - final int maxDegree = (int) FastMath.floor(FastMath.sqrt(2 * coefficients.size())) - 1; - synchronized (PolynomialsUtils.class) { + synchronized (coefficients) { + final int maxDegree = (int) FastMath.floor(FastMath.sqrt(2 * coefficients.size())) - 1; if (degree > maxDegree) { computeUpToDegree(degree, maxDegree, generator, coefficients); }