{"record":{"id":"01c0b1c07c34f2ad","repo":"Netflix/Hystrix","slug":"it-s-prohibited-to-create-instances-of-the-class","errorCode":null,"errorMessage":"It's prohibited to create instances of the class.","messagePattern":"It's prohibited to create instances of the class\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/utils/AopUtils.java","lineNumber":36,"sourceCode":"import com.google.common.base.Optional;\nimport com.google.common.base.Throwables;\nimport org.apache.commons.lang3.Validate;\nimport org.aspectj.lang.JoinPoint;\nimport org.aspectj.lang.reflect.MethodSignature;\n\nimport java.io.IOException;\nimport java.lang.annotation.Annotation;\nimport java.lang.reflect.Method;\nimport java.lang.reflect.Modifier;\nimport java.lang.reflect.Type;\n\n/**\n * Provides common methods to retrieve information from JoinPoint and not only.\n */\npublic final class AopUtils {\n\n    private AopUtils() {\n        throw new UnsupportedOperationException(\"It's prohibited to create instances of the class.\");\n    }\n\n    /**\n     * Gets a {@link Method} object from target object (not proxy class).\n     *\n     * @param joinPoint the {@link JoinPoint}\n     * @return a {@link Method} object or null if method doesn't exist or if the signature at a join point\n     *         isn't sub-type of {@link MethodSignature}\n     */\n    public static Method getMethodFromTarget(JoinPoint joinPoint) {\n        Method method = null;\n        if (joinPoint.getSignature() instanceof MethodSignature) {\n            MethodSignature signature = (MethodSignature) joinPoint.getSignature();\n            method = getDeclaredMethod(joinPoint.getTarget().getClass(), signature.getName(),\n                    getParameterTypes(joinPoint));\n        }\n        return method;\n    }","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-contrib/hystrix-javanica/src/main/java/com/netflix/hystrix/contrib/javanica/utils/AopUtils.java#L18-L54","documentation":"AopUtils is a static-only utility class in Javanica, and its private constructor throws UnsupportedOperationException to prevent instantiation (even via reflection-based constructor access within the class itself or by test tooling). This is a deliberate guard, not a runtime failure of library logic — you only see it if something tries to `new AopUtils()`.","triggerScenarios":"Explicitly calling new AopUtils(); a reflection framework (XStream, Kryo, certain mocking libs, JSON deserializers) instantiating the class because it appears on a classpath scan; a copy-paste of the class into your source and constructing it.","commonSituations":"Component scanning (e.g. Spring picking it up after copying the package into your source tree); serializers that require no-arg constructors; accidental instantiation in unit tests.","solutions":["Remove the instantiation — call the static helpers (getMethodFromTarget, etc.) directly","If a framework is constructing it, exclude the class from scanning/serialization (e.g. @ComponentScan filter, Kryo serializer config)","If you copied the class into your own package, delete the copy and depend on the artifact instead"],"exampleFix":"// before\nAopUtils utils = new AopUtils();\nMethod m = utils.getMethodFromTarget(joinPoint);\n\n// after\nMethod m = AopUtils.getMethodFromTarget(joinPoint);","handlingStrategy":"validation","validationCode":"if (AopUtils.class.equals(clazz)) { throw new IllegalStateException(\"AopUtils is static-only; do not instantiate\"); }","typeGuard":null,"tryCatchPattern":"catch (UnsupportedOperationException e) { /* remove the instantiation; call static methods directly */ }","preventionTips":["Keep static utility classes out of component-scan/serialization paths","Call static helpers via the class name only","Never copy library utility classes into your own packages"],"tags":["hystrix","javanica","utility-class","instantiation","static"],"backgroundTag":null,"analyzedSha":"5ce3bc58c38e7ca60ef2fe0e516e390e294ad941","analyzedAt":"2026-08-14T10:55:35.600Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}