diff --git a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java index cf17713b5..09c580044 100644 --- a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java +++ b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreHighPrecisionRuleFactory.java @@ -19,6 +19,8 @@ package org.apache.commons.math3.analysis.integration.gauss; import java.math.MathContext; import java.math.BigDecimal; import org.apache.commons.math3.util.Pair; +import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.apache.commons.math3.exception.util.LocalizedFormats; /** * Factory that creates Gauss-type quadrature rule using Legendre polynomials. @@ -63,6 +65,11 @@ public class LegendreHighPrecisionRuleFactory extends BaseRuleFactory computeRule(int numberOfPoints) { + if (numberOfPoints <= 0) { + throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS, + numberOfPoints); + } + if (numberOfPoints == 1) { // Break recursion. return new Pair(new BigDecimal[] { BigDecimal.ZERO }, diff --git a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java index e3471ede5..a794acce9 100644 --- a/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java +++ b/src/main/java/org/apache/commons/math3/analysis/integration/gauss/LegendreRuleFactory.java @@ -17,6 +17,8 @@ package org.apache.commons.math3.analysis.integration.gauss; import org.apache.commons.math3.util.Pair; +import org.apache.commons.math3.exception.NotStrictlyPositiveException; +import org.apache.commons.math3.exception.util.LocalizedFormats; /** * Factory that creates Gauss-type quadrature rule using Legendre polynomials. @@ -35,6 +37,11 @@ public class LegendreRuleFactory extends BaseRuleFactory { */ @Override protected Pair computeRule(int numberOfPoints) { + if (numberOfPoints <= 0) { + throw new NotStrictlyPositiveException(LocalizedFormats.NUMBER_OF_POINTS, + numberOfPoints); + } + if (numberOfPoints == 1) { // Break recursion. return new Pair(new Double[] { 0d },