[2.x] fix: sbt --client fails if -mem is provided#8831
Merged
eed3si9n merged 2 commits intosbt:developfrom Mar 5, 2026
Merged
Conversation
Contributor
Author
|
@eed3si9n This is ready for review. All tests pass and formatting checks are clean. Let me know if you'd like any changes. |
Member
|
Hi, thanks for the contribution! Please check out our Contributor's Guildeline and:
Here's how to build sbtn locally: $ sbt nativeImage
# or on ARM macOS
$ ARCHS=arm64 sbt nativeImage |
eed3si9n
requested changes
Feb 28, 2026
The bash launcher's runNativeClient() passed all original CLI args to sbtn, only stripping --client. This caused sbtn to receive launcher flags like -mem 10000, which NetworkClient.parseArgs() misclassified: -mem went to sbtArguments and 10000 went to commandArgs, resulting in a broken server start command. Fix runNativeClient() to use an allowlist: only forward -D* properties, -bsp, --sbt-launch-jar, and sbt commands to sbtn. All launcher-specific flags (-mem, -jvm-debug, -java-home, -batch, -debug, etc.) are skipped. As defense-in-depth, add launcher flag filtering to NetworkClient.parseArgs() so that even if launcher flags reach sbtn, they are silently dropped instead of being misclassified.
Move all launcher flag filtering to NetworkClient.parseArgs() so the fix applies uniformly across all launchers (sbt.sh, sbt.bat, sbtw).
d655ffa to
36d49b7
Compare
eed3si9n
pushed a commit
to eed3si9n/sbt
that referenced
this pull request
Mar 23, 2026
The bash launcher's runNativeClient() passed all original CLI args to sbtn, only stripping --client. This caused sbtn to receive launcher flags like -mem 10000, which NetworkClient.parseArgs() misclassified: -mem went to sbtArguments and 10000 went to commandArgs, resulting in a broken server start command.
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 #6825
Summary
sbt -mem 10000 -clientfails because launcher-only flags leak through to the native thin client (sbtn), which doesn't understand them.Problem
runNativeClient()in the bash launcher only strips--clientand forwards everything else to sbtn. Sosbtnreceives-mem 10000, andNetworkClient.parseArgs()misclassifies them:-memgoes tosbtArguments,10000goes tocommandArgs. The server start command becomessbt -mem --detach-stdio --server, which fails because-memhas no value.Solution
1. Bash launcher (
sbt): allowlist-based arg forwardingReplace the naive
--clientstripping inrunNativeClient()with an allowlist loop. Only-D*properties,-bsp,--sbt-launch-jar, and non-flag command args are forwarded to sbtn. All launcher-specific flags are categorized and skipped:-mem,-jvm-debug,-java-home, etc.): skip flag + next arg--client,-batch,-debug, etc.): skip flag--supershell=false,--color=never): skip-J*JVM flags: skip2. Defense-in-depth in
NetworkClient.parseArgs()Added matching launcher flag sets and corresponding match cases so that even if launcher flags somehow reach sbtn, they are silently dropped instead of being misclassified as sbt arguments or commands.
3. Unit tests for
NetworkClient.parseArgs()18 test cases covering:
-mem 10000,-jvm-debug 5005,-java-home /path)--client,-debug,-batch,-allow-empty)--supershell=false,--color=never)-J*JVM flags-Dfoo=bar,-bsp,--sbt-launch-jar,--sbt-script)Test results
sbt commandProj/test— 38/38 pass:Verification
sbt commandProj/compilepassessbt commandProj/test— 38/38 passsbt scalafmtCheckAllpassessbt scalafmtSbtCheckpassesGenerated-by: Claude Code (claude.ai/code)