Skip to content

Commit d83b501

Browse files
committed
fixed a crash when /usr/libexec/java_home returns no JVMs (tofi86#93)
1 parent e9f09c7 commit d83b501

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [Unreleased]
10+
### Fixed
11+
- Fixed a crash when `/usr/libexec/java_home` returns no JVMs (#93)
12+
13+
914
## [3.1.0] - 2021-01-07
1015
### Added
1116
- Support for macOS 11.0 "Big Sur" (#91)

src/universalJavaApplicationStub

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
# #
1212
# @author Tobias Fischer #
1313
# @url https://github.com/tofi86/universalJavaApplicationStub #
14-
# @date 2021-01-07 #
15-
# @version 3.1.0 #
14+
# @date 2021-02-03 #
15+
# @version 3.1.1 #
1616
# #
1717
##################################################################################
1818
# #
@@ -576,15 +576,18 @@ if [ -z "${JAVACMD}" ] || [ ! -x "${JAVACMD}" ] ; then
576576
javaCounter=$(/usr/libexec/PlistBuddy -c "Print" /dev/stdin <<< $javaXml | grep "Dict" | wc -l | tr -d ' ')
577577

578578
# iterate over all Dict entries
579-
for idx in $(seq 0 $((javaCounter - 1)))
580-
do
581-
version=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)
582-
path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)
583-
path+="/bin/java"
584-
allJVMs+=("$version:$path")
585-
done
586-
# unset for loop variables
587-
unset version path
579+
# but only if there are any JVMs at all (#93)
580+
if [ "$javaCounter" -gt "0" ] ; then
581+
for idx in $(seq 0 $((javaCounter - 1)))
582+
do
583+
version=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)
584+
path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)
585+
path+="/bin/java"
586+
allJVMs+=("$version:$path")
587+
done
588+
# unset for loop variables
589+
unset version path
590+
fi
588591

589592
# add SDKMAN! java versions (#95)
590593
if [ -d ~/.sdkman/candidates/java/ ] ; then

0 commit comments

Comments
 (0)