{"record":{"id":"9bc61b3dd4ed2078","repo":"apache/maven","slug":"invalid-threads-value-value-must-be-positiv","errorCode":null,"errorMessage":"Invalid threads value: '{}'. Value must be positive.","messagePattern":"Invalid threads value: '(.+?)'\\. Value must be positive\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java","lineNumber":1643,"sourceCode":"\n    int calculateDegreeOfConcurrency(String threadConfiguration) {\n        try {\n            if (threadConfiguration.endsWith(\"C\")) {\n                String str = threadConfiguration.substring(0, threadConfiguration.length() - 1);\n                float coreMultiplier = Float.parseFloat(str);\n\n                if (coreMultiplier <= 0.0f) {\n                    throw new IllegalArgumentException(\"Invalid threads core multiplier value: '\" + threadConfiguration\n                            + \"'. Value must be positive.\");\n                }\n\n                int procs = Runtime.getRuntime().availableProcessors();\n                int threads = (int) (coreMultiplier * procs);\n                return threads == 0 ? 1 : threads;\n            } else {\n                int threads = Integer.parseInt(threadConfiguration);\n                if (threads <= 0) {\n                    throw new IllegalArgumentException(\n                            \"Invalid threads value: '\" + threadConfiguration + \"'. Value must be positive.\");\n                }\n                return threads;\n            }\n        } catch (NumberFormatException e) {\n            throw new IllegalArgumentException(\"Invalid threads value: '\" + threadConfiguration\n                    + \"'. Supported are int and float values ending with C.\");\n        }\n    }\n\n    // ----------------------------------------------------------------------\n    // Properties handling\n    // ----------------------------------------------------------------------\n\n    void populateProperties(\n            CommandLine commandLine, Properties paths, Properties systemProperties, Properties userProperties)\n            throws Exception {\n","sourceCodeStart":1625,"sourceCodeEnd":1661,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/compat/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java#L1625-L1661","documentation":"When the -T / --threads value does not end in 'C', MavenCli.calculateDegreeOfConcurrency() parses it as an integer thread count and requires it to be greater than 0. Values like 0, -2, or 00 throw IllegalArgumentException ('Invalid threads value ... Value must be positive.') during CLI configuration, before any project builds.","triggerScenarios":"mvn -T0, mvn -T-2, mvn -T0x4. Templated command lines like -T${JOBS} where JOBS is 0 (e.g. nproc returning 0 in restricted containers, or a failed arithmetic default), producing the option value 0.","commonSituations":"CI pipelines deriving -T from container CPU counts (nproc/cpu quota) that yield 0 on throttled runners. Scripts defaulting a jobs variable to 0 to mean 'auto'. Renaming a variable so the interpolation becomes empty or 0.","solutions":["Pass a positive integer: -T4, or fall back to 1: -T${JOBS:-1}.","Guard the derived value in your script: JOBS=$(nproc); [ \"$JOBS\" -lt 1 ] && JOBS=1 before building the -T argument.","Prefer the multiplier form -T1C to scale with actual available processors instead of computing counts yourself.","Omit -T for serial builds."],"exampleFix":"# before\nJOBS=$(nproc)   # returns 0 in a cgroup-limited container\nmvn -T${JOBS} package\n\n# after\nJOBS=$(nproc); [ \"$JOBS\" -lt 1 ] && JOBS=1\nmvn -T${JOBS} package","handlingStrategy":"validation","validationCode":"String v = argAfter(args, \"-T\", \"--threads\");\nif (v != null && !v.toUpperCase(Locale.ROOT).endsWith(\"C\")) {\n    int n = Integer.parseInt(v); // NumberFormatException here = your bug, caught in launcher\n    if (n <= 0) throw new IllegalArgumentException(\"-T must be a positive int: \" + v);\n}","typeGuard":null,"tryCatchPattern":"try {\n    mavenCli.doMain(args, ...);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Invalid threads value\")\n            && e.getMessage().contains(\"must be positive\")) {\n        // replace with -T1 (or drop -T) and re-invoke\n    }\n    throw e;\n}","preventionTips":["Clamp derived job counts: JOBS=$(nproc); [ \"$JOBS\" -ge 1 ] || JOBS=1.","Validate numeric CI variables before composing the mvn command line.","Remember -T0 is not 'auto'; omitting -T is the serial default."],"tags":["maven","cli","threads","parallel-build","invalid-value"],"backgroundTag":"invalid-thread-count","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}