This repository was archived by the owner on Jul 2, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,7 +37,12 @@ for arg in "$@"; do
3737 esac
3838done
3939
40- cmd=(" ${java_bin} " -jar " ${jar_path} " )
40+ # `jvm_quiet_flags` adds `--sun-misc-unsafe-memory-access=allow` on JDK 23+ to
41+ # silence the noisy "terminally deprecated sun.misc.Unsafe" runtime warnings
42+ # emitted by detekt's bundled kotlinc dependencies on every invocation.
43+ declare -a jvm_flags=()
44+ mapfile -t jvm_flags < <( jvm_quiet_flags " ${java_bin} " )
45+ cmd=(" ${java_bin} " " ${jvm_flags[@]} " -jar " ${jar_path} " )
4146if [ " ${# flags[@]} " -gt 0 ]; then
4247 cmd+=(" ${flags[@]} " )
4348fi
Original file line number Diff line number Diff line change 3838
3939# ktfmt edits files in place when given paths. The default args from
4040# .pre-commit-hooks.yaml are `--kotlinlang-style`. Pre-commit appends file paths.
41- " ${java_bin} " -jar " ${jar_path} " " $@ "
41+ # `jvm_quiet_flags` adds `--sun-misc-unsafe-memory-access=allow` on JDK 23+ to
42+ # silence the noisy "terminally deprecated sun.misc.Unsafe" runtime warnings
43+ # that ktfmt's bundled kotlinc dependencies trigger.
44+ declare -a jvm_flags=()
45+ mapfile -t jvm_flags < <( jvm_quiet_flags " ${java_bin} " )
46+ " ${java_bin} " " ${jvm_flags[@]} " -jar " ${jar_path} " " $@ "
4247status=$?
4348
4449modified=0
Original file line number Diff line number Diff line change 3939# ktlint can auto-fix via --format flag. When invoked with filenames,
4040# it lints them. Combine JAVA_HOME and direct invocation.
4141# The executable is a shell script wrapper around a jar, so we need java.
42- JAVA_HOME=" ${JAVA_HOME:- } " " ${exe_path} " " $@ "
42+ # `jvm_quiet_flags` adds `--sun-misc-unsafe-memory-access=allow` on JDK 23+ via
43+ # JAVA_OPTS, silencing the noisy "terminally deprecated sun.misc.Unsafe"
44+ # runtime warnings that ktlint's bundled kotlinc dependencies trigger.
45+ declare -a quiet_flags=()
46+ java_for_probe=" ${JAVA_HOME: +${JAVA_HOME} / bin/ java} "
47+ java_for_probe=" ${java_for_probe:- java} "
48+ mapfile -t quiet_flags < <( jvm_quiet_flags " ${java_for_probe} " )
49+ extra_java_opts=" ${quiet_flags[*]} "
50+ JAVA_HOME=" ${JAVA_HOME:- } " JAVA_OPTS=" ${JAVA_OPTS:- } ${extra_java_opts} " " ${exe_path} " " $@ "
4351status=$?
4452
4553modified=0
Original file line number Diff line number Diff line change @@ -76,3 +76,21 @@ locate_java() {
7676 printf ' set JAVA_HOME, install JDK 17+ via SDKMAN/Homebrew/apt, or run `sdk install java 17-tem`.\n' >&2
7777 exit 0
7878}
79+
80+ # jvm_quiet_flags: print extra `java` CLI flags that silence noisy "WARNING: A
81+ # terminally deprecated method in sun.misc.Unsafe has been called" output from
82+ # JDK 23+ runtimes. The flag itself (`--sun-misc-unsafe-memory-access=allow`)
83+ # only exists on JDK 23+; calling older JDKs with it aborts with
84+ # "Unrecognized option". So we gate on the detected major version.
85+ #
86+ # Usage:
87+ # read -ra quiet_flags < <(jvm_quiet_flags "${java_bin}")
88+ # "${java_bin}" "${quiet_flags[@]}" -jar "${jar_path}" "$@"
89+ jvm_quiet_flags () {
90+ local java_bin=" ${1:- java} "
91+ local major
92+ major=" $( _java_major_version " ${java_bin} " ) "
93+ if [[ " ${major} " =~ ^[0-9]+$ ]] && (( major >= 23 )) ; then
94+ printf ' %s\n' ' --sun-misc-unsafe-memory-access=allow'
95+ fi
96+ }
You can’t perform that action at this time.
0 commit comments