Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] Null Reference Exceoption when getting android.jar #976

Merged
merged 3 commits into from Nov 1, 2017

Conversation

dellis1972
Copy link
Contributor

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=60324

If a android.jar file does NOT exist for a target platform we should
raise a normal error. But we currently throw a null reference
exception.

TryGetPlatformDirectoryFromApiLevel can return null, this is by
design. So we need to handle that in the places where its used.
And return a reasonable error message if we do get a null back.

@@ -69,7 +69,8 @@ public override bool Execute ()
}

platform = GetTargetSdkVersion (platform, target_sdk);
JavaPlatformJarPath = Path.Combine (MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions), "android.jar");
var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions);
JavaPlatformJarPath = Path.Combine (platformPath ?? MonoAndroidHelper.AndroidSdk.GetPlatformDirectoryFromId (platform), "android.jar");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would make more sense to instead emit an error if TryGetPlatformDirectoryFromApiLevel() fails, especially considering that TryGetPlatformDirectoryFromApiLevel() calls GetPlatformDirectoryFromId().

If null is returned, it's because the directory doesn't exist.

Thus, I think we should instead have:

static string TryGetAndroidJarPath (TaskLoggingHelper log, string platform)
{
    var platformPath = MonoAndroidHelper.AndroidSdk.TryGetPlatformDirectoryFromApiLevel (platform, MonoAndroidHelper.SupportedVersions);
    if (platformPath == null) {
        log.LogError ("XA1234", $"Could not determine Android SDK directory for {platform}.");
        return null;
    }
    return Path.Combine (platformPath, "android.jar");
}

The one downside here is that we don't see the directories that we're trying. I'm not sure that's a problem.

…android.jar

Fixes https://bugzilla.xamarin.com/show_bug.cgi?id=60324

If a android.jar file does NOT exist for a target platform we should
raise a normal error. But we currently throw a null reference
exception.

`TryGetPlatformDirectoryFromApiLevel` can return null, this is by
design. So we need to handle that in the places where its used.
And return a reasonable error message if we do get a null back.
@jonpryor jonpryor merged commit 7f45a6d into xamarin:master Nov 1, 2017
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants