{"record":{"id":"c99a9c1f2ff6b056","repo":"apache/dubbo","slug":"no-instance-of-netutils-for-you","errorCode":null,"errorMessage":"No instance of 'NetUtils' for you! ","messagePattern":"No instance of 'NetUtils' for you! ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"warning","filePath":"dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java","lineNumber":64,"sourceCode":"import java.util.regex.PatternSyntaxException;\n\nimport static java.util.Collections.emptyList;\nimport static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;\nimport static org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND;\nimport static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_KEY;\nimport static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;\nimport static org.apache.dubbo.common.utils.CollectionUtils.first;\n\n/**\n * IP and Port Helper for RPC\n */\npublic final class NetUtils {\n\n    /**\n     * Forbids instantiation.\n     */\n    private NetUtils() {\n        throw new UnsupportedOperationException(\"No instance of 'NetUtils' for you! \");\n    }\n\n    private static Logger logger;\n\n    static {\n        /*\n            DO NOT replace this logger to error type aware logger (or fail-safe logger), since its\n            logging method calls NetUtils.getLocalHost().\n\n            According to issue #4992, getLocalHost() method will be endless recursively invoked when network disconnected.\n        */\n\n        logger = LoggerFactory.getLogger(NetUtils.class);\n        if (logger instanceof FailsafeLogger) {\n            logger = ((FailsafeLogger) logger).getLogger();\n        }\n    }\n","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/dubbo/blob/3a3043227f5571d25eb2889de5bca22f2914843b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java#L46-L82","documentation":"NetUtils is a utility class with a private constructor that throws UnsupportedOperationException to prevent instantiation. Attempting 'new NetUtils()' always fails; all functionality is exposed only via static methods.","triggerScenarios":"Calling 'new NetUtils()' directly, or using reflection/spy frameworks (PowerMock, Mockito for static) that try to instantiate the class to intercept it.","commonSituations":"Tooling or frameworks that instantiate classes reflectively without checking isInstanceCreatable; misguided attempts to mock a final utility class by subclassing via objenesis.","solutions":["Do not instantiate NetUtils; call its static methods (getLocalHost, getAvailablePort, etc.) directly","For testing, wrap NetUtils calls behind your own interface and mock that interface instead"],"exampleFix":"// before\nNetUtils net = new NetUtils();\n// after\nString host = NetUtils.getLocalHost();","handlingStrategy":"validation","validationCode":"// NetUtils cannot be instantiated; this is by design. Do not attempt 'new NetUtils()'.\nString host = NetUtils.getLocalHost();","typeGuard":"// n/a","tryCatchPattern":"// n/a","preventionTips":["Treat NetUtils as a static-only utility","Wrap static calls behind an injectable interface for testability"],"tags":["utility","instantiation","reflection"],"backgroundTag":null,"analyzedSha":"3a3043227f5571d25eb2889de5bca22f2914843b","analyzedAt":"2026-08-14T00:43:19.853Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}