{"record":{"id":"11f33523974b832b","repo":"TheAlgorithms/Java","slug":"speed-must-not-exceed-the-speed-of-light","errorCode":null,"errorMessage":"Speed must not exceed the speed of light","messagePattern":"Speed must not exceed the speed of light","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/physics/Relativity.java","lineNumber":74,"sourceCode":"     * @return The time that has passed in the laboratory frame (s).\n     */\n    public static double timeDilation(double time, double v) {\n        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":56,"sourceCodeEnd":82,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/physics/Relativity.java#L56-L82","documentation":"Thrown by Relativity.velocityAddition when Math.abs(v1) > SPEED_OF_LIGHT. The relativistic velocity-addition formula (v1 - v) / (1 - v1*v/c^2) only has physical meaning when the object's velocity in the lab frame does not exceed c; a superluminal v1 is invalid. This is the first of two velocity guards in velocityAddition, checked before the frame-velocity v guard.","triggerScenarios":"Calling velocityAddition(v1, v) with |v1| strictly greater than SPEED_OF_LIGHT. A v1 of exactly ±c is allowed by this guard (it checks > not >=), though the formula denominator may still misbehave.","commonSituations":"Unit mismatch (km/s vs m/s) inflating v1, or composing velocities from a Galilean-addition step that already exceeded c before being passed here.","solutions":["Ensure |v1| is in m/s and does not exceed 299792458 m/s.","Verify the unit of v1 matches the SPEED_OF_LIGHT constant (m/s in this file).","If v1 originates from a previous velocityAddition result, the prior call already enforces subluminal output, so a superluminal input here signals a unit error."],"exampleFix":"// before\ndouble u = Relativity.velocityAddition(4e8, 1e8);\n// after\ndouble u = Relativity.velocityAddition(2e8, 1e8);","handlingStrategy":"validation","validationCode":"if (Math.abs(v1) > SPEED_OF_LIGHT) {\n    throw new IllegalArgumentException(\"|v1| must be <= c, got \" + v1);\n}\ndouble u = Relativity.velocityAddition(v1, v);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate both v1 and v units (m/s) before composing velocities.","Remember v1 may equal ±c but v may not — the two guards differ.","Unit-test the composition with subluminal canonical values."],"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-14T05:17:29.042Z"}