Conversation
…anner crash Agent-Logs-Url: https://github.com/1c-syntax/sonar-bsl-plugin-community/sessions/dbfba67b-b20e-4a21-bc5f-4f57190271e2 Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
|
@copilot а что по поводу куска кода из комментария к оригинальной задаче? Саму ошибку подсветки тоже надо поправить |
…ultiline token) Agent-Logs-Url: https://github.com/1c-syntax/sonar-bsl-plugin-community/sessions/98d41071-1921-4dd3-8c68-58e03eb63f95 Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
…nvalid offsets Agent-Logs-Url: https://github.com/1c-syntax/sonar-bsl-plugin-community/sessions/98d41071-1921-4dd3-8c68-58e03eb63f95 Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Нашёл и исправил корневую причину. Проблема в том, что SDBL лексер объединяет Исправление в Проверено на файле |
|
В плагине сонаркуба 1.18.0 (в 1.17.2 не повторяется) поймал похоже #121, тут в чате уже обсуждалось. java.lang.IllegalArgumentException: java.lang.IllegalArgumentException: Unable to highlight file На плагине, собранном из этой ветки, ошибка та же, что и на 1.18.0: 11:48:00.838 ERROR Error during SonarScanner Engine execution 11:48:02.800 DEBUG Java command exited with code 1 |
|
@copilot посмотри комментарии тут и в оригинальном ишузе. Убедись, что все примеры файлов успешно анализируются твоей версией кода |
Adds reproducers from the comments on issue #318 and PR #424: - The full CRM_КлиентыСервер.bsl module attached by @Bazil1c to issue #318, which crashed the scanner on a multiline СГРУППИРОВАТЬ ПО SDBL token. - The ИНДЕКСИРОВАТЬ ПО (INDEX BY) on separate BSL continuation lines scenario reported by @para11ax (ERP 2.5 СтруктураЗаказа module). Both tests fail on the initial commit of this branch and pass with the multiline-token truncation fix, confirming the fix covers every code sample shared in the PR/issue discussion. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes a SonarScanner crash caused by SDBL multi-word keywords being tokenized as a single token containing a newline (e.g., СГРУППИРОВАТЬ ПО split across BSL string-continuation lines), which previously led to invalid highlight ranges.
Changes:
- Truncate multiline token text to the first line before computing highlight ranges in
BSLHighlighter.highlightToken(). - Add a safety net in
BSLHighlighter.saveHighlighting()to catch and log invalid highlight ranges instead of terminating the scan. - Add regression tests and real-world BSL example files covering multiline SDBL keywords and long/tab-indented queries.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/com/github/_1c_syntax/bsl/sonar/BSLHighlighter.java | Prevents invalid ranges from multiline token text; adds exception shielding around highlight emission. |
| src/test/java/com/github/_1c_syntax/bsl/sonar/BSLHighlighterTest.java | Adds regression tests ensuring highlighting does not throw for multiline SDBL tokens and invalid positions. |
| src/test/resources/examples/highlightCrmQuery.bsl | Realistic reproducer with СГРУППИРОВАТЬ / ПО split across lines. |
| src/test/resources/examples/highlightErpIndexByQuery.bsl | Reproducer for ИНДЕКСИРОВАТЬ / ПО split across lines. |
| src/test/resources/examples/highlightLongQuery.bsl | Long/tab-indented query example to ensure highlighting remains stable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } catch (IllegalArgumentException e) { | ||
| LOGGER.error("Unable to highlight file {}", inputFile, e); | ||
| } |
There was a problem hiding this comment.
The catch block logs only the file and emits an ERROR + stacktrace for every invalid token. If a file produces many invalid ranges, this can spam logs and still won’t identify which token/range caused it. Consider including the failing range/token details in the message and/or lowering to WARN/DEBUG or aggregating (e.g., count failures per file and log once).
| @Test | ||
| void testHighlightingWithLongQuery() { | ||
| // given | ||
| context = SensorContextTester.create(Path.of(".")); | ||
| highlighter = new BSLHighlighter(context); | ||
| var fileName = "highlightLongQuery.bsl"; | ||
| var baseDirName = "src/test/resources/examples"; | ||
| var path = Path.of(baseDirName, fileName); | ||
| documentContext = BSLLSBinding.getServerContext().addDocument(path.toUri()); | ||
| BSLLSBinding.getServerContext().rebuildDocument(documentContext); | ||
| inputFile = Tools.inputFileBSL(fileName, Path.of(baseDirName).toFile()); | ||
|
|
||
| // when/then - should not throw even with tabs causing position differences | ||
| assertThatNoException().isThrownBy(() -> | ||
| highlighter.saveHighlighting(inputFile, documentContext) | ||
| ); | ||
| } | ||
|
|
||
| @Test | ||
| void testHighlightingWithMultilineGroupByToken() { | ||
| // given - file with СГРУППИРОВАТЬ ПО (GROUP BY) on separate lines, | ||
| // which the SDBL lexer combines into a single multiline token | ||
| context = SensorContextTester.create(Path.of(".")); | ||
| highlighter = new BSLHighlighter(context); | ||
| var fileName = "highlightCrmQuery.bsl"; | ||
| var baseDirName = "src/test/resources/examples"; | ||
| var path = Path.of(baseDirName, fileName); | ||
| documentContext = BSLLSBinding.getServerContext().addDocument(path.toUri()); | ||
| BSLLSBinding.getServerContext().rebuildDocument(documentContext); | ||
| inputFile = Tools.inputFileBSL(fileName, Path.of(baseDirName).toFile()); | ||
|
|
||
| // when/then - should not throw despite multiline SDBL tokens | ||
| assertThatNoException().isThrownBy(() -> | ||
| highlighter.saveHighlighting(inputFile, documentContext) | ||
| ); | ||
| } |
There was a problem hiding this comment.
The new tests repeat the same setup boilerplate (creating context/highlighter, resolving baseDirName/path, adding & rebuilding the document, building the InputFile). Extracting a small helper (e.g., loadDocumentAndInputFile(fileName)) would reduce duplication and make future repro additions less error-prone.
- S138 (BSLHighlighter.saveHighlighting too long): extract applyHighlighting() helper to shrink the method below the 75-line limit. - S2211 (lambda parameter without explicit type): replace the inline block lambda with a method reference to the new helper. - S5976 (repeated test bodies): collapse the four file-based highlighting tests into a single @ParameterizedTest sourced from @valuesource. Added junit-jupiter-params test dependency. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|



BSLHighlighter.highlightToken()crashes the entire SonarScanner withIllegalArgumentExceptionwhen SDBL multi-word keywords likeСГРУППИРОВАТЬ ПО(GROUP BY) are placed on separate BSL string continuation lines. The SDBL lexer combines these into a single token whose text contains\n, buthighlightToken()computed the end offset using the total codepoint count across all lines — producing an offset that exceeded the first line's actual length.Root cause fix in
highlightToken()Multiline token text is truncated to the first line before computing the highlight range. This correctly highlights
СГРУППИРОВАТЬon its line, whileПОon the next line is highlighted as part of the BSL STRING token.Safety net in
saveHighlighting()Added
@Slf4jand try-catch aroundhighlighting.highlight()— any remaining invalid tokens are logged and skipped instead of terminating the scan. Follows the same pattern established inIssuesLoader.getTextRange().Tests
testHighlightingWithMultilineGroupByToken: Reproducing test using a real-world query from issue comments containingСГРУППИРОВАТЬ ПОon separate linestestSaveHighlightingWithInvalidTokenPosition: Safety net test with a token at an invalid offset, asserting no exception is throwntestHighlightingWithLongQuery: Tab-indented query highlighting test