{"record":{"id":"995f042bc13fc786","repo":"zhisheng17/flink-learning","slug":"unsupported-client-type-cannot-happen","errorCode":null,"errorMessage":"Unsupported client type - cannot happen","messagePattern":"Unsupported client type - cannot happen","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"warning","filePath":"flink-learning-connectors/flink-learning-connectors-flume/src/main/java/com/zhisheng/connectors/flume/utils/FlumeUtil.java","lineNumber":41,"sourceCode":"        switch(clientType.toUpperCase()) {\n            case \"THRIFT\":\n                client = RpcClientFactory.getThriftInstance(hostname, port, batchSize);\n                break;\n            case \"DEFAULT\":\n                client = RpcClientFactory.getDefaultInstance(hostname, port, batchSize);\n                break;\n            case \"DEFAULT_FAILOVER\":\n                props = getDefaultProperties(hostname, port, batchSize);\n                props.put(CLIENT_TYPE_KEY, CLIENT_TYPE_DEFAULT_FAILOVER);\n                client = RpcClientFactory.getInstance(props);\n                break;\n            case \"DEFAULT_LOADBALANCE\":\n                props = getDefaultProperties(hostname, port, batchSize);\n                props.put(CLIENT_TYPE_KEY, CLIENT_TYPE_DEFAULT_LOADBALANCING);\n                client = RpcClientFactory.getInstance(props);\n                break;\n            default:\n                throw new IllegalStateException(\"Unsupported client type - cannot happen\");\n        }\n        return client;\n    }\n\n    public static void destroy(RpcClient client) {\n        if (null != client) {\n            client.close();\n        }\n    }\n\n    private static Properties getDefaultProperties(String hostname, Integer port, Integer batchSize) {\n        Properties props = new Properties();\n        props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS, \"h1\");\n        props.setProperty(RpcClientConfigurationConstants.CONFIG_HOSTS_PREFIX + \"h1\",\n                hostname + \":\" + port.intValue());\n        props.setProperty(RpcClientConfigurationConstants.CONFIG_BATCH_SIZE, batchSize.toString());\n        return props;\n    }","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/zhisheng17/flink-learning/blob/d731cee7618021be56d132cc925102ffff8d75e6/flink-learning-connectors/flink-learning-connectors-flume/src/main/java/com/zhisheng/connectors/flume/utils/FlumeUtil.java#L23-L59","documentation":"FlumeUtil.getRpcClient switches on a client type string and its default branch throws IllegalStateException('Unsupported client type - cannot happen'). It is an internal invariant guard: only the enumerated branches (e.g. DEFAULT_FAILover / DEFAULT_LOADBALANCE) are supposed to be passed, so the default should be unreachable.","triggerScenarios":"Only if getRpcClient is called with a client-type constant outside the handled switch cases — i.e. code modification adding a new type without a matching case, since the public wrapper only passes supported constants.","commonSituations":"Developers extending FlumeUtil with a new RpcClient type but forgetting to add a switch case; refactoring that changes the client type constants.","solutions":["Add a switch case for the new client type before the default branch","Verify no caller passes an unhandled client type constant","If it fires unexpectedly, check that CLIENT_TYPE constants were not renamed inconsistently"],"exampleFix":"// before\ndefault:\n    throw new IllegalStateException(\"Unsupported client type - cannot happen\");\n// after\ncase \"THRIFT\":\n    props = getThriftProperties(hostname, port, batchSize);\n    client = RpcClientFactory.getInstance(props);\n    break;\ndefault:\n    throw new IllegalStateException(\"Unsupported client type - cannot happen\");","handlingStrategy":"try-catch","validationCode":"static boolean isSupportedClientType(String type) {\n    return \"DEFAULT_FAILOVER\".equals(type) || \"DEFAULT_LOADBALANCE\".equals(type);\n}","typeGuard":null,"tryCatchPattern":"try {\n    RpcClient client = FlumeUtil.getRpcClient(hostname, port, batchSize, clientType);\n} catch (IllegalStateException e) {\n    LOG.error(\"Unsupported flume rpc client type: {}\", clientType, e);\n    throw e;\n}","preventionTips":["Only pass the CLIENT_TYPE constants defined in FlumeUtil","When adding a new client type, always extend the switch in getRpcClient","Cover getRpcClient with unit tests parameterized over all supported types"],"tags":["flume","invariant","switch","flink"],"backgroundTag":"internal-invariant-violation","analyzedSha":"d731cee7618021be56d132cc925102ffff8d75e6","analyzedAt":"2026-09-06T05:35:08.496Z","contentChangedAt":"2026-09-06T05:35:08.496Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}