Skip to content

Comments

Don't warn when JDK path from env var is not a directory#276

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-argumentexception-issue
Draft

Don't warn when JDK path from env var is not a directory#276
Copilot wants to merge 2 commits intomainfrom
copilot/fix-argumentexception-issue

Conversation

Copy link
Contributor

Copilot AI commented Feb 20, 2026

When JI_JAVA_HOME (or other JDK path sources) points to a path that exists but is not a directory (e.g., a file or broken symlink), TryGetJdkInfo was propagating the ArgumentException from JdkInfo..ctor as a TraceLevel.Warning, producing noisy, misleading output in MSBuild logs.

Changes

  • JdkInfo.TryGetJdkInfo: Add an early Directory.Exists guard. Paths that don't resolve to a directory are now silently skipped — logged only at Verbose — rather than emitting a Warning.
// Before: ArgumentException from ctor was caught and logged as Warning
internal static JdkInfo? TryGetJdkInfo(string path, ...)
{
    try { jdk = new JdkInfo(path, locator); }
    catch (Exception e) {
        logger(TraceLevel.Warning, ...);  // ← showed up in MSBuild output
    }
}

// After: non-directory paths are skipped before construction
if (!Directory.Exists(path)) {
    logger(TraceLevel.Verbose, $"Skipping JDK path `{path}`...");
    return null;
}
  • New test GetKnownSystemJdkInfos_JiJavaHome_NonDirectoryPath_NoWarning: sets JI_JAVA_HOME to a temp file path and asserts no Warning is logged.
Original prompt

This section details on the original issue you should resolve

<issue_title>ArgumentException looking for JDKs</issue_title>
<issue_description>This happened in a test here:

23:21:22.063   1:7>/Users/runner/android-toolchain/dotnet/packs/Microsoft.Android.Sdk.Darwin/31.0.200-ci.pr.gh6745.77/tools/Xamarin.Android.Tooling.targets(69,5): warning : An exception occurred while validating the Java SDK installation in '/Users/runner/Library/Android/jdk-11' that was found while searching the paths from '$JI_JAVA_HOME'. Ensure that the Android section of the Visual Studio options has a valid Java SDK directory configured. To use a custom SDK path for a command line build, set the 'JavaSdkDirectory' MSBuild property to the custom path. Exception: Not a directory (Parameter 'homePath') [/Users/runner/work/1/a/TestRelease/02-14_22.59.11/temp/NothingToBindclass-parse/UnnamedProject.csproj]
                     System.ArgumentException: Not a directory (Parameter 'homePath')
                        at Xamarin.Android.Tools.JdkInfo..ctor(String homePath, String locator, Action`2 logger) in /Users/builder/azdo/_work/2/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs:line 57
                        at Xamarin.Android.Tools.JdkInfo..ctor(String homePath, String locator) in /Users/builder/azdo/_work/2/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs:line 97
                        at Xamarin.Android.Tools.JdkInfo.TryGetJdkInfo(String path, Action`2 logger, String locator) in /Users/builder/azdo/_work/2/s/xamarin-android/external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/JdkInfo.cs:line 347 (TaskId:57)

The MSBuild log says $JI_JAVA_HOME is:

JI_JAVA_HOME = /Users/runner/Library/Android/jdk-11
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Fix ArgumentException during JDK validation Don't warn when JDK path from env var is not a directory Feb 20, 2026
Copilot AI requested a review from rmarinho February 20, 2026 19:29
Copilot AI and others added 2 commits February 24, 2026 19:08
When JI_JAVA_HOME (or another JDK path source) points to a path that
exists but is not a directory, TryGetJdkInfo now checks Directory.Exists
before constructing JdkInfo. Non-directory paths are skipped silently
(logged at Verbose only) instead of generating a Warning in MSBuild output.

Fixes: ArgumentException "Not a directory" spurious warning

Co-authored-by: rmarinho <1235097+rmarinho@users.noreply.github.com>
@rmarinho rmarinho force-pushed the copilot/fix-argumentexception-issue branch from 731c702 to 07738c1 Compare February 24, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArgumentException looking for JDKs

2 participants