{"record":{"id":"49646f9abb76b544","repo":"YunaiV/ruoyi-vue-pro","slug":"createprotocol-s-s","errorCode":null,"errorMessage":"[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]","messagePattern":"\\[createProtocol\\]\\[协议实例 (.+?) 的协议类型 (.+?) 暂不支持\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/IotProtocolManager.java","lineNumber":122,"sourceCode":"                return createHttpProtocol(config);\n            case TCP:\n                return createTcpProtocol(config);\n            case UDP:\n                return createUdpProtocol(config);\n            case COAP:\n                return createCoapProtocol(config);\n            case WEBSOCKET:\n                return createWebSocketProtocol(config);\n            case MQTT:\n                return createMqttProtocol(config);\n            case EMQX:\n                return createEmqxProtocol(config);\n            case MODBUS_TCP_CLIENT:\n                return createModbusTcpClientProtocol(config);\n            case MODBUS_TCP_SERVER:\n                return createModbusTcpServerProtocol(config);\n            default:\n                throw new IllegalArgumentException(String.format(\n                        \"[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]\", config.getId(), protocolType));\n        }\n    }\n\n    /**\n     * 创建 HTTP 协议实例\n     *\n     * @param config 协议实例配置\n     * @return HTTP 协议实例\n     */\n    private IotHttpProtocol createHttpProtocol(IotGatewayProperties.ProtocolProperties config) {\n        return new IotHttpProtocol(config);\n    }\n\n    /**\n     * 创建 TCP 协议实例\n     *\n     * @param config 协议实例配置","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/YunaiV/ruoyi-vue-pro/blob/0418084e222612af2fc1141f566af454f9236ab1/yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/IotProtocolManager.java#L104-L140","documentation":"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.","triggerScenarios":"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.","commonSituations":"Extending the gateway to support a new protocol type; an enum constant added in a branch merge but the factory not updated.","solutions":["Add the missing case branch and a createXxxProtocol(config) factory method in IotProtocolManager.","Add a unit test that iterates every IotProtocolTypeEnum value and asserts createProtocol dispatches without throwing, so future enum additions are caught.","If the protocol type is genuinely unsupported, remove/fix the protocol instance from yudao.gateway.protocols config."],"exampleFix":"// after adding enum value OPC_UA\ncase OPC_UA:\n    return createOpcUaProtocol(config);\n// ...\nprivate IotOpcUaProtocol createOpcUaProtocol(ProtocolProperties config) {\n    return new IotOpcUaProtocol(config);\n}","handlingStrategy":"validation","validationCode":"// validate the configured protocol type is one the manager supports, before start()\nIotProtocolTypeEnum t = IotProtocolTypeEnum.of(config.getProtocol());\nif (t == null) {\n    log.error(\"不支持的协议类型: {}\", config.getProtocol());\n    continue; // or skip this instance\n}\n// (createProtocol's default branch is otherwise unreachable for the current enum)","typeGuard":"// ensure every enum value is handled\nstatic final Set<IotProtocolTypeEnum> SUPPORTED = EnumSet.allOf(IotProtocolTypeEnum.class);\nboolean isSupportedProtocol(IotProtocolTypeEnum t) {\n    return t != null && SUPPORTED.contains(t);\n}","tryCatchPattern":null,"preventionTips":["Add a unit test iterating every IotProtocolTypeEnum value through createProtocol to keep the switch exhaustive.","When adding a new enum value, add its case + factory in the same commit.","Treat a missing protocol type in config as a soft skip (the manager already does this for unknown strings) rather than a hard startup failure."],"tags":["iot","protocol","config","switch"],"backgroundTag":null,"analyzedSha":"0418084e222612af2fc1141f566af454f9236ab1","analyzedAt":"2026-08-14T00:56:18.412Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}