Skip to content

Commit d39e481

Browse files
[pigeon] Fixes crash that occurs when an object that is removed from the instance manager calls to Dart (#10552)
In the event of a hot restart, the native `InstanceManagers` are cleared. There is then a chance for a class to make a callback when it is no in the instance manager which leads to a null exception in the codec. Part of fixing flutter/flutter#176451 Pigeon side fix for #10529 ## Pre-Review Checklist **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 02b9c2c commit d39e481

File tree

11 files changed

+1291
-746
lines changed

11 files changed

+1291
-746
lines changed

packages/pigeon/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 26.1.4
2+
3+
* [swift][kotlin] Fixes crash that occurs when an object that is removed from the instance manager
4+
calls to Dart.
5+
16
## 26.1.3
27

38
* [dart] Fixes error from constructor parameter sharing name with attached field for a ProxyApi.

packages/pigeon/lib/src/generator_tools.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'generator.dart';
1515
/// The current version of pigeon.
1616
///
1717
/// This must match the version in pubspec.yaml.
18-
const String pigeonVersion = '26.1.3';
18+
const String pigeonVersion = '26.1.4';
1919

2020
/// Read all the content from [stdin] to a String.
2121
String readStdin() {

packages/pigeon/lib/src/kotlin/kotlin_generator.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2241,6 +2241,18 @@ fun deepEquals(a: Any?, b: Any?): Boolean {
22412241
$errorClassName("ignore-calls-error", "Calls to Dart are being ignored.", "")))
22422242
return''');
22432243
},
2244+
addTrailingNewline: false,
2245+
);
2246+
indent.writeScoped(
2247+
' else if (!pigeonRegistrar.instanceManager.containsInstance(${classMemberNamePrefix}instanceArg)) {',
2248+
'}',
2249+
() {
2250+
indent.format('''
2251+
callback(
2252+
Result.failure(
2253+
$errorClassName("missing-instance-error", "Callback to `${api.name}.${method.name}` failed because native instance was not in the instance manager.", "")))
2254+
return''');
2255+
},
22442256
);
22452257
indent.writeln(
22462258
'val binaryMessenger = pigeonRegistrar.binaryMessenger',

packages/pigeon/lib/src/swift/swift_generator.dart

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,26 @@ func deepHash${generatorOptions.fileSpecificClassNameComponent}(value: Any?, has
26922692
code: "ignore-calls-error",
26932693
message: "Calls to Dart are being ignored.", details: "")))
26942694
return''');
2695-
});
2695+
}, addTrailingNewline: false);
2696+
2697+
final String instanceArgName = _getSafeArgumentName(
2698+
0,
2699+
NamedType(name: 'pigeonInstance', type: apiAsTypeDeclaration),
2700+
);
2701+
indent.writeScoped(
2702+
' else if !pigeonRegistrar.instanceManager.containsInstance($instanceArgName as AnyObject) {',
2703+
'}',
2704+
() {
2705+
indent.format('''
2706+
completion(
2707+
.failure(
2708+
${_getErrorClassName(generatorOptions)}(
2709+
code: "missing-instance-error",
2710+
message: "Callback to `${api.name}.${method.name}` failed because native instance was not in the instance manager.", details: "")))
2711+
return''');
2712+
},
2713+
);
2714+
26962715
indent.writeln(
26972716
'let binaryMessenger = pigeonRegistrar.binaryMessenger',
26982717
);

packages/pigeon/platform_tests/test_plugin/android/src/main/kotlin/com/example/test_plugin/ProxyApiTestApiImpls.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface ProxyApiInterface
1515

1616
@RequiresApi(25) class ClassWithApiRequirement
1717

18-
class ProxyApiRegistrar(binaryMessenger: BinaryMessenger) :
18+
open class ProxyApiRegistrar(binaryMessenger: BinaryMessenger) :
1919
ProxyApiTestsPigeonProxyApiRegistrar(binaryMessenger) {
2020
override fun getPigeonApiProxyApiTestClass(): PigeonApiProxyApiTestClass {
2121
return ProxyApiTestClassApi(this)

0 commit comments

Comments
 (0)