{"record":{"id":"58ee2e3d8b98f9c4","repo":"Tencent/APIJSON","slug":"query-value-value-0-1-2-tabl","errorCode":null,"errorMessage":"{}/query:value 中 value 的值不合法！必须在 [0, 1, 2] 或 [TABLE, TOTAL, ALL] 内 !","messagePattern":"(.+?)/query:value 中 value 的值不合法！必须在 \\[0, 1, 2\\] 或 \\[TABLE, TOTAL, ALL\\] 内 !","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"APIJSONORM/src/main/java/apijson/orm/AbstractParser.java","lineNumber":1363,"sourceCode":"\t\tif (query == null) {\n\t\t\tquery2 = apijson.JSONRequest.QUERY_TABLE;\n\t\t}\n\t\telse {\n\t\t\tswitch (query) {\n\t\t\tcase \"0\":\n\t\t\tcase apijson.JSONRequest.QUERY_TABLE_STRING:\n\t\t\t\tquery2 = apijson.JSONRequest.QUERY_TABLE;\n\t\t\t\tbreak;\n\t\t\tcase \"1\":\n\t\t\tcase apijson.JSONRequest.QUERY_TOTAL_STRING:\n\t\t\t\tquery2 = apijson.JSONRequest.QUERY_TOTAL;\n\t\t\t\tbreak;\n\t\t\tcase \"2\":\n\t\t\tcase apijson.JSONRequest.QUERY_ALL_STRING:\n\t\t\t\tquery2 = apijson.JSONRequest.QUERY_ALL;\n\t\t\t\tbreak;\n\t\t\tdefault:\n\t\t\t\tthrow new IllegalArgumentException(path + \"/\" + apijson.JSONRequest.KEY_QUERY + \":value 中 value 的值不合法！必须在 [0, 1, 2] 或 [TABLE, TOTAL, ALL] 内 !\");\n\t\t\t}\n\t\t}\n\n\t\tint minPage = getMinQueryPage(); // 兼容各种传 0 或 null/undefined 自动转 0 导致的问题\n\t\tint page2 = page == null || page == 0 ? 0 : page - minPage;\n\n\t\tint maxPage = getMaxQueryPage();\n\t\tif (page2 < 0 || page2 > maxPage) {\n\t\t\tthrow new IllegalArgumentException(path + \"/\" + apijson.JSONRequest.KEY_PAGE + \":value 中 value 的值不合法！必须在 \" + minPage + \"-\" + maxPage + \" 内 !\");\n\t\t}\n\n\t\t//不用total限制数量了，只用中断机制，total只在query = 1,2的时候才获取\n\t\tint count2 = isSubquery || count != null ? (count == null ? 0 : count) : getDefaultQueryCount();\n\t\tint max = isSubquery ? count2 : getMaxQueryCount();\n\n\t\tif (count2 < 0 || count2 > max) {\n\t\t\tthrow new IllegalArgumentException(path + \"/\" + apijson.JSONRequest.KEY_COUNT + \":value 中 value 的值不合法！必须在 0-\" + max + \" 内 !\");\n\t\t}","sourceCodeStart":1345,"sourceCodeEnd":1381,"githubUrl":"https://github.com/Tencent/APIJSON/blob/5284052872898eddc449a58f629e5c8d588b8e22/APIJSONORM/src/main/java/apijson/orm/AbstractParser.java#L1345-L1381","documentation":"Inside []:{}, the query parameter selects what to fetch. Only 0/TABLE, 1/TOTAL, 2/ALL (or their string names) are accepted; the switch's default branch throws IllegalArgumentException naming the path and the allowed sets. query2 is then used to decide whether to also fetch the total count.","triggerScenarios":"{\"[]\":{\"query\":3,...}} or query:\"TOTALS\"/\"tables\"/true/1.0 — anything outside 0,1,2 and TABLE,TOTAL,ALL (case per constants). Sending query as a non-matching string hits default.","commonSituations":"Typos or pluralized names; using an integer as string with decimals; copying query from another framework's dialect; version change where new modes were expected but the deployed jar is older.","solutions":["Set query to 0/TABLE, 1/TOTAL, or 2/ALL exactly as documented","If you need both rows and total, use query:2 (ALL)","Validate the value client-side against the enum before sending","Check the APIJSON version's JSONRequest constants for the exact accepted spellings"],"exampleFix":"// before\n{\"[]\":{\"query\":\"TABLES\",\"User\":{}}}\n// after\n{\"[]\":{\"query\":2,\"User\":{}}}","handlingStrategy":"validation","validationCode":"Set<Object> OK = Set.of(0,1,2,\"0\",\"1\",\"2\",\"TABLE\",\"TOTAL\",\"ALL\");\nif (!OK.contains(query)) throw new IllegalArgumentException(\"bad query: \" + query);","typeGuard":"boolean isValidQueryValue(Object q) {\n  return q == null || Set.of(0,1,2,\"TABLE\",\"TOTAL\",\"ALL\").contains(q);\n}","tryCatchPattern":null,"preventionTips":["Expose query as an enum client-side so invalid values cannot be constructed","Pin the accepted spellings from JSONRequest constants of your deployed version","Omit query entirely when default TABLE behavior suffices"],"tags":["apijson","query-param","validation","pagination"],"backgroundTag":null,"analyzedSha":"5284052872898eddc449a58f629e5c8d588b8e22","analyzedAt":"2026-08-14T15:15:29.577Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}