apache/dubbo · warning · UnsupportedOperationException

No instance of 'NetUtils' for you!

Error message

No instance of 'NetUtils' for you! 

What it means

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.

Source

Thrown at dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java:64

import java.util.regex.PatternSyntaxException;

import static java.util.Collections.emptyList;
import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE;
import static org.apache.dubbo.common.constants.CommonConstants.DUBBO_IP_TO_BIND;
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.LOCALHOST_VALUE;
import static org.apache.dubbo.common.utils.CollectionUtils.first;

/**
 * IP and Port Helper for RPC
 */
public final class NetUtils {

    /**
     * Forbids instantiation.
     */
    private NetUtils() {
        throw new UnsupportedOperationException("No instance of 'NetUtils' for you! ");
    }

    private static Logger logger;

    static {
        /*
            DO NOT replace this logger to error type aware logger (or fail-safe logger), since its
            logging method calls NetUtils.getLocalHost().

            According to issue #4992, getLocalHost() method will be endless recursively invoked when network disconnected.
        */

        logger = LoggerFactory.getLogger(NetUtils.class);
        if (logger instanceof FailsafeLogger) {
            logger = ((FailsafeLogger) logger).getLogger();
        }
    }

View on GitHub (pinned to 3a3043227f)

Solutions

  1. Do not instantiate NetUtils; call its static methods (getLocalHost, getAvailablePort, etc.) directly
  2. For testing, wrap NetUtils calls behind your own interface and mock that interface instead

Example fix

// before
NetUtils net = new NetUtils();
// after
String host = NetUtils.getLocalHost();
Defensive patterns

Strategy: validation

Validate before calling

// NetUtils cannot be instantiated; this is by design. Do not attempt 'new NetUtils()'.
String host = NetUtils.getLocalHost();

Type guard

// n/a

Try / catch

// n/a

Prevention

When it happens

Trigger: Calling 'new NetUtils()' directly, or using reflection/spy frameworks (PowerMock, Mockito for static) that try to instantiate the class to intercept it.

Common situations: Tooling or frameworks that instantiate classes reflectively without checking isInstanceCreatable; misguided attempts to mock a final utility class by subclassing via objenesis.

Related errors


AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14). Data as JSON: /api/errors/c99a9c1f2ff6b056. Report an issue: GitHub.