Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix array indexing and length handling #1274

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ascheman
Copy link

Cf. https://sdkman.slack.com/archives/CJTNQA94M/p1706573532033689?thread_ts=1706516271.626039&cid=CJTNQA94M

  • Array indexing is wrong, it starts at 1 (not 0) and ends at the highest index, not at array length -1. You have both in C or Java, but shell is different.
  • Executed in bash the ${#versions} is - for whatever reason - restricted to four bits. So the maximum value is 15. If the versions array is > 15, you have to use ${#versions[@]} instead (cf. https://linuxhandbook.com/array-length-bash/).
  • a GitHub Issue was opened for this feature / bug.
  • test coverage was added (Cucumber or Spock as appropriate).

NOTE: I have no idea how to provide a Cucumber test for this case. But I am happy to learn about it, in particular how to test the array size in bash if it is > 15. Feel free to get in touch with me about it.

Fixes #1273

Cf. https://sdkman.slack.com/archives/CJTNQA94M/p1706573532033689?thread_ts=1706516271.626039&cid=CJTNQA94M

- Array indexing is wrong, it starts at 1 (not 0) and ends at the
  highest index, not at array length -1. You have both in C or Java,
  but shell is different.
- Executed in bash the `${#versions}` is - for whatever reason -
  restricted to four bits. So the maximum value is 15. If the versions
  array is > 15, you have to use `${#versions[@]}` instead (cf.
  https://linuxhandbook.com/array-length-bash/).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Problems with array indexing and length handling in sdkman-list.sh
1 participant