Commit 131c149
authored
[generator] Fix NRE from return type not consistently set (#834)
Fixes: dotnet/android#5921
Context: #834 (comment)
Context: https://github.com/xamarin/java.interop/blob/100fffc1dc416f543293d0509870138d9d4f1669/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs#L1175-L1181
Consider the following Java type declaration:
package com.example;
public interface FlowIterator<R> {
R next();
public static class RangeIterator<T extends Comparable<T>> implements FlowIterator<T> {
public T next() {return null;}
}
}
This used to work in d16-7 -- not sure when exactly we broke it --
but it now throws a `NullReferenceException` when using
`generator --codegen-target=XAJavaInterop1`, when emitting the nested
`FlowIteratorRangerIterator` type:
$ 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)
Fix the `NullReferenceException` by ensuring that the `ReturnType`
property and `Parameters` collection are set before the
`BoundMethodAbstractDeclaration` constructor completes.1 parent 100fffc commit 131c149
File tree
2 files changed
+55
-2
lines changed- tests/generator-Tests/Unit-Tests
- tools/generator/SourceWriters
2 files changed
+55
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| |||
1271 | 1273 | | |
1272 | 1274 | | |
1273 | 1275 | | |
| 1276 | + | |
| 1277 | + | |
| 1278 | + | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
1274 | 1326 | | |
1275 | 1327 | | |
Lines changed: 3 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
| |||
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | | - | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | | - | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
0 commit comments