{"record":{"id":"a623d617aea43012","repo":"karatelabs/karate","slug":"pool-size-must-be-at-least-1","errorCode":null,"errorMessage":"Pool size must be at least 1","messagePattern":"Pool size must be at least 1","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"karate-core/src/main/java/io/karatelabs/driver/PooledDriverProvider.java","lineNumber":93,"sourceCode":"    private volatile boolean shutdown = false;\n\n    /**\n     * Create a pooled driver provider with auto-detected pool size.\n     * Pool size will match the Suite's parallelism (threadCount).\n     */\n    public PooledDriverProvider() {\n        // Pool size auto-detected on first acquire()\n    }\n\n    /**\n     * Create a pooled driver provider with explicit pool size.\n     * Use this when you need to override the auto-detected size.\n     *\n     * @param poolSize maximum number of drivers to create\n     */\n    public PooledDriverProvider(int poolSize) {\n        if (poolSize < 1) {\n            throw new IllegalArgumentException(\"Pool size must be at least 1\");\n        }\n        this.poolSize = poolSize;\n        this.availableDrivers = new ArrayBlockingQueue<>(poolSize);\n    }\n\n    @Override\n    public Driver acquire(ScenarioRuntime runtime, Map<String, Object> config) {\n        if (shutdown) {\n            throw new IllegalStateException(\"Provider has been shut down\");\n        }\n\n        // Initialize pool lazily with auto-detected size\n        ensurePoolInitialized(runtime);\n\n        // Check if this scenario already has a driver assigned (shouldn't happen normally)\n        Driver existing = assignedDrivers.get(runtime);\n        if (existing != null && !existing.isTerminated()) {\n            logger.debug(\"Returning existing driver for scenario: {}\", runtime.getScenario().getName());","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/karatelabs/karate/blob/a22eb90246d958d15a47bf436693d0121ad2812d/karate-core/src/main/java/io/karatelabs/driver/PooledDriverProvider.java#L75-L111","documentation":"The PooledDriverProvider constructor validates its pool size; a value below 1 cannot hold even one driver and would make the pool unusable, so it throws IllegalArgumentException immediately at construction time.","triggerScenarios":"Constructing new PooledDriverProvider(0) or with a negative value, e.g. from a misconfigured karate.driver.pool-size property parsed as 0, or code computing the size from an empty config/count.","commonSituations":"Typo'd or missing config keys defaulting to 0, integer parsing of blank settings, programmatic pool setup with a size derived from data (e.g. number of scenarios) that was empty.","solutions":["Pass an explicit pool size >= 1 (commonly the expected parallelism)","Fix the config source so the pool-size property resolves to a positive integer","Clamp computed sizes: Math.max(1, computedSize)"],"exampleFix":"// before\nint size = Integer.parseInt(cfg.get(\"pool-size\")); // \"\" -> NumberFormatException/0\nnew PooledDriverProvider(size);\n// after\nint size = Math.max(1, Integer.parseInt(cfg.getOrDefault(\"pool-size\", \"4\")));\nnew PooledDriverProvider(size);","handlingStrategy":"validation","validationCode":"int size = Integer.parseInt(System.getProperty(\"karate.driver.pool-size\", \"4\"));\nif (size < 1) throw new IllegalArgumentException(\"pool size must be >= 1, got \" + size);\nPooledDriverProvider pool = new PooledDriverProvider(size);","typeGuard":null,"tryCatchPattern":"try {\n    pool = new PooledDriverProvider(configuredSize);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"Pool size\")) {\n        pool = new PooledDriverProvider(Math.max(1, configuredSize));\n    } else { throw e; }\n}","preventionTips":["Clamp computed sizes with Math.max(1, n)","Validate pool-size config at startup","Never derive pool size from possibly-empty collections without a default"],"tags":["driver","pool","configuration"],"backgroundTag":"invalid-argument-value","analyzedSha":"a22eb90246d958d15a47bf436693d0121ad2812d","analyzedAt":"2026-09-12T09:01:00.220Z","contentChangedAt":"2026-09-12T09:01:00.220Z","schemaVersion":2},"datasetVersion":"2026-09-16T19:17:19.609Z"}