{"record":{"id":"df280a96f82c7aaf","repo":"TheAlgorithms/Java","slug":"stepsize-should-be-greater-than-zero","errorCode":null,"errorMessage":"stepSize should be greater than zero","messagePattern":"stepSize should be greater than zero","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/EulerMethod.java","lineNumber":60,"sourceCode":"        BiFunction<Double, Double, Double> exampleEquation3 = (x, y) -> x + y + x * y;\n        ArrayList<double[]> points3 = eulerFull(0, 0.1, 0.025, 1, exampleEquation3);\n        assert points3.get(points3.size() - 1)[1] == 1.1116729841674804;\n        points3.forEach(point -> System.out.printf(\"x: %1$f; y: %2$f%n\", point[0], point[1]));\n    }\n\n    /**\n     * calculates the next y-value based on the current value of x, y and the\n     * stepSize the console.\n     *\n     * @param xCurrent Current x-value.\n     * @param stepSize Step-size on the x-axis.\n     * @param yCurrent Current y-value.\n     * @param differentialEquation The differential equation to be solved.\n     * @return The next y-value.\n     */\n    public static double eulerStep(double xCurrent, double stepSize, double yCurrent, BiFunction<Double, Double, Double> differentialEquation) {\n        if (stepSize <= 0) {\n            throw new IllegalArgumentException(\"stepSize should be greater than zero\");\n        }\n        return yCurrent + stepSize * differentialEquation.apply(xCurrent, yCurrent);\n    }\n\n    /**\n     * Loops through all the steps until xEnd is reached, adds a point for each\n     * step and then returns all the points\n     *\n     * @param xStart First x-value.\n     * @param xEnd Last x-value.\n     * @param stepSize Step-size on the x-axis.\n     * @param yStart First y-value.\n     * @param differentialEquation The differential equation to be solved.\n     * @return The points constituting the solution of the differential\n     * equation.\n     */\n    public static ArrayList<double[]> eulerFull(double xStart, double xEnd, double stepSize, double yStart, BiFunction<Double, Double, Double> differentialEquation) {\n        if (xStart >= xEnd) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/EulerMethod.java#L42-L78","documentation":"Thrown by EulerMethod.eulerStep when stepSize <= 0. eulerStep computes a single Euler integration step y_next = yCurrent + stepSize * f(x,y); a non-positive step would move backward or not at all, violating the method's contract as a forward integrator. The guard runs before the function evaluation so no computation is wasted on an invalid step.","triggerScenarios":"Calling eulerStep with stepSize = 0, a negative value, or a stepSize parsed from config that defaulted to 0. Because eulerStep is also called internally by eulerFull, this can surface indirectly if eulerFull's own guard is bypassed or if eulerStep is used standalone.","commonSituations":"Adaptive-step code that computes a step size which collapses to 0; config file missing the stepSize key and parsing to 0; reusing a step variable that was zeroed.","solutions":["Pass a positive stepSize such as 0.1 or 0.01.","If computing stepSize adaptively, clamp it to a positive minimum.","Validate config-derived values before the call."],"exampleFix":"// before\ndouble yNext = EulerMethod.eulerStep(x, 0, y, f);\n\n// after\ndouble yNext = EulerMethod.eulerStep(x, 0.1, y, f);","handlingStrategy":"validation","validationCode":"if (!(stepSize > 0)) {\n    throw new IllegalArgumentException(\"stepSize must be > 0\");\n}\nEulerMethod.eulerStep(x, stepSize, y, f);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Clamp adaptively-computed steps to a positive minimum.","Default config stepSize to a positive constant.","Guard against numSteps == 0 when deriving stepSize by division."],"tags":["validation","numerical-methods","ode","precondition"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}