{"record":{"id":"54e60cb9233a9540","repo":"elastic/elasticsearch","slug":"unknown-license-for-license-file","errorCode":null,"errorMessage":"Unknown license for license file: {}","messagePattern":"Unknown license for license file: (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/LicenseAnalyzer.java","lineNumber":155,"sourceCode":"            \"GeoIp-Database-Service\",\n            false,\n            false,\n            Pattern.compile(\n                (\"By using the GeoIP Database Service, you agree to the Elastic GeoIP Database Service Agreement,\\n\"\n                    + \"available at www.elastic.co/elastic-geoip-database-service-terms.\").replaceAll(\"\\\\s+\", \"\\\\\\\\s*\"),\n                Pattern.DOTALL\n            )\n        ) };\n\n    public static LicenseInfo licenseType(File licenseFile) {\n        for (LicenseMatcher matcher : matchers) {\n            boolean matches = matcher.matches(licenseFile);\n            if (matches) {\n                return new LicenseInfo(matcher.identifier(), matcher.spdxLicense, matcher.sourceRedistributionRequired);\n            }\n        }\n\n        throw new IllegalStateException(\"Unknown license for license file: \" + licenseFile);\n    }\n\n    public record LicenseInfo(String identifier, boolean spdxLicense, boolean sourceRedistributionRequired) {}\n\n    private record LicenseMatcher(String identifier, boolean spdxLicense, boolean sourceRedistributionRequired, Pattern pattern) {\n\n        public boolean matches(File licenseFile) {\n            try {\n                String content = Files.readString(licenseFile.toPath()).replaceAll(\"\\\\*\", \" \");\n                return pattern.matcher(content).find();\n            } catch (IOException e) {\n                throw new UncheckedIOException(e);\n            }\n        }\n    }\n}\n","sourceCodeStart":137,"sourceCodeEnd":172,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/precommit/LicenseAnalyzer.java#L137-L172","documentation":"Thrown by LicenseAnalyzer.licenseType(File) when no LicenseMatcher pattern in the hardcoded matchers array matches the given license file's content. The analyzer recognises a fixed set (Apache-2.0, BSD-2/3-Clause, CDDL-1.0/1.1, ICU, MIT, MIT-0, MPL-1.1/2.0, XZ, EPL-2.0, EDL-1.0, LGPL-2.1/3.0, GeoLite, GeoIp-Database-Service). Any dependency whose LICENSE file does not match one of these patterns is rejected so an untracked license cannot slip into the distribution.","triggerScenarios":"A dependency's LICENSE file whose text does not match any of the compiled regex patterns — either it is a genuinely new license, a dual-license variant the patterns miss, or a heavily reformatted boilerplate.","commonSituations":"Adding a new third-party dependency with an unusual license; a license file with reformatted boilerplate (line wrapping, case changes) that breaks the regex; a license not yet in the allowed set (e.g. ISC, Unlicense, BSL); a dependency whose LICENSE file is actually a NOTICE or a custom EULA.","solutions":["Open the offending LICENSE file and compare its text against the closest matcher pattern in LicenseAnalyzer.","If the license is acceptable and missing, add a new LicenseMatcher entry with a regex that matches this file's boilerplate.","If the license is not acceptable for the distribution, remove the dependency.","Re-run dependencyLicenses to confirm the file now resolves."],"exampleFix":"// before: new dep with ISC license -> IllegalStateException\n// after: add a matcher\nnew LicenseMatcher(\"ISC\", true, false,\n    Pattern.compile(\"Permission to use, copy, modify, and.*ISC License.*\", Pattern.DOTALL))","handlingStrategy":"try-catch","validationCode":"// Pre-check: try matching before throwing, and report which license file is unmatched\nfor (File lf : licenseFiles) {\n    boolean matched = Arrays.stream(LicenseAnalyzer.matchers).anyMatch(m -> m.matches(lf));\n    if (!matched) System.err.println(\"Unmatched LICENSE: \" + lf);\n}","typeGuard":null,"tryCatchPattern":"try {\n    LicenseAnalyzer.licenseType(licenseFile);\n} catch (IllegalStateException e) {\n    // add a new LicenseMatcher regex or remove the dependency, then re-run dependencyLicenses\n    throw e;\n}","preventionTips":["When adding a dependency, add its LICENSE file to the licenses dir and confirm dependencyLicenses resolves it.","Keep LicenseMatcher patterns permissive enough to handle minor boilerplate reformatting.","Review any dependency whose license is dual/recursive — pick the most permissive matching one explicitly."],"tags":["gradle","license-check","precommit","dependencies","regex"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}