{"record":{"id":"9931320fbf373ef8","repo":"chinabugotech/hutool","slug":"bad-expression-we-find-but-no-993132","errorCode":null,"errorMessage":"Bad expression '{}':{}, we find '[' but no ']' !","messagePattern":"Bad expression '(.+?)':(.+?), we find '\\[' but no '\\]' !","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"hutool-core/src/main/java/cn/hutool/core/bean/BeanPath.java","lineNumber":350,"sourceCode":"\t\t\tif ('\\'' == c) {\n\t\t\t\t// 结束\n\t\t\t\tisInWrap = (false == isInWrap);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tif (false == isInWrap && ArrayUtil.contains(EXP_CHARS, c)) {\n\t\t\t\t// 处理边界符号\n\t\t\t\tif (CharUtil.BRACKET_END == c) {\n\t\t\t\t\t// 中括号（数字下标）结束\n\t\t\t\t\tif (false == isNumStart) {\n\t\t\t\t\t\tthrow new IllegalArgumentException(StrUtil.format(\"Bad expression '{}':{}, we find ']' but no '[' !\", expression, i));\n\t\t\t\t\t}\n\t\t\t\t\tisNumStart = false;\n\t\t\t\t\t// 中括号结束加入下标\n\t\t\t\t} else {\n\t\t\t\t\tif (isNumStart) {\n\t\t\t\t\t\t// 非结束中括号情况下发现起始中括号报错（中括号未关闭）\n\t\t\t\t\t\tthrow new IllegalArgumentException(StrUtil.format(\"Bad expression '{}':{}, we find '[' but no ']' !\", expression, i));\n\t\t\t\t\t} else if (CharUtil.BRACKET_START == c) {\n\t\t\t\t\t\t// 数字下标开始\n\t\t\t\t\t\tisNumStart = true;\n\t\t\t\t\t}\n\t\t\t\t\t// 每一个边界符之前的表达式是一个完整的KEY，开始处理KEY\n\t\t\t\t}\n\t\t\t\tif (builder.length() > 0) {\n\t\t\t\t\tlocalPatternParts.add(builder.toString());\n\t\t\t\t}\n\t\t\t\tbuilder.setLength(0);\n\t\t\t} else {\n\t\t\t\t// 非边界符号，追加字符\n\t\t\t\tbuilder.append(c);\n\t\t\t}\n\t\t}\n\n\t\t// 末尾边界符检查\n\t\tif (isNumStart) {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/chinabugotech/hutool/blob/8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442/hutool-core/src/main/java/cn/hutool/core/bean/BeanPath.java#L332-L368","documentation":"The same parser rejects a second '[' while a previous '[' is still open (isNumStart already true), i.e. a nested/overlapping bracket that the simple index grammar does not allow. BeanPath supports single-level numeric indices like a[0], not a[0[1]]. This branch is reached when a boundary char is found and isNumStart is already true.","triggerScenarios":"Paths like \"a[0[1]]\", \"a[[0]]\", or \"a[0][\" where a second '[' appears before the first index closes. Also any boundary EXP_CHAR encountered mid-index.","commonSituations":"Trying to express multi-dimensional arrays with nested brackets (BeanPath uses chained [i][j] instead); malformed generated paths.","solutions":["Use chained single-level indices: a[0][1] rather than a[0[1]].","Verify each '[' is immediately followed by digits then ']'.","Generate paths from a structured builder rather than string concatenation."],"exampleFix":"// before\nBeanPath p = new BeanPath(\"matrix[0[1]]\");\n// after\nBeanPath p = new BeanPath(\"matrix[0][1]\");","handlingStrategy":"validation","validationCode":"if (path.indexOf('[') != path.lastIndexOf('[') && path.replaceAll(\"[^\\\\[]\",\"\").length() != path.replaceAll(\"[^\\\\]]\",\"\").length()) throw new IllegalArgumentException(\"nested/unbalanced brackets: \" + path);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use chained [i][j] for multi-dimensional access, never [i[j]].","Unit-test generated paths against BeanPath construction."],"tags":["bean-path","parser","argument-validation"],"backgroundTag":null,"analyzedSha":"8870454b2a0c29cc6ffd31dcf5667c8ceb2fc442","analyzedAt":"2026-08-14T04:01:12.892Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}