{"record":{"id":"d77a105833d9afc1","repo":"MyCATApache/Mycat-Server","slug":"sql-d77a10","errorCode":null,"errorMessage":"sql 注释 语法错误","messagePattern":"sql 注释 语法错误","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/util/StringUtil.java","lineNumber":503,"sourceCode":"        } else\n        {\n            sql=oriSql;\n        }\n\t\tint pos = 0;\n\t\tboolean insertFound = false;\n\t\tboolean intoFound = false;\n\t\tint tableStartIndx = -1;\n\t\tint tableEndIndex = -1;\n\t\twhile (pos < sql.length()) {\n\t\t\tchar ch = sql.charAt(pos);\n\t\t\t// 忽略处理注释 /* */ BEN\n\t\t\tif(ch == '/' &&  pos+4 < sql.length() && sql.charAt(pos+1) == '*') {\n\t\t\t\tif(sql.substring(pos+2).indexOf(\"*/\") != -1) {\n\t\t\t\t\tpos += sql.substring(pos+2).indexOf(\"*/\")+4;\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\t// 不应该发生这类情况。\n\t\t\t\t\tthrow new IllegalArgumentException(\"sql 注释 语法错误\");\n\t\t\t\t}\n\t\t\t} else if (ch <= ' ' || ch == '(' || ch=='`') {//\n\t\t\t\tif (tableStartIndx > 0) {\n\t\t\t\t\ttableEndIndex = pos;\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tpos++;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t} else if (ch == 'i' || ch == 'I') {\n\t\t\t\tif (intoFound) {\n\t\t\t\t\tif (tableStartIndx == -1 && ch!='`') {\n\t\t\t\t\t\ttableStartIndx = pos;\n\t\t\t\t\t}\n\t\t\t\t\tpos++;\n\t\t\t\t} else if (insertFound) {// into start\n\t\t\t\t\t// 必须全部都为INTO才认为是into\n\t\t\t\t\tif(pos+5 < sql.length() && (sql.charAt(pos+1) == 'n' || sql.charAt(pos+1) == 'N') && (sql.charAt(pos+2) == 't' || sql.charAt(pos+2) == 'T') && (sql.charAt(pos+3) == 'o' || sql.charAt(pos+3) == 'O') && (sql.charAt(pos+4) <= ' ')) {","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/util/StringUtil.java#L485-L521","documentation":"StringUtil.getTableName scans a SQL string to find the table name, skipping block comments. If it encounters '/*' with no closing '*/' later in the string (a malformed comment), it throws IllegalArgumentException('sql 注释 语法错误' — 'SQL comment syntax error').","triggerScenarios":"Passing SQL whose '/*' comment is never closed, e.g. getTableName(\"select * from t1 /* hint\") — the code detects '*/' is absent and aborts.","commonSituations":"Hand-written hints like /*+index*/ accidentally cut off by string truncation or editors; generated SQL where a comment template failed to close; copy/paste dropping the tail of the query.","solutions":["Close the block comment with '*/' in the SQL string","Replace the unterminated comment with '-- ' line comment or remove it","If SQL comes from a template/log truncation, ensure the full statement is passed to getTableName","Note the scan condition requires pos+4 < sql.length(); very short trailing input can also land here — keep comments well-formed"],"exampleFix":"// before\nString sql = \"select * from t1 /* test\";\n// after\nString sql = \"select * from t1 /* test */\";","handlingStrategy":"validation","validationCode":"static boolean hasBalancedBlockComments(String sql){\n    if (sql == null) return true;\n    int open = 0;\n    for (int i = 0; i < sql.length()-1; i++) {\n        if (sql.startsWith(\"/*\", i)) { open++; i++; }\n        else if (sql.startsWith(\"*/\", i)) { open--; i++; if (open < 0) return false; }\n    }\n    return open == 0;\n}","typeGuard":null,"tryCatchPattern":"try { table = StringUtil.getTableName(sql); }\ncatch (IllegalArgumentException e) { throw new IllegalArgumentException(\"SQL contains unterminated /* comment\", e); }","preventionTips":["Always close /* */ comments, including optimizer hints","Run comment-balance checks on SQL generated from templates","Prefer '--' line comments for quick annotations in scripts","Avoid truncating SQL when copying from logs before parsing"],"tags":["java","sql","parsing"],"backgroundTag":"invalid-argument-format","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}