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

NullReferenceException when Repository.GetAllTeams() contains nested teams #2052

Closed
MikhailTymchukDX opened this issue Dec 13, 2019 · 7 comments · Fixed by #2156
Closed

NullReferenceException when Repository.GetAllTeams() contains nested teams #2052

MikhailTymchukDX opened this issue Dec 13, 2019 · 7 comments · Fixed by #2156
Assignees
Labels
Type: Bug Something isn't working as documented

Comments

@MikhailTymchukDX
Copy link
Contributor

MikhailTymchukDX commented Dec 13, 2019

Octokit.NET v0.36.0

client.Repository.GetAllTeams("AnyTestOrg", "how-to-use-grid-with-vertical-scrollbar-in-full-screen-mode-100-width-and-height-e1081").Wait();

throws an exception:

System.AggregateException
  HResult=0x80131500
  Message=One or more errors occurred.
  Source=mscorlib
  StackTrace:
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at GitHubApiTest.Program.Main(String[] args) in F:\Projects\GitHubApiTest\GitHubApiTest\Program.cs:line 62

Inner Exception 1:
NullReferenceException: Object reference not set to an instance of an object.

Inner exception stack trace:

   at Octokit.Reflection.ReflectionUtils.<>c__DisplayClass41_0.<GetSetMethodByExpression>b__0(Object source, Object val) in C:\Users\shiftkey\src\octokit.net\Octokit\SimpleJson.cs:line 2075
   at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type) in C:\Users\shiftkey\src\octokit.net\Octokit\SimpleJson.cs:line 1495
   at Octokit.Internal.SimpleJsonSerializer.GitHubSerializerStrategy.DeserializeObject(Object value, Type type) in C:\Users\shiftkey\src\octokit.net\Octokit\Http\SimpleJsonSerializer.cs:line 193
   at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type) in C:\Users\shiftkey\src\octokit.net\Octokit\SimpleJson.cs:line 1495
   at Octokit.Internal.SimpleJsonSerializer.GitHubSerializerStrategy.DeserializeObject(Object value, Type type) in C:\Users\shiftkey\src\octokit.net\Octokit\Http\SimpleJsonSerializer.cs:line 193
   at Octokit.PocoJsonSerializerStrategy.DeserializeObject(Object value, Type type) in C:\Users\shiftkey\src\octokit.net\Octokit\SimpleJson.cs:line 1522
   at Octokit.Internal.SimpleJsonSerializer.GitHubSerializerStrategy.DeserializeObject(Object value, Type type) in C:\Users\shiftkey\src\octokit.net\Octokit\Http\SimpleJsonSerializer.cs:line 193
   at Octokit.SimpleJson.DeserializeObject(String json, Type type, IJsonSerializerStrategy jsonSerializerStrategy) in C:\Users\shiftkey\src\octokit.net\Octokit\SimpleJson.cs:line 591
   at Octokit.SimpleJson.DeserializeObject[T](String json, IJsonSerializerStrategy jsonSerializerStrategy) in C:\Users\shiftkey\src\octokit.net\Octokit\SimpleJson.cs:line 603
   at Octokit.Internal.SimpleJsonSerializer.Deserialize[T](String json) in C:\Users\shiftkey\src\octokit.net\Octokit\Http\SimpleJsonSerializer.cs:line 22
   at Octokit.Internal.JsonHttpPipeline.DeserializeResponse[T](IResponse response) in C:\Users\shiftkey\src\octokit.net\Octokit\Http\JsonHttpPipeline.cs:line 66
   at Octokit.Connection.<Run>d__57`1.MoveNext() in C:\Users\shiftkey\src\octokit.net\Octokit\Http\Connection.cs:line 628
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Octokit.ApiConnection.<GetPage>d__42`1.MoveNext() in C:\Users\shiftkey\src\octokit.net\Octokit\Http\ApiConnection.cs:line 620
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Octokit.ApiConnection.<>c__DisplayClass17_0`1.<<GetAll>b__0>d.MoveNext() in C:\Users\shiftkey\src\octokit.net\Octokit\Http\ApiConnection.cs:line 197
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Octokit.ApiPagination.<GetAllPages>d__0`1.MoveNext() in C:\Users\shiftkey\src\octokit.net\Octokit\Clients\ApiPagination.cs:line 37

FIddler output:

image

If I move ASPxGridView to the root, the error is gone:

image

@MikhailTymchukDX MikhailTymchukDX changed the title NullReferenceException when Repository.GetAllTeams() contains in nested teams NullReferenceException when Repository.GetAllTeams() contains nested teams Dec 13, 2019
@shiftkey
Copy link
Member

@MikhailTymchukDX just a heads up that those screenshots contain the token you used. Please ensure it gets revoked or renewed before someone decides to borrow it.

@MikhailTymchukDX
Copy link
Contributor Author

@shiftkey oops, my bad. revoked it. thanks a ton!

@cliffchapmanrbx
Copy link

I presume there isn't an update for this? We started getting bit by this in the last few days.

@cliffchapmanrbx
Copy link

I've simply commented out the parent field in the Team object for testing and the null exception went away. I have to stop for now. I suspect it's related to the parent team having (null) for the permission field but wasn't able to confirm yet.

@cliffchapmanrbx
Copy link

Okay so this definitely seems related to attempting to set a StringEnum to null. Line 1495 in SimpleJson.cs stopped in the debugger is showing that it's deserializes the null value as.. null, and is attempting to use the compiled setter to set the value on line 2074. The compiled setter doesn't handle that case for the StringEnum apparently.

devenv_nJwn0oyrTm

So the next question is what is it supposed to do with a null value for a StringEnum? Can I add a value to a StringEnum to have it handle null properly?

@cliffchapmanrbx
Copy link

As a temporary workaround I've added this to line 193 of SimpleJsonSerializer.cs:

                // HACK: Support for string enums with null values
                if (value == null && ReflectionUtils.IsStringEnumWrapper(type))
                {
                    return Activator.CreateInstance(type, "null");
                }

And this to the Permission.cs enum:

        /// <summary>
        /// Team groups can be null, such as when a parent team doesn't have permission
        /// to a repo while a child team does.
        /// </summary>
        [Parameter(Value = "null")]
        None,

This feels pretty hacky but I don't really have a better solution at the moment. I'd say it sounds like an API bug on GitHub's end but it doesn't, as lack of permissions to a repository feels alright to be a 'null' value coming from the API.

@shiftkey
Copy link
Member

@cliffchapmanrbx apologies for missing your messages. It might be that we only need to make that change in Octokit/Models/Response/PermissionLevel.cs (we shouldn't be using Permission.cs as that's for the request itself).

I've opened #2156 which will make a beta package available to help with your testing, as I need to be a member of your organization to query for teams in the way that you are.

@shiftkey shiftkey self-assigned this Mar 17, 2020
@nickfloyd nickfloyd added Type: Bug Something isn't working as documented and removed category: bug labels Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants