YunaiV/ruoyi-vue-pro · error · IllegalArgumentException

[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]

Error message

[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]

What it means

Thrown by the default branch of IotProtocolManager.createProtocol()'s switch when a protocol config's IotProtocolTypeEnum matches no case. This is effectively defensive dead code today: the enum has exactly 9 values (TCP, UDP, WEBSOCKET, HTTP, MQTT, EMQX, COAP, MODBUS_TCP_CLIENT, MODBUS_TCP_SERVER) and all 9 have explicit cases; unknown string types are already handled earlier by IotProtocolTypeEnum.of() returning null (logged at line 99, returns null). It only becomes reachable if a new enum constant is added without a matching case.

Source

Thrown at yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/IotProtocolManager.java:122

                return createHttpProtocol(config);
            case TCP:
                return createTcpProtocol(config);
            case UDP:
                return createUdpProtocol(config);
            case COAP:
                return createCoapProtocol(config);
            case WEBSOCKET:
                return createWebSocketProtocol(config);
            case MQTT:
                return createMqttProtocol(config);
            case EMQX:
                return createEmqxProtocol(config);
            case MODBUS_TCP_CLIENT:
                return createModbusTcpClientProtocol(config);
            case MODBUS_TCP_SERVER:
                return createModbusTcpServerProtocol(config);
            default:
                throw new IllegalArgumentException(String.format(
                        "[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]", config.getId(), protocolType));
        }
    }

    /**
     * 创建 HTTP 协议实例
     *
     * @param config 协议实例配置
     * @return HTTP 协议实例
     */
    private IotHttpProtocol createHttpProtocol(IotGatewayProperties.ProtocolProperties config) {
        return new IotHttpProtocol(config);
    }

    /**
     * 创建 TCP 协议实例
     *
     * @param config 协议实例配置

View on GitHub (pinned to 0418084e22)

Solutions

  1. Add the missing case branch and a createXxxProtocol(config) factory method in IotProtocolManager.
  2. Add a unit test that iterates every IotProtocolTypeEnum value and asserts createProtocol dispatches without throwing, so future enum additions are caught.
  3. If the protocol type is genuinely unsupported, remove/fix the protocol instance from yudao.gateway.protocols config.

Example fix

// after adding enum value OPC_UA
case OPC_UA:
    return createOpcUaProtocol(config);
// ...
private IotOpcUaProtocol createOpcUaProtocol(ProtocolProperties config) {
    return new IotOpcUaProtocol(config);
}
Defensive patterns

Strategy: validation

Validate before calling

// validate the configured protocol type is one the manager supports, before start()
IotProtocolTypeEnum t = IotProtocolTypeEnum.of(config.getProtocol());
if (t == null) {
    log.error("不支持的协议类型: {}", config.getProtocol());
    continue; // or skip this instance
}
// (createProtocol's default branch is otherwise unreachable for the current enum)

Type guard

// ensure every enum value is handled
static final Set<IotProtocolTypeEnum> SUPPORTED = EnumSet.allOf(IotProtocolTypeEnum.class);
boolean isSupportedProtocol(IotProtocolTypeEnum t) {
    return t != null && SUPPORTED.contains(t);
}

Prevention

When it happens

Trigger: A developer adds a new IotProtocolTypeEnum value (e.g. OPC_UA) but forgets to add a case + createXxxProtocol() factory in IotProtocolManager.createProtocol(); then configures a protocol instance with that type.

Common situations: Extending the gateway to support a new protocol type; an enum constant added in a branch merge but the factory not updated.

Related errors


AI-assisted analysis of YunaiV/ruoyi-vue-pro@0418084e22 (2026-08-14). Data as JSON: /api/errors/49646f9abb76b544. Report an issue: GitHub.