Skip to content

Fix NetBeans launch failure on unix shell for arguments with quotes et al#7908

Open
sid-srini wants to merge 1 commit into
apache:masterfrom
sid-srini:fix_nb_fails_launch_args_with_quotes
Open

Fix NetBeans launch failure on unix shell for arguments with quotes et al#7908
sid-srini wants to merge 1 commit into
apache:masterfrom
sid-srini:fix_nb_fails_launch_args_with_quotes

Conversation

@sid-srini
Copy link
Copy Markdown
Contributor

@sid-srini sid-srini commented Oct 24, 2024

Issue

When NetBeans is launched on *nix shell with arguments that contain special characters like quotes, spaces, $ and backticks, then it may fail or not receive the arguments correctly.

The launcher scripts are:

  • java/java.lsp.server/script/bin/nbcode
  • platform/o.n.bootstrap/launcher/unix/nbexec

The cause is due to incomplete escaping of the special characters before quoting the argument.
Examples:

  • --jdkhome "$HOME/openjdk's jdkhome"
  • --jdkhome '/home/user/tools/jdk "23"'
  • --jdkhome /c/Program\ Files/Java/jdk
    • EDIT: values with spaces alone is not a problem with the IDE launcher.
  • --userdir "/mnt/user's macbook pro/Users/user/Library/Application Support/NetBeans"
  • -Dnetbeans.extra.dirs="nb-dev\$old/extras/plugin1:nb-dev\$old/extras/plugin2:ext/My Plugins/quo\"'d"

Further, a discrepancy is created between the argument strings passed on a Windows host (using the launcher exe/dll) and *nix hosts.

Fix

  1. Ensure that all arguments are quoted before passing forward to the executable launch.
    • This is implemented similar to other open-source build tools.
    • Example: ant
  2. Ensure that the special characters ' " $ ` in the argument are escaped according to the quoting being performed.
  3. Consistently use eval with arguments single-quoted and parameter substitution within it being double-quoted.
    • This makes nbexec similar to the nbcode script
  4. Updated the unit test for nbexec.

@mbien mbien added LSP [ci] enable Language Server Protocol tests Platform [ci] enable platform tests (platform/*) ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) labels Oct 24, 2024
@mbien mbien requested a review from neilcsmith-net October 24, 2024 14:40
@sid-srini
Copy link
Copy Markdown
Contributor Author

@neilcsmith-net - Please review this PR whenever its possible for you, and provide any suggestions for it. Thank you.

@sid-srini
Copy link
Copy Markdown
Contributor Author

@neilcsmith-net, @mbien - Please review this PR whenever earliest its possible for you, along with any suggestions for improvement. Thank you.

@sid-srini sid-srini force-pushed the fix_nb_fails_launch_args_with_quotes branch from 283d42c to 00d5835 Compare March 19, 2025 12:47
@sid-srini
Copy link
Copy Markdown
Contributor Author

I've rebased the PR against the current master. Please do trigger CI tests and review this PR. Thank you.
cc: @neilcsmith-net, @mbien, @dbalek, @sdedic.

@sid-srini sid-srini force-pushed the fix_nb_fails_launch_args_with_quotes branch from 00d5835 to 75b98ab Compare August 21, 2025 18:32
@sid-srini
Copy link
Copy Markdown
Contributor Author

I've rebased the PR against the current master. Please do trigger CI tests and review this PR. Thank you.
cc: @neilcsmith-net, @mbien, @dbalek, @sdedic.

@sid-srini sid-srini force-pushed the fix_nb_fails_launch_args_with_quotes branch from 75b98ab to 99bf67b Compare September 8, 2025 11:01
@sid-srini
Copy link
Copy Markdown
Contributor Author

I've rebased the PR against the current master. Please do trigger CI tests and review this PR. Thank you.
cc: @neilcsmith-net, @mbien, @dbalek, @sdedic.

Copy link
Copy Markdown
Contributor

@singh-akhilesh singh-akhilesh left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Copy link
Copy Markdown
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

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

This seems to work for NetBeans IDE. But what makes me nervous is:

  • the problems are not reproducible with the NetBeans IDE with an older master build
  • the NetBeans IDE launcher is missing from the launcher enumeration
  • the problems are not reproduible with the NetBeans IDE with this applied

So what testing was done with the IDE?

@sid-srini
Copy link
Copy Markdown
Contributor Author

sid-srini commented May 13, 2026

Hi @matthiasblaesing. Thanks for taking a look at this. Please find my responses below.

This seems to work for NetBeans IDE. But what makes me nervous is:

  • the problems are not reproducible with the NetBeans IDE with an older master build

I do not know which older master build did not have these problems reproducible. I have seen this for releases since the last 2-3 years.

  • the NetBeans IDE launcher is missing from the launcher enumeration

The NetBeans IDE launcher nb/ide.launcher/unix/netbeans is essentially invoking the launcher script covered in this PR i.e. platform/o.n.bootstrap/launcher/unix/nbexec.

The IDE launcher script is a wrapper that performs basic parsing and addition of some extra platform-specific options to the command-line for nbexec. The IDE launcher uses eval with '"$@"' that will pass forward the user-input arguments literally.

The IDE launcher also utilizes env variable values defined in the IDE's netbeans.conf file which are populated by the build and mostly do not have such problems. A glitch may occur when the user installs NetBeans in a location like the examples given in the PR description, causing basedir to have such a value. Nonetheless, these are more controlled settings unlike the general user input on the command line.

If you prefer similar changes may be added in the wrapper for the default options read from netbeans.conf.

  • the problems are not reproduible with the NetBeans IDE with this applied

So what testing was done with the IDE?

The problems are not reproducible with the NetBeans IDE with this fix applied.

The testing up till now has been done via:

  • the unit tests for nbexec
  • manual tests for launching the IDE on command-line with example test values like those given in the PR description, as well as with some non-problematic values.

One thing to note is that problematic values with only spaces and not any of the other special characters is handled fine by the IDE launch i.e. nbexec, which used to be a problem with the other launcher that has been removed since NB28.

Please let me know what you think. Thanks.

@matthiasblaesing
Copy link
Copy Markdown
Contributor

@sid-srini thanks for your reply. I wanted to ensure that testing was done with the NetBeans IDE. You confirmed that.

I intent to merge this some time next week, so it gets in early in the NB31 cycle and has time to settle should something break.

@mbien mbien added this to the NB31 milestone May 14, 2026
@mbien
Copy link
Copy Markdown
Member

mbien commented May 14, 2026

please rebase before merge. branch is ~8 month old by now.

@matthiasblaesing
Copy link
Copy Markdown
Contributor

@sid-srini @mbien is right, it makes sense to do a rebase before merging. Could you please do so and update the PR to that state?

@sid-srini sid-srini force-pushed the fix_nb_fails_launch_args_with_quotes branch from 99bf67b to 9f6def5 Compare May 19, 2026 10:09
…t al

**Issue**

When NetBeans is launched on *nix shell with arguments that contain
special characters like quotes, spaces, $ and backticks, then it may
fail or not receive the arguments correctly.

The launcher script is:
- platform/o.n.bootstrap/launcher/unix/nbexec

The cause is due to incomplete escaping of the special characters before
quoting the argument.

**Fix**

1. Ensure that all arguments are quoted before passing forward to the
   executable launch.
    - This is implemented similar to other open-source build tools.
    - Example: [ant](https://github.com/apache/ant/blob/master/src/script/ant#L63)
2. Ensure that the special characters ' " $ ` in the argument are
   escaped according to the quoting being performed.
3. Consistently use `eval` with arguments single-quoted and parameter
   substitution within it being double-quoted.
4. Updated the unit test for `nbexec`

Signed-off-by: Siddharth Srinivasan <siddharth.srinivasan@oracle.com>
@sid-srini sid-srini force-pushed the fix_nb_fails_launch_args_with_quotes branch from 9f6def5 to 1c9d385 Compare May 19, 2026 10:11
@sid-srini
Copy link
Copy Markdown
Contributor Author

sid-srini commented May 19, 2026

Thanks @mbien and @matthiasblaesing. I have rebased the branch to the current master which includes the post NB30 sig files etc.

Additional minor changes:

  • I have also added an additional unit test for checking -J options handling.
  • A couple of lines that were missed in the earlier nbexec changes; specifically setting of netbeans.home property and in look_for_new_clusters(), which would not impact a NetBeans IDE installation location that is currently supported.

Please re-run the CI tests and re-review this PR before proceeding to merge. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:dev-build [ci] produce a dev-build zip artifact (7 days expiration, see link on workflow summary page) LSP [ci] enable Language Server Protocol tests Platform [ci] enable platform tests (platform/*)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants