{"record":{"id":"79dd8fb2d05c4dd0","repo":"elastic/elasticsearch","slug":"sysprop-property-must-be-true-or-false-bu","errorCode":null,"errorMessage":"Sysprop [${property}] must be [true] or [false] but was [${propertyValue}]","messagePattern":"Sysprop \\[(.+?)\\] must be \\[true\\] or \\[false\\] but was \\[(.+?)\\]","errorType":"exception","errorClass":"GradleException","httpStatus":null,"severity":"error","filePath":"build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java","lineNumber":42,"sourceCode":"import java.io.File;\nimport java.util.Optional;\nimport java.util.function.Supplier;\n\nimport javax.annotation.Nullable;\n\npublic class Util {\n\n    public static boolean getBooleanProperty(String property, boolean defaultValue) {\n        String propertyValue = System.getProperty(property);\n        if (propertyValue == null) {\n            return defaultValue;\n        }\n        if (\"true\".equals(propertyValue)) {\n            return true;\n        } else if (\"false\".equals(propertyValue)) {\n            return false;\n        } else {\n            throw new GradleException(\"Sysprop [\" + property + \"] must be [true] or [false] but was [\" + propertyValue + \"]\");\n        }\n    }\n\n    /**\n     * @param project The project to look for resources.\n     * @param filter  Optional filter function to filter the returned resources\n     * @return Returns the {@link FileTree} for main resources from Java projects. Returns null if no files exist.\n     */\n    @Nullable\n    public static FileTree getJavaMainSourceResources(Project project, Action<? super PatternFilterable> filter) {\n        final Optional<FileTree> mainFileTree = getJavaMainSourceSet(project).map(SourceSet::getResources).map(FileTree::getAsFileTree);\n        return mainFileTree.map(files -> files.matching(filter)).orElse(null);\n    }\n\n    /**\n     * @param project The project to look for resources.\n     * @param filter  Optional filter function to filter the returned resources\n     * @return Returns the {@link FileTree} for test resources from Java projects. Returns null if no files exist.","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-conventions/src/main/java/org/elasticsearch/gradle/internal/conventions/util/Util.java#L24-L60","documentation":"Util.getBooleanProperty reads a Java system property and only accepts the canonical strings \"true\" and \"false\"; unset falls back to the default. Anything else — yes, no, 1, 0, TRUE, empty — throws a GradleException naming the property and the bad value. This guards build switches against silent truthy/falsy coercion.","triggerScenarios":"Calling Util.getBooleanProperty(name, default) while -D<name> is set to a non-canonical boolean string. Common call sites in this repo read feature-flag and behaviour sysprops during configuration.","commonSituations":"A CI matrix exporting booleans as 1/0 or yes/no that get mapped verbatim onto the sysprop; a wrapper script uppercasing values; a user passing -Dfoo=True expecting case-insensitivity.","solutions":["Set the property to exactly true or false.","Leave it unset to take the default.","Fix the upstream env-to-sysprop mapping to canonicalise before passing to Gradle."],"exampleFix":"// before\n./gradlew build -Dtests.leaks=1\n// after\n./gradlew build -Dtests.leaks=true","handlingStrategy":"validation","validationCode":"static boolean canonicalBoolean(String property, boolean defaultValue) {\n    String v = System.getProperty(property);\n    if (v == null) return defaultValue;\n    if (\"true\".equals(v)) return true;\n    if (\"false\".equals(v)) return false;\n    throw new GradleException(\"Sysprop [\" + property + \"] must be [true] or [false] but was [\" + v + \"]\");\n}","typeGuard":"static boolean isCanonicalBoolean(String s) {\n    return \"true\".equals(s) || \"false\".equals(s);\n}","tryCatchPattern":null,"preventionTips":["Canonicalise env-supplied booleans to true/false before passing as -D sysprops.","Document each supported sysprop and its allowed values in your build README.","Leave the property unset rather than passing empty strings."],"tags":["gradle","build-config","validation","system-property"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}