{"record":{"id":"f30c009f7f5ed762","repo":"TheAlgorithms/Java","slug":"orbiting-mass-and-radius-must-be-positive","errorCode":null,"errorMessage":"Orbiting mass and radius must be positive.","messagePattern":"Orbiting mass and radius must be positive\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/physics/CoulombsLaw.java","lineNumber":71,"sourceCode":"        double fy = forceMagnitude * (dy / distance);\n\n        return new double[] {fx, fy};\n    }\n\n    /**\n     * Calculates the speed required for a stable circular orbit of a charged particle\n     * around a central charge (e.g., an electron orbiting a nucleus).\n     *\n     * @param centralCharge The charge of the central body (in Coulombs).\n     * @param orbitingCharge The charge of the orbiting body (in Coulombs).\n     * @param orbitingMass The mass of the orbiting body (in kg).\n     * @param radius The radius of the orbit (in m).\n     * @return The orbital speed (in m/s).\n     * @throws IllegalArgumentException if mass or radius are not positive.\n     */\n    public static double calculateCircularOrbitVelocity(double centralCharge, double orbitingCharge, double orbitingMass, double radius) {\n        if (orbitingMass <= 0 || radius <= 0) {\n            throw new IllegalArgumentException(\"Orbiting mass and radius must be positive.\");\n        }\n\n        // We only need the magnitude of the force, which is always positive.\n        double forceMagnitude = Math.abs(COULOMBS_CONSTANT * centralCharge * orbitingCharge) / (radius * radius);\n\n        // F_c = m * v^2 / r  =>  v = sqrt(F_c * r / m)\n        return Math.sqrt(forceMagnitude * radius / orbitingMass);\n    }\n}\n","sourceCodeStart":53,"sourceCodeEnd":81,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/physics/CoulombsLaw.java#L53-L81","documentation":"Thrown by CoulombsLaw.calculateCircularOrbitVelocity when orbitingMass <= 0 or radius <= 0. The orbital velocity formula v = sqrt(F_c * r / m) divides by mass and takes a square root, so a non-positive mass or radius would yield a division by zero, an imaginary result, or a physically meaningless value. This models a charged particle in stable circular orbit around a central charge.","triggerScenarios":"Calling calculateCircularOrbitVelocity(centralCharge, orbitingCharge, orbitingMass, radius) with orbitingMass = 0 or negative, or radius = 0 or negative. Note centralCharge and orbitingCharge are NOT validated here (they are squared/magnitude-handled), so they do not trigger this.","commonSituations":"Using uninitialised (0) mass/radius fields, a config typo specifying radius 0, unit-conversion mistakes producing 0, or importing data where a column was null and coerced to 0.","solutions":["Pass strictly positive values for orbitingMass (kg) and radius (m).","Validate inputs at the boundary of your data layer (parse/load) and reject zero or negative mass/radius before reaching the physics call.","If charges came from external data, double-check you are not confusing the charge array index with the mass/radius index."],"exampleFix":"// before\ndouble v = CoulombsLaw.calculateCircularOrbitVelocity(1.6e-19, 1.6e-19, 0, 5.29e-11);\n// after\ndouble v = CoulombsLaw.calculateCircularOrbitVelocity(1.6e-19, 1.6e-19, 9.11e-31, 5.29e-11);","handlingStrategy":"validation","validationCode":"if (!(orbitingMass > 0 && radius > 0)) {\n    throw new IllegalArgumentException(\"mass and radius must be > 0 before orbit calc\");\n}\ndouble v = CoulombsLaw.calculateCircularOrbitVelocity(centralCharge, orbitingCharge, orbitingMass, radius);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Load and validate physical constants at the data boundary before any physics call.","Use named constants for canonical values (electron mass, Bohr radius) rather than literals.","Add a NaN guard if values come from upstream arithmetic."],"tags":["java","physics","parameter-validation","orbital-mechanics","illegal-argument"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}