Skip to content

[pigeon] Fix Kotlin/Java interop for sync methods that throw #184200

Description

@stuartmorgan-g

The Kotlin generator generates FlutterError as a Throwable, which causes it to be a checked exception in Java. In Java, however, we make it a RuntimeException subclass, so it's not a checked exception.

This causes problems when trying to use the Kotlin generator but a Java implementation, because the generated interface to implement doesn't list any thrown exceptions (since Kotlin doesn't do checked exceptions). For instance, I tried to convert url_launcher_android to the Kotlin generator, but I get

unreported exception FlutterError; must be caught or declared to be thrown

on the Java side unless I declare the the implementation to throw. But if I do that, I get

'launchUrl(String, Map<String, String>, boolean)' in 'io.flutter.plugins.urllauncher.UrlLauncher' clashes with
'launchUrl(String, Map<String, String>, boolean)' in 'io.flutter.plugins.urllauncher.UrlLauncherApi';
overridden method does not throw 'io.flutter.plugins.urllauncher.FlutterError'

I think we probably just want to make the Kotlin generator generate FlutterError as a subclass of RuntimeException rather than Throwable.

Metadata

Metadata

Labels

P1High-priority issues at the top of the work listp: pigeonrelated to pigeon messaging codegen toolpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions