Skip to content

[file_selector] Switch to Kotlin Pigeon#11479

Open
stuartmorgan-g wants to merge 4 commits intoflutter:mainfrom
stuartmorgan-g:kotlin-pigeon-file-selector
Open

[file_selector] Switch to Kotlin Pigeon#11479
stuartmorgan-g wants to merge 4 commits intoflutter:mainfrom
stuartmorgan-g:kotlin-pigeon-file-selector

Conversation

@stuartmorgan-g
Copy link
Copy Markdown
Collaborator

Replaces the Java Pigeon generator with the Kotlin Pigeon generator, and adjusts the project accordingly:

  • Adds Kotlin build setings to Gradle.
  • Updates API signatures for Kotlin/Java differences.
  • Adds generic Java/Kotlin compat shim to create Result objects from Java, since those haven't been added to the Pigeon generator yet.
  • Updates tests to use constructors instead of builders, since the Kotlin generator doesn't create builders.
  • Updates tests to use a Java/Kotlin compat shim to read Kotlin Result values, instead of mocking the Java Pigeon response object.

This does not attempt to fix the pre-existing invalid use of null paths described in flutter/flutter#159568, but the behavior does change slightly from an IllegalStateException (which came from the Java builder) to a NullPointerException (from trying to assign to a non-null Kotlin field).

Part of flutter/flutter#158287

Pre-Review Checklist

Footnotes

  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. 2

Replaces the Java Pigeon generator with the Kotlin Pigeon generator, and
adjusts the project accordingly:
- Adds Kotlin build setings to Gradle.
- Updates API signatures for Kotlin/Java differences.
- Adds generic Java/Kotlin compat shim to create Result objects from
  Java, since those haven't been added to the Pigeon generator yet.
- Updates tests to use constructors instead of builders, since the Kotlin
  generator doesn't create builders.
- Updates tests to use a Java/Kotlin compat shim to read Kotlin Result
  values, instead of mocking the Java Pigeon response object.

This does not attempt to fix the pre-existing invalid use of null paths
described in flutter/flutter#159568, but the
behavior does change slightly from an IllegalStateException (which came
from the Java builder) to a NullPointerException (from trying to assign
to a non-null Kotlin field).

Part of flutter/flutter#158287
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the file_selector_android package to use Kotlin Pigeon for its internal implementation. Key changes include updating the CHANGELOG.md and pubspec.yaml for version and dependency updates, modifying build.gradle.kts to incorporate Kotlin plugins and compiler options, and replacing the Java-generated Pigeon API with a new Kotlin-generated one. Existing Java files (FileSelectorApiImpl.java, FileSelectorAndroidPlugin.java) are refactored to integrate with the new Kotlin API, including changes to method signatures and error handling. New Kotlin utility files (ResultUtils.kt, TestResultUtils.kt) are added to support Kotlin Result types and facilitate testing. The Dart-generated API (file_selector_api.g.dart) is also updated to reflect the new Pigeon version and error handling. A review comment highlights an incorrect package name in TestResultUtils.kt that needs to be corrected, along with its corresponding import in FileSelectorAndroidPluginTest.java.

@github-actions github-actions bot removed the CICD Run CI/CD label Apr 9, 2026
@stuartmorgan-g stuartmorgan-g added the CICD Run CI/CD label Apr 9, 2026
@github-actions github-actions bot removed the CICD Run CI/CD label Apr 9, 2026
@stuartmorgan-g stuartmorgan-g added the CICD Run CI/CD label Apr 9, 2026

assertThrows(
IllegalStateException.class,
NullPointerException.class,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change? How do we usually handle things like that?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a grey area; either way it's a PlatformException on the Dart side, so it only breaks people doing string matching on the exact exception. When it's something that we've previously had as an intentional user-facing error that we expect them to handle, we have generally treated changing the exception internals as breaking and avoided doing it unless we are overhauling the plugin to use structure errors.

In this case, where it's an unintentional plugin bug (in an edge case), I don't think we need to assume people are string-matching the exception details and trying to handle it. Once once we fix the bug this will go away regardless.

@@ -1,3 +1,7 @@
## 0.5.2+6

* Updates internal implementation to use Kotlin Pigeon.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention the NullPointer change?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's not an intentional behavior, I didn't think there was much to usefully document. It would have to say something like "The string details of the PlatformException reported in some rare failure cases have changed from referencing IllegalStateException to NullPointerException."

@stuartmorgan-g stuartmorgan-g added the triage-android Should be looked at in Android triage label Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD p: file_selector platform-android triage-android Should be looked at in Android triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants