{"record":{"id":"1d52b21ee1bafb1d","repo":"quarkusio/quarkus","slug":"unable-to-parse-query-with-limiting-results-clause","errorCode":null,"errorMessage":"Unable to parse query with limiting results clause. Offending method is ${repositoryMethodDescription}.","messagePattern":"Unable to parse query with limiting results clause\\. Offending method is (.+?)\\.","errorType":"exception","errorClass":"UnableToParseMethodException","httpStatus":null,"severity":"error","filePath":"extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/MethodNameParser.java","lineNumber":125,"sourceCode":"        int minFirstOrTopIndex = Math.min(indexOfOrMaxValue(methodName, \"First\"), indexOfOrMaxValue(methodName, \"Top\"));\n        // 'First' and 'Top' could be part of a field name, so we only consider them as part of a top query\n        // if they are found before 'By'\n        if (minFirstOrTopIndex < byIndex) {\n            if (queryType != QueryType.SELECT) {\n                throw new UnableToParseMethodException(\n                        \"When 'Top' or 'First' is specified, the query must be a find query. Offending method is \"\n                                + repositoryMethodDescription + \".\");\n            }\n            try {\n                String topCountStr = methodName.substring(minFirstOrTopIndex, byIndex)\n                        .replace(\"Top\", \"\").replace(\"First\", \"\");\n                if (topCountStr.isEmpty()) {\n                    topCount = 1;\n                } else {\n                    topCount = Integer.valueOf(topCountStr);\n                }\n            } catch (Exception e) {\n                throw new UnableToParseMethodException(\n                        \"Unable to parse query with limiting results clause. Offending method is \"\n                                + repositoryMethodDescription + \".\");\n            }\n        }\n\n        if (methodName.substring(0, byIndex).contains(\"Distinct\")) {\n            throw new UnableToParseMethodException(\n                    \"Distinct is not yet supported. Offending method is \" + repositoryMethodDescription + \".\");\n        }\n\n        // handle 'AllIgnoreCase'\n        String afterByPart = methodName.substring(byIndex + 2);\n        boolean allIgnoreCase = false;\n        if (afterByPart.contains(ALL_IGNORE_CASE)) {\n            allIgnoreCase = true;\n            afterByPart = afterByPart.replace(ALL_IGNORE_CASE, \"\");\n        }\n","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/spring-data-jpa/deployment/src/main/java/io/quarkus/spring/data/deployment/MethodNameParser.java#L107-L143","documentation":"When First/Top is used in a find method, the text between the First/Top keyword and 'By' must parse as an integer limit (empty means 1). If Integer.valueOf fails — e.g. findTopABCByName — parse() throws UnableToParseMethodException.","triggerScenarios":"`findTopTwoByName`, `findFirst10thBy...` or any non-numeric garbage between Top/First and 'By' in a SELECT derived-query method name.","commonSituations":"Writing limits as words ('TopFive'); typos like 'Top1O' (letter O); leftover characters from renaming; accidental field-name fragment between Top and By.","solutions":["Use a numeric limit: findTop5ByStatus or findFirst10ByName (bare Top/First means 1)","Spell the number as digits immediately after Top/First, nothing else between it and 'By'","If a non-numeric limit expression is needed, switch to @Query with pagination/limit at the call site"],"exampleFix":"// before\nList<User> findTopFiveByStatus(String status);\n// after\nList<User> findTop5ByStatus(String status);","handlingStrategy":"validation","validationCode":"// text between Top/First and 'By' must be empty or a positive integer\nString s = methodName.substring(minIdx, byIndex).replace(\"Top\",\"\").replace(\"First\",\"\");\nif (!s.isEmpty()) Integer.parseInt(s); // throws before build if invalid","typeGuard":null,"tryCatchPattern":"// Build-time failure; use digits:\n// List<User> findTop5ByStatus(String status);","preventionTips":["Write limits as digits: Top5, First10","Omit the number entirely to mean 1 (Top/First alone)","Never put field names or words between Top/First and By"],"tags":["spring-data-jpa","build-time","derived-query","limit"],"backgroundTag":"unparseable-repository-method","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}