-
Notifications
You must be signed in to change notification settings - Fork 232
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
fixed panic: reflect: indirection through nil pointer to embedded struct #211
Conversation
Hi @morus12, introducing myself: I have contributed to the default functionality recently I was able to reproduce the issue, and the solution you proposed fixes it (fixes #213). I think that ignoring the embedded struct if it is nil is an option, but there are also two other alternatives that we can explore:
This not only avoids the panic, but also makes sure that any embedded struct fields with the From a pure logic perspective, I think your solution makes most sens, but in order to keep in line with what the library does when decoding, I am leaning slightly towards option 2. Let's try to get a second opinion. @AlexVulaj, @jaitaiwan any thoughts ? |
Hi @zak905, nice to meet you! I agree that the proposed solution to initialize nil pointers to the embedded structs is a better way to fix this case. I did it by iterating over struct fields and allocating nil pointers because this line panics:
It calls FieldByIndex under the hood, checks for nil pointers there, and panics |
thanks @morus12, and nice to meet you too! It looks good to me. |
This looks good to me - thanks @davidnewhall @zak905 @morus12 for your contributions, testing, and reviewing of this change! |
@morus12 I do see there's a merge conflict here - do you mind resolving that and pushing this back up so I can merge it? Thanks! |
@AlexVulaj It's ready. |
Are we waiting for anything before merging this and cutting a release? Happy to help further if needed. |
It does not seem the case, I think it's good to merge. @AlexVulaj any concerns here ? the branch have been updated as requested. |
@jaitaiwan it seems like Alex is unresponsive nowdays, do you mind taking a look please ? |
Taking a look |
This has been merged, I have no current plans to perform a version release for this repository yet. If this becomes an issue for anyone, I'll be happy to look at doing another release. For now many other gorilla repos require the maintainers attention. Thanks! |
@jaitaiwan |
Hi @jaitaiwan, If you want to maintain the trust of the community you'd make a new release and remove the bug (that causes panics) from the Thanks! |
Sorry for taking a while to get back to this - other repositories have been having issues as well that required more of our time. @davidnewhall it looks like this went out as part of v1.4.0 |
What type of PR is this? (check all applicable)
Description
The provided test
TestUnmarshallToEmbeddedNoData
shows that the decoder panics whensetDefaults
encounters a nil pointer to an embedded struct. The fix replacesFieldByName
withFieldByIndexErr
to catch this kind of situation and continue with the next field.Related Tickets & Documents
Added/updated tests?
have not been included
Run verifications and test
make verify
is passingmake test
is passing