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

FileCache throws NullReferenceException #3105

Merged

Conversation

SoundersFan
Copy link

FileCache.InitializeTypeAsync(Stream...) should not return null. It should return Task.FromResult<StorageFile>(null). Otherwise, CacheBase attempts to dereference the Task to call ConfigureAwait(false) which results in a NullReferenceException.

Fixes #3104

PR Type

What kind of change does this PR introduce?

  • Bugfix

What is the current behavior?

If the Uri has not already been cached, calling the following throws a NullReferenceException

StorageFile file = await FileCache.Instance.GetFromCacheAsync(new Uri("https://www.bing.com"));

What is the new behavior?

No NullReferenceException is thrown.

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
  • Pull Request has been submitted to the documentation repository instructions. Link:
  • Sample in sample app has been added / updated (for bug fixes / features)
  • Tests for the changes have been added (for bug fixes / features) (if applicable)
  • Header has been added to all new source files (run build/UpdateHeaders.bat)
  • Contains NO breaking changes

Other information

I also updated the what the InitializeTypeAsync(StorageFile...) return to be consistent with the other InitializeTypeAsync(Stream...) return. In the end, Task.FromResult is the more appropriate thing to return when your asynchronous method does not await.

…hould return `Task.FromResult<StorageFile>(null)`. Otherwise, CacheBase attempts to dereference the Task to call ConfigureAwait(false) which results in a NullReferenceException.
@ghost
Copy link

ghost commented Jan 22, 2020

Thanks for opening a Pull Request! The reviewers will test the PR and highlight if there is any conflict or changes required. If the PR is approved we will proceed to merge the pull request 🙌

@ghost ghost assigned azchohfi Jan 22, 2020
Copy link
Contributor

@hermitdave hermitdave left a comment

Choose a reason for hiding this comment

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

Please rebase so the branch is up to date. Looks good otherwise

@hermitdave hermitdave merged commit ba1c642 into CommunityToolkit:master Jan 29, 2020
@michael-hawker
Copy link
Member

Thanks @hermitdave for taking a look and @SoundersFan for the contribution!

@michael-hawker michael-hawker added this to the 6.1 milestone Mar 24, 2020
@michael-hawker michael-hawker mentioned this pull request Apr 1, 2020
36 tasks
@Kyaa-dost Kyaa-dost added the bug 🐛 An unexpected issue that highlights incorrect behavior label Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FileCache GetFromCacheAsync throws NullReferenceException
5 participants