Skip to content

[2.x] fix: Handle JVM parameters with spaces in dot files#8730

Merged
eed3si9n merged 3 commits intosbt:developfrom
Eruis2579:fix/7333-sbtopts-spaces
Feb 14, 2026
Merged

[2.x] fix: Handle JVM parameters with spaces in dot files#8730
eed3si9n merged 3 commits intosbt:developfrom
Eruis2579:fix/7333-sbtopts-spaces

Conversation

@Eruis2579
Copy link
Copy Markdown
Contributor

@Eruis2579 Eruis2579 commented Feb 11, 2026

Fixes #7333

Problem

The sbt launcher script used naive word splitting when parsing .sbtopts and .jvmopts, so arguments with spaces were split incorrectly. For example, -J--add-modules jdk.incubator.concurrent in .sbtopts and -Dtest.key="value with spaces" in .jvmopts were not passed to the JVM as intended.

Solution

Parsing was updated to be quote-aware. A new parseLineIntoWords() helper splits lines while respecting single and double quotes. loadConfigFileIntoArray() loads config files into bash arrays: for -J lines it splits the remainder and prepends -J to each token (e.g. -J--add-modules jdk.incubator.concurrent-J--add-modules and -Jjdk.incubator.concurrent); for other lines it uses quote-aware splitting. .sbtopts now uses loadConfigFileIntoArray instead of loadConfigFile; .jvmopts uses loadConfigFileIntoArray and merges the result into java_args instead of appending via JAVA_OPTS string concatenation.

Testing

Two integration tests were added in RunnerScriptTest.scala: one for -J--add-modules jdk.incubator.concurrent in .sbtopts, and one for -Dtest.7333="value with spaces" in .jvmopts, both verifying that the full values are passed correctly to the JVM.

@Eruis2579 Eruis2579 force-pushed the fix/7333-sbtopts-spaces branch from 9a26d61 to e3ed1a1 Compare February 13, 2026 18:19
@Eruis2579 Eruis2579 requested a review from eed3si9n February 13, 2026 18:43
@Eruis2579
Copy link
Copy Markdown
Contributor Author

Hi, @eed3si9n , Please check my updates if you have time. Thank you.

Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@Eruis2579
Copy link
Copy Markdown
Contributor Author

Eruis2579 commented Feb 14, 2026

Hi, @eed3si9n , Thank you for your review. Could you merge this PR?

@eed3si9n eed3si9n changed the title fix: Handle JVM parameters with spaces in sbtopts and jvmopts (#7333) [2.x] fix: Handle JVM parameters with spaces in dot files Feb 14, 2026
@eed3si9n eed3si9n merged commit 921efce into sbt:develop Feb 14, 2026
15 checks passed
eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Feb 14, 2026
**Problem**

The sbt launcher script used naive word splitting when parsing `.sbtopts` and `.jvmopts`, so arguments with spaces were split incorrectly. For example, `-J--add-modules jdk.incubator.concurrent` in `.sbtopts` and `-Dtest.key="value with spaces"` in `.jvmopts` were not passed to the JVM as intended.
eed3si9n added a commit that referenced this pull request Feb 14, 2026
)

**Problem**

The sbt launcher script used naive word splitting when parsing `.sbtopts` and `.jvmopts`, so arguments with spaces were split incorrectly. For example, `-J--add-modules jdk.incubator.concurrent` in `.sbtopts` and `-Dtest.key="value with spaces"` in `.jvmopts` were not passed to the JVM as intended.

Co-authored-by: PandaMan <[email protected]>
njlazzar-su pushed a commit to njlazzar-su/sbt that referenced this pull request Feb 17, 2026
**Problem**
After PR sbt#8730 (commit 921efce), inline comments in .jvmopts and .sbtopts files cause errors.
For example, `--add-opens=java.base/java.util=ALL-UNNAMED # comment` results in:
Error: Could not find or load main class #

The # and everything after it is now parsed as separate arguments instead of being stripped as a comment.

**Solution**
Update the sed command in outputConfigFileTokens() to strip inline comments (everything from # to end of line) before parsing tokens. Changed:
  sed $'/^\#/d;s/\r$//'
To:
  sed $'/^\#/d;s/\s*\#.*//;s/\r$//'

The new s/\s*\#.*// pattern matches optional whitespace + # + rest of line and removes it.

**Testing**
- Added integration test verifying inline comments are stripped from .jvmopts
- Manually tested with .jvmopts containing inline comments - no errors
- Full line comments (starting with #) still work correctly

Generated-by: Claude Sonnet 4.5
eed3si9n pushed a commit that referenced this pull request Feb 17, 2026
)

**Problem**
After PR #8730 (commit 921efce), inline comments in .jvmopts and .sbtopts files cause errors.
For example, `--add-opens=java.base/java.util=ALL-UNNAMED # comment` results in:
Error: Could not find or load main class #

The # and everything after it is now parsed as separate arguments instead of being stripped as a comment.

**Solution**
Update the sed command in outputConfigFileTokens() to strip inline comments (everything from # to end of line) before parsing tokens.

The new s/\s*\#.*// pattern matches optional whitespace + # + rest of line and removes it.

Generated-by: Claude Sonnet 4.5
eed3si9n added a commit to eed3si9n/sbt that referenced this pull request Feb 23, 2026
…t#8730)"

This reverts commit 921efce.
Ref sbt#8767

**Problem**
On Git Bash on Windows, we get a cryptic error Invalid maximum heap size: -Xmx2G.

**Solution**
Revert.
eed3si9n added a commit to eed3si9n/sbt that referenced this pull request Feb 23, 2026
eed3si9n added a commit that referenced this pull request Feb 23, 2026
)" (#8797)

This reverts commit 921efce.
Ref #8767

**Problem**
On Git Bash on Windows, we get a cryptic error Invalid maximum heap size: -Xmx2G.

**Solution**
Revert.
eed3si9n added a commit that referenced this pull request Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sbtopts does not recognize JVM parameters with spaces

2 participants