Skip to content
This repository has been archived by the owner on Feb 4, 2023. It is now read-only.

Terminating app due to uncaught exception when executing on a Mac where there is no Java #93

Closed
1 of 3 tasks
ampusasidharan opened this issue Oct 20, 2020 · 3 comments
Closed
1 of 3 tasks
Assignees
Labels
Milestone

Comments

@ampusasidharan
Copy link

I'm submitting a bug.

  • bug report
  • feature request
  • other

Short description of the issue/suggestion:
Terminating app due to uncaught exception when executing the app on a Mac where there is no Java (JDK) available.

Steps to reproduce the issue/enhancement:

  1. Execute the app on a Mac with no JDK in the system

What is the expected behavior?
Exception should be handled the with a proper error message

What is the current behavior?
It is failing with below uncaught exception

Unable to find any JVMs matching version "(null)".
No Java runtime present, try --request to install.
Print: Entry, ":0:JVMVersion", Does Not Exist
Print: Entry, ":0:JVMHomePath", Does Not Exist
2020-10-19 11:59:32.898 PlistBuddy[75396:4189457] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFArray objectAtIndex:]: index (-1 (or possibly larger)) beyond bounds (0)'
*** First throw call stack:

Do you have screenshots, GIFs, demos or samples which demonstrate the problem or enhancement?
NA

What is the motivation / use case for changing the behavior?
Executing the app on Mac with no Java

Please tell us about your environment:

  • universalJavaApplicationStub version: 3.1.0-beta
  • Mac OS version: 10.14.6
  • Java version(s): No JDK

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

@tofi86 tofi86 added this to the Version 3.1.1 milestone Jan 7, 2021
@Flexperte
Copy link

Flexperte commented Feb 3, 2021

It's the for loop on line 579:
# iterate over all Dict entries
for idx in $(seq 0 $((javaCounter - 1)))
do
version=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMVersion" /dev/stdin <<< $javaXml)
path=$(/usr/libexec/PlistBuddy -c "print :$idx:JVMHomePath" /dev/stdin <<< $javaXml)

When javaCounter is 0 then seq 0 -1 makes PlistBuddy run twice with index -1 in the second iteration, when actually the loop should not run at all.

Possible solution:
for (( idx = 0 ; idx < javaCounter ; idx++ ))
But I don't know if that would introduce a typing problem for the compiled version, when $idx is used in a string. I guess that was the reason for writing the loop like this in the first place? So maybe enclosing the whole loop in an "if javaCounter > 0" instead?

@tofi86
Copy link
Owner

tofi86 commented Feb 3, 2021

Thanks for the hint @Flexperte! And sorry for the delay @ampusasidharan!

I added a fix with d83b501 which implements a basic if guard.

This will be released shortly with v3.1.1

@tofi86 tofi86 closed this as completed Feb 3, 2021
@tofi86 tofi86 added the bug label Feb 3, 2021
@tofi86 tofi86 self-assigned this Feb 3, 2021
@tofi86
Copy link
Owner

tofi86 commented Feb 3, 2021

I'd be happy to get feedback for this fix. Give it a try by taking the latest version v3.1.1-beta from the develop branch... Otherwise v3.1.1 will be released in a couple of days anyways...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants