{"record":{"id":"ac2c82806be2153c","repo":"theonedev/onedev","slug":"file-query-is-too-general-term","errorCode":null,"errorMessage":"File query is too general: ${term}","messagePattern":"File query is too general: (.+?)","errorType":"validation","errorClass":"TooGeneralQueryException","httpStatus":406,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/search/code/query/FileQueryOption.java","lineNumber":58,"sourceCode":"\t\treturn term;\n\t}\n\n\tpublic boolean isCaseSensitive() {\n\t\treturn caseSensitive;\n\t}\n\n\tpublic void applyConstraints(BooleanQuery.Builder builder) {\n\t\tPreconditions.checkNotNull(term);\n\t\t\n\t\tboolean tooGeneral = true;\n\t\tfor (char ch: term.toCharArray()) {\n\t\t\tif (ch != '?' && ch != '*' && ch != ',' && ch != '.') {\n\t\t\t\ttooGeneral = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (tooGeneral)\n\t\t\tthrow new TooGeneralQueryException(\"File query is too general: \" + term);\n\n\t\tbuilder.add(new WildcardQuery(new Term(BLOB_NAME.name(), term.toLowerCase())), BooleanClause.Occur.MUST);\n\t}\n\n\t@Nullable\n\tpublic Optional<LinearRange> matches(String blobName, @Nullable String excludeFileName) {\n\t\tPreconditions.checkNotNull(term);\n\t\t\n\t\tvar normalizedTerm = term;\n\t\tvar normalizedBlobName = blobName;\n\t\tvar normalizedExcludeFileName = excludeFileName;\n\t\tif (!caseSensitive) {\n\t\t\tnormalizedBlobName = normalizedBlobName.toLowerCase();\n\t\t\tnormalizedTerm = normalizedTerm.toLowerCase();\n\t\t\tif (normalizedExcludeFileName != null)\n\t\t\t\tnormalizedExcludeFileName = normalizedExcludeFileName.toLowerCase();\n\t\t}\n\t\tif (WildcardUtils.matchString(normalizedTerm, normalizedBlobName)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/search/code/query/FileQueryOption.java#L40-L76","documentation":"FileQueryOption.applyConstraints builds a Lucene wildcard query over blob names for code file searches. If the term consists only of wildcard/separator characters ('?', '*', ',', '.') with no real literal characters, matching would scan everything, so TooGeneralQueryException is thrown to protect the index from a degenerate query.","triggerScenarios":"Creating a FileQueryOption with a term like '*', '??', '*.*' (only wildcards and dots/commas, no letters/digits) and applying it during a code file search, either programmatically or via the code search UI.","commonSituations":"User types '*' or '*.*' into the file-name code search box; a saved search contains only wildcards; programmatic search built from user input without pre-validation.","solutions":["Include at least one literal character (letter or digit) in the search term, e.g. '*.java' instead of '*.*'.","Validate the term client-side before submitting: reject terms matching ^[?*,.]+$ .","Catch TooGeneralQueryException in the search entry point and show a 'query too general' message."],"exampleFix":"// before\nnew FileQuery().withOption(new FileQueryOption(\"*.*\", false));\n// after\nnew FileQuery().withOption(new FileQueryOption(\"*.java\", false));","handlingStrategy":"validation","validationCode":"if (term == null || term.matches(\"[?*,.]+\"))\n    throw new IllegalArgumentException(\"File search term needs at least one literal character\");","typeGuard":"boolean isUsableFileTerm(String term) {\n    return term != null && term.chars().anyMatch(c -> \"?*,.\".indexOf(c) < 0);\n}","tryCatchPattern":"try {\n    query = new FileQuery().withOption(new FileQueryOption(term, caseSensitive));\n} catch (TooGeneralQueryException e) {\n    return Result.error(\"File query too general: \" + term);\n}","preventionTips":["Require at least one alphanumeric character in file search terms","Keep wildcard + extension in the term (e.g. '*.java') rather than bare wildcards","Validate search terms in UI before submission"],"tags":["lucene","code-search","validation"],"backgroundTag":"invalid-query-parameter","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}