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

Null reference when Getting AnnoationFilter #687

Closed
ysanghi opened this Issue Aug 16, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@ysanghi
Contributor

ysanghi commented Aug 16, 2016

Short summary (3-5 sentences) describing the issue.
When you have an invalid set prefer header (eg: Prefer: odata-includeannoations), and trying to access the annotation filter is throwing a null reference exception rather than return empty or not set.

Assemblies affected

Which assemblies and versions are known to be affected e.g. OData .Net lib 6.15-beta.
Lib 6.xx

Reproduce steps

The simplest set of steps to reproduce the issue. If possible, reference a commit that demonstrates the issue.
Create a request with Prefer header as Prefer: odata-includeannotations. Trying to access PreferenceHeader.AnnotationFilter will throw a null reference exception

Expected result

What would happen if there wasn't a bug.
It should ideally return null or empty string.

Actual result

What is actually happening.
Null reference exception is being thrown

Additional details

Optional, details of the root cause if known. Delete this section if you have no additional details to add.

@TomDu

This comment has been minimized.

Contributor

TomDu commented Aug 19, 2016

Hi @ysanghi, the PreferenceHeader.AnnotationFilter simply returns annotation values or null, maybe you can give us some detailed result stack trace, thanks.

@ysanghi

This comment has been minimized.

Contributor

ysanghi commented Aug 19, 2016

I believe the request is failing below on line 225 since odataAnnotations.Value is null.
public string AnnotationFilter
218 {
219 get
220 {
221 var odataAnnotations = this.Get(ODataAnnotationPreferenceToken);
222

223 if (odataAnnotations != null)
224 {
225 return odataAnnotations.Value.Trim('"');
226 }
227

228 return null;
229 }

Stack Trace I have:
"type": "System.NullReferenceException",
"stacktrace": " at Microsoft.OData.Core.ODataPreferenceHeader.get_AnnotationFilter()\r\n at Microsoft.Exchange.Services.OData.Web.ODataPreferenceHeader.get_AnnotationFilter()

@TomDu TomDu added the bug label Aug 23, 2016

TomDu added a commit to TomDu/odata.net that referenced this issue Aug 23, 2016

@TomDu

This comment has been minimized.

Contributor

TomDu commented Aug 23, 2016

@ysanghi I see, you mean you added prefer header odata.include-annotations but didn't set a value on it, e.g. Prefer: odata.include-annotations. This is indeed a bug and I've submitted a fix on it, thanks a lot for your feedback.

TomDu added a commit to TomDu/odata.net that referenced this issue Aug 23, 2016

TomDu added a commit to TomDu/odata.net that referenced this issue Aug 23, 2016

@TomDu TomDu closed this Aug 23, 2016

@TomDu TomDu self-assigned this Aug 23, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment