{"record":{"id":"2237483d0b64e0d4","repo":"TheAlgorithms/Java","slug":"no-instances","errorCode":null,"errorMessage":"No instances.","messagePattern":"No instances\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"src/main/java/com/thealgorithms/maths/PiApproximation.java","lineNumber":20,"sourceCode":"import java.util.ArrayList;\nimport java.util.List;\nimport java.util.Random;\n\n/**\n * Implementation to calculate an estimate of the number π (Pi).\n *\n * We take a random point P with coordinates (x, y) such that 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1.\n * If x² + y² ≤ 1, then the point is inside the quarter disk of radius 1,\n * else the point is outside. We know that the probability of the point being\n * inside the quarter disk is equal to π/4.\n *\n *\n * @author [Yash Rajput](https://github.com/the-yash-rajput)\n */\npublic final class PiApproximation {\n\n    private PiApproximation() {\n        throw new AssertionError(\"No instances.\");\n    }\n\n    /**\n     * Structure representing a point with coordinates (x, y)\n     * where 0 ≤ x ≤ 1 and 0 ≤ y ≤ 1.\n     */\n    static class Point {\n        double x;\n        double y;\n\n        Point(double x, double y) {\n            this.x = x;\n            this.y = y;\n        }\n    }\n\n    /**\n     * This function uses the points in a given list (drawn at random)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/TheAlgorithms/Java/blob/fdfb9a395b310167a66bd29e311e36e0e3e9b964/src/main/java/com/thealgorithms/maths/PiApproximation.java#L2-L38","documentation":"Thrown by the private constructor of PiApproximation to prevent instantiation. PiApproximation is a utility class whose members are static; creating an instance is never meaningful. The constructor is private and immediately throws AssertionError so reflection-based or accidental instantiation fails loudly.","triggerScenarios":"Any attempt to construct a PiApproximation instance — via reflection (PiApproximation.class.getDeclaredConstructor().setAccessible(true).newInstance()) or by subclassing/inner-class access. Normal new PiApproximation() is blocked at compile time by the private constructor.","commonSituations":"Reflection-driven frameworks (some DI containers, serializers, ORMs) that try to instantiate classes via no-arg constructors; a copy-paste of a utility class into a context expecting instances; test code using reflection to construct objects.","solutions":["Do not instantiate PiApproximation; call its static methods directly (e.g., PiApproximation.someStaticMethod()).","If a framework requires instantiable types, annotate/skip utility classes or wrap the static API behind an instance-based adapter you control.","For reflection-heavy frameworks, register a custom factory or exclude the class from auto-instantiation."],"exampleFix":"// before (reflection)\nPiApproximation p = PiApproximation.class.getDeclaredConstructor().setAccessible(true) ? ... : null;\n\n// after — call static API directly\ndouble pi = PiApproximation.estimatePi(iterations);","handlingStrategy":"validation","validationCode":"// never instantiate; call static methods directly\ndouble pi = PiApproximation.someStaticMethod();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Do not instantiate utility classes; call their static methods directly.","For reflection-based frameworks, register custom factories or exclude utility classes.","Wrap static APIs behind an instance-based adapter if a framework requires instances."],"tags":["math","utility-class","instantiation","reflection"],"backgroundTag":null,"analyzedSha":"fdfb9a395b310167a66bd29e311e36e0e3e9b964","analyzedAt":"2026-08-13T23:36:13.315Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}