Repository navigation
Fix DBeaver IndexOutOfBoundsException when a file starts with SET - #3182
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
nedtwigg
enabled auto-merge
November 10, 2026 06:14
nedtwigg
added a commit
to glaforge/spotless
that referenced
this pull request
Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1552.
Problem
Formatting a SQL file that starts with
SET(for example H2'sSET MODE PostgreSQL;) prints a stack trace to stderr:The file still gets formatted, because the exception is caught, but every such file dumps a trace into the build output.
Root cause
SETshares a case withFROM,WHERE,ORDER BYand friends, which all callinsertReturnAndIndent(argList, index, indent - 1)to put a line break before the keyword. When the keyword is the first token,indexis 0. The token at 0 is neither whitespace nor a statement delimiter, soinsertReturnAndIndentlooks at the previous token withargList.get(argIndex - 1), which isget(-1). Thecatch (IndexOutOfBoundsException e)at the bottom of the method then callse.printStackTrace()and returns 0.Fix
In
insertReturnAndIndent, return 0 before looking at the previous token whenargIndex == 0. There is nothing in front of the first token to turn into a line break, so this is the same result the catch block gave, without the exception. The formatted output doesn't change.Tests
DBeaverSQLFormatterStepTest.keywordAtStartOfFileDoesNotThrow, which formatssql/dbeaver/set-mode.dirty(SET MODE PostgreSQL;), checks the output againstset-mode.clean, and asserts nothing was written toSystem.err.mainit fails: stderr contains theIndexOutOfBoundsExceptiontrace above../gradlew :testlib:test --tests 'com.diffplug.spotless.sql.*'(all 5 pass),./gradlew spotlessCheck :lib:spotbugsMain.