{"record":{"id":"1400894b39106bbb","repo":"TheAlgorithms/Java","slug":"frame-speed-must-be-lower-than-the-speed-of-light","errorCode":null,"errorMessage":"Frame speed must be lower than the speed of light","messagePattern":"Frame speed must be lower than the speed of light","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/physics/Relativity.java","lineNumber":77,"sourceCode":"        if (time < 0) {\n            throw new IllegalArgumentException(\"Time must be non-negative\");\n        }\n        return time * gamma(v);\n    }\n\n    /**\n     * Calculates the velocity with respect to the moving frame.\n     *\n     * @param v1 The velocity of the object with respect to laboratory frame (m/s).\n     * @param v The velocity of the moving frame (m/s).\n     * @return The velocity with respect to the moving frame (m/s).\n     */\n    public static double velocityAddition(double v1, double v) {\n        if (Math.abs(v1) > SPEED_OF_LIGHT) {\n            throw new IllegalArgumentException(\"Speed must not exceed the speed of light\");\n        }\n        if (Math.abs(v) >= SPEED_OF_LIGHT) {\n            throw new IllegalArgumentException(\"Frame speed must be lower than the speed of light\");\n        }\n        return (v1 - v) / (1 - v1 * v / (SPEED_OF_LIGHT * SPEED_OF_LIGHT));\n    }\n}\n","sourceCodeStart":59,"sourceCodeEnd":82,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/physics/Relativity.java#L59-L82","documentation":"Thrown by Relativity.velocityAddition when Math.abs(v) >= SPEED_OF_LIGHT. The frame velocity v appears in the denominator 1 - v1*v/c^2; if |v| reaches c the denominator can vanish (singularity) and beyond c the formula loses physical meaning. This is the second guard, checked after the v1 guard, so v1 must already be within ±c.","triggerScenarios":"Calling velocityAddition(v1, v) with |v| >= SPEED_OF_LIGHT. Unlike the v1 check, this uses >= so exactly ±c for the frame velocity is rejected (the moving frame cannot travel at c).","commonSituations":"Unit mismatch inflating the frame velocity v, or reusing a particle velocity as a frame velocity without subluminal enforcement.","solutions":["Ensure |v| is in m/s and strictly less than 299792458 m/s (the frame must be subluminal, not equal to c).","Confirm v uses the same m/s unit as SPEED_OF_LIGHT.","Note the asymmetry: v1 may equal ±c but v may not — do not treat the two guards as interchangeable."],"exampleFix":"// before\ndouble u = Relativity.velocityAddition(2e8, 3e8);\n// after\ndouble u = Relativity.velocityAddition(2e8, 1.5e8);","handlingStrategy":"validation","validationCode":"if (Math.abs(v) >= SPEED_OF_LIGHT) {\n    throw new IllegalArgumentException(\"|v| (frame) must be < c, got \" + v);\n}\ndouble u = Relativity.velocityAddition(v1, v);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat the frame velocity v as strictly subluminal (not equal to c).","Do not reuse a particle-at-c value as a frame velocity.","Validate units (m/s) against SPEED_OF_LIGHT before composing."],"tags":["java","physics","relativity","parameter-validation","unit-mismatch","illegal-argument"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}