Skip to content

Commit 8a09cf7

Browse files
authored
Return empty properties when java fails to run (#255)
If the Java executable we are trying to run fails to be be executed (i.e., locked file, broken symlink, or any raeson actually) we should just return an empty dictionary. That way when running `GetPathEnvironmentJdkPaths`, the invalid/not available executable is just ignored. Call stack from: * https://developercommunity.visualstudio.com/t/visual-studio-does-not-see-detect-the-co/10888076 System.ComponentModel.Win32Exception (0x80004005): The system cannot find the path specified at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at Xamarin.Android.Tools.ProcessUtils.Exec(ProcessStartInfo processStartInfo, DataReceivedEventHandler output, Boolean includeStderr) at Xamarin.Android.Tools.JdkInfo.GetJavaProperties(Action`2 logger, String java) at Xamarin.Android.Tools.JdkInfo.<GetPathEnvironmentJdkPaths>d__61.MoveNext() The message `The system cannot find the path specified` is a bit misleading because we are already validating the file exist before calling `GetJavaProperties`, and this can only occurr if we found a broken symlink.
1 parent d4b5529 commit 8a09cf7

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ static Dictionary<string, List<string>> GetJavaProperties (Action<TraceLevel, st
274274

275275
const string PropertySettings = "Property settings:";
276276

277-
ProcessUtils.Exec (javaProps, (o, e) => {
277+
try {
278+
ProcessUtils.Exec (javaProps, (o, e) => {
278279
const string ContinuedValuePrefix = " ";
279280
const string NewValuePrefix = " ";
280281
const string NameValueDelim = " = ";
@@ -307,7 +308,14 @@ static Dictionary<string, List<string>> GetJavaProperties (Action<TraceLevel, st
307308
props.Add (curKey, values = new List<string> ());
308309
values.Add (value);
309310
}
310-
});
311+
});
312+
}
313+
catch (Exception e) {
314+
logger (TraceLevel.Error, $"Error retrieving Java properties by running `{javaProps.FileName} {javaProps.Arguments}`: {e.Message}");
315+
logger (TraceLevel.Verbose, e.ToString ());
316+
return props;
317+
}
318+
311319
if (!foundPS) {
312320
logger (TraceLevel.Warning, $"No Java properties found; did not find `{PropertySettings}` in `{java} -XshowSettings:properties -version` output: ```{output.ToString ()}```");
313321
}

0 commit comments

Comments
 (0)