-
Notifications
You must be signed in to change notification settings - Fork 66
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
4.4.1 - Fixing NRE in IsWebJobsAttribute #655
Conversation
return attribute.AttributeType.Resolve().CustomAttributes.Any(a => a.AttributeType.FullName == "Microsoft.Azure.WebJobs.Description.BindingAttribute") | ||
var attributeTypeDefinition = attribute.AttributeType?.Resolve(); | ||
|
||
if (attributeTypeDefinition == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a fan of pattern matching, but no worries if you want to keep it as is:
if (attribute.AttributeType?.Resolve() is not { } attributeTypeDefinition)
{
return false;
}
(may need to use actual type in place of { }
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good if we can have a simple set of tests against this method.
Updated E2E test to cover the scenario which caused NRE. |
… method (#655) * Adding null check to `IsWebJobsAttribute` extension method. * Fix method summary. * Updating E2E test to include a function with nullable parameter type.
Fixes #641
attribute.AttributeType?.Resolve()
inIsWebJobsAttribute
method, before calling other methods on the result of that.I also investigated the reason why the
Resolve
method was returning null when using nullable parameter.The problem arises when the function parameter is nullable (e.g.,
string? id
) in an in-process .NET 8.0 application. In such cases, theIsWebJobsAttribute
method is called forSystem.Runtime.CompilerServices.NullableAttribute
, and theattribute.AttributeType.Resolve()
expression returns null, leading to a NullReferenceException.This code is executed from
Microsoft.NET.Sdk.Functions.Generator
, which we start from the .NET 6.0 output (relevant code here). This causes the .NET 6 version of theSystem.Runtime
module (among others) to be loaded. TheNullableAttribute
is not available in .NET 6, causing theResolve
method to return null. Discussed this with the team and we agreed that returning false when Resolve returns null is good enough to address the issue.