-
Notifications
You must be signed in to change notification settings - Fork 57
[generator] Fix NRE from return type not getting set for abstract methods with generics. #834
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
Conversation
…hods with generics.
@jpobst: I'm confused. If I extract the XML within $ mono bin/Debug/generator.exe -o ji-834.main ~/ji-834.xml --codegen-target=XAJavaInterop1
# no error Additionally, the generated C# source doesn't contain explicitly implemented interface members either; there is no $ grep -r Com.Example.RangeIterator.Next ji-834.main
# no output (Why was I bothering in the first place? For the commit message, to attempt to describe why we were explicitly implementing a method in the first place, to help "backfill" historical knowledge. On a related note, the original PR message doesn't quite make sense: the "set-up" mentions I thus can't be sure that the fix here is an actual fix, given that the test here doesn't trigger the exception mentioned in dotnet/android#5921. |
Interesting, if you revert the change to Here's the original |
It looks like the test fails while real |
The code path that crashes is simply trying to generate any |
Context: #834 (comment) Context: https://gist.github.com/jonpryor/41a0a920d27e5a761f499da4ade791a8 I was operating under the (deluded?) assumption that it should be possible to use the XML within `WriteBoundMethodAbstractDeclarationWithGenericReturn()` to reproduce the `NullReferenceException`, but I was unable to do so. I thus returned to the [full API declaration][0] to recreate a minimal test case which *would* result in a `NullReferenceException`, and found one. Oddly, the "missing piece" to trigger the NRE was *nested types* (?!): the original PR #834 had `RangeIterator` as a top-level type, and in this situation I wasn't able to get an NRE with main. Once I "reverted" it to a nested `FlowIterator.RangeIterator` type, it broke. I don't know if that's the *only* relevant change, as I changed other pieces as well: * Simpler (no parameters) `next()` method * Fixed the `//interface/@jni-signature` value for `FlowIterator` Regardless, this "newer" XML *does* crash, but also only with `--codegen-target=XAJavaInterop1`. It doesn't NRE w/o `--codegen-target`: $ mono bin/Debug/generator.exe -o yyy ji-834-fixed.xml --codegen-target=XAJavaInterop1 … Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.SourceWriter.MethodWriter.WriteReturnType (Xamarin.SourceWriter.CodeWriter writer) at Xamarin.SourceWriter.MethodWriter.WriteSignature (Xamarin.SourceWriter.CodeWriter writer) at Xamarin.SourceWriter.MethodWriter.Write (Xamarin.SourceWriter.CodeWriter writer) [0]: #834 (comment)
Fixes: dotnet/android#5921
For the following generic-laden Java:
We need to generate an explicit method declaration:
However when we did the
generator
refactor this code code path was not tested, and the code short-circuits, bypassing setting theReturnType
andParameters
collection.Attempting to generate the method results in an NRE:
This commit ensures the
ReturnType
andParameters
collection is set before the method returns.Pre-refactor code: https://github.com/xamarin/java.interop/blob/main/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs#L1175-L1181