Skip to content
New issue

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

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

Already on GitHub? # to your account

ktlint prints an error when running with JAVA_TOOL_OPTIONS #1543

Closed
rawilder opened this issue Jul 13, 2022 · 1 comment · Fixed by #1544
Closed

ktlint prints an error when running with JAVA_TOOL_OPTIONS #1543

rawilder opened this issue Jul 13, 2022 · 1 comment · Fixed by #1544

Comments

@rawilder
Copy link
Contributor

Expected Behavior

running ktlint with JAVA_TOOL_OPTIONS set should not produce an error

Observed Behavior

running ktlint with JAVA_TOOL_OPTIONS produces the following error

/usr/local/Cellar/ktlint/0.46.1/libexec/ktlint: line 5: [: Picked up JAVA_TOOL_OPTIONS: integer expression expected

Steps to Reproduce

download ktlint
export some JAVA_TOOL_OPTIONS
run ktlint

Your Environment

  • Version of ktlint used: 0.46.1
  • Relevant parts of the .editorconfig settings: n/a
  • Name and version (or code for custom task) of integration used (Gradle plugin, Maven plugin, command line, custom Gradle task): n/a
  • Version of Gradle used (if applicable): n/a
  • Operating System and version: macos 12.3
  • i have JAVA_TOOL_OPTIONS set

Investigation

This seems to be happening from these two lines in the ktlint start

# incorrectly retrieves version
JV=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1)
echo $JV
# echoes 'Picked up JAVA_TOOL_OPTIONS:'
X=$( [ "$JV" -ge "16" ] && echo "--add-opens java.base/java.lang=ALL-UNNAMED" || echo "")
# this command fails because the version is not correctly parsed

Ktlint still runs okay, it just spits some errors in the beginning. This could be solved with a different way to get the java version. Perhaps something with sed or awk to search for the 'version' string instead of head.

@rawilder
Copy link
Contributor Author

#1544

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant