{"record":{"id":"a5722c82b0595a26","repo":"apache/pulsar","slug":"connectionsperbroker-must-be-1","errorCode":null,"errorMessage":"connectionsPerBroker must be >= 1","messagePattern":"connectionsPerBroker must be >= 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"pulsar-client-api-v5/src/main/java/org/apache/pulsar/client/api/v5/config/ConnectionPolicy.java","lineNumber":64,"sourceCode":"    private final ProxyProtocol proxyProtocol;\n    private final BackoffPolicy connectionBackoff;\n\n    private ConnectionPolicy(Duration connectionTimeout,\n                             int connectionsPerBroker,\n                             boolean enableTcpNoDelay,\n                             Duration keepAliveInterval,\n                             Duration connectionMaxIdleTime,\n                             int ioThreads,\n                             int callbackThreads,\n                             String proxyServiceUrl,\n                             ProxyProtocol proxyProtocol,\n                             BackoffPolicy connectionBackoff) {\n        Objects.requireNonNull(connectionTimeout, \"connectionTimeout must not be null\");\n        Objects.requireNonNull(keepAliveInterval, \"keepAliveInterval must not be null\");\n        Objects.requireNonNull(connectionMaxIdleTime, \"connectionMaxIdleTime must not be null\");\n        Objects.requireNonNull(connectionBackoff, \"connectionBackoff must not be null\");\n        if (connectionsPerBroker < 1) {\n            throw new IllegalArgumentException(\"connectionsPerBroker must be >= 1\");\n        }\n        if (ioThreads < 1) {\n            throw new IllegalArgumentException(\"ioThreads must be >= 1\");\n        }\n        if (callbackThreads < 1) {\n            throw new IllegalArgumentException(\"callbackThreads must be >= 1\");\n        }\n        this.connectionTimeout = connectionTimeout;\n        this.connectionsPerBroker = connectionsPerBroker;\n        this.enableTcpNoDelay = enableTcpNoDelay;\n        this.keepAliveInterval = keepAliveInterval;\n        this.connectionMaxIdleTime = connectionMaxIdleTime;\n        this.ioThreads = ioThreads;\n        this.callbackThreads = callbackThreads;\n        this.proxyServiceUrl = proxyServiceUrl;\n        this.proxyProtocol = proxyProtocol;\n        this.connectionBackoff = connectionBackoff;\n    }","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client-api-v5/src/main/java/org/apache/pulsar/client/api/v5/config/ConnectionPolicy.java#L46-L82","documentation":"ConnectionPolicy requires connectionsPerBroker >= 1 because it controls how many TCP connections the client opens to each broker; zero or negative values would prevent any connection from being established. The constructor throws IllegalArgumentException when a smaller value is supplied.","triggerScenarios":"Calling ConnectionPolicy.builder().connectionsPerBroker(0) or a negative number; computing the value from config or a formula that yields 0 (e.g. an empty pool calculation).","commonSituations":"Using 0 as 'unlimited' or 'default' sentinel; parsing an empty/blank config string into 0; a sizing algorithm dividing counts that returns 0 for small workloads.","solutions":["Set connectionsPerBroker to at least 1; omit the call to keep the library default.","Fix the calculation producing 0 and clamp: Math.max(1, value).","Treat 0 in config as 'use default' instead of passing it through."],"exampleFix":"// before\nConnectionPolicy cp = ConnectionPolicy.builder()\n    .connectionsPerBroker(0) // IllegalArgumentException\n    .build();\n\n// after\nConnectionPolicy cp = ConnectionPolicy.builder()\n    .connectionsPerBroker(1)\n    .build();","handlingStrategy":"validation","validationCode":"int c = Math.max(1, configuredConnectionsPerBroker);\nConnectionPolicy cp = ConnectionPolicy.builder().connectionsPerBroker(c).build();","typeGuard":"static boolean isValidConnectionsPerBroker(int v) { return v >= 1; }","tryCatchPattern":"try {\n    cp = ConnectionPolicy.builder().connectionsPerBroker(cfg).build();\n} catch (IllegalArgumentException e) {\n    log.warn(\"Invalid connectionsPerBroker, using default\", e);\n    cp = ConnectionPolicy.builder().build();\n}","preventionTips":["Never pass 0; there is no 'unlimited' semantics for this field - omit it for defaults.","Map missing/blank config to the library default rather than to 0.","Clamp pool-sizing formulas with Math.max(1, ...)."],"tags":["java","configuration","connection","illegal-argument","client-api"],"backgroundTag":"invalid-configuration-value","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}