Skip to content

[camera_avfoundation] Fix Swift analyzer issues in tests - #13340

Merged
auto-submit[bot] merged 2 commits into
flutter:mainfrom
jmagman:camera-warnings
Oct 20, 2026
Merged

auto-submit[bot] merged 2 commits into
flutter:mainfrom
jmagman:camera-warnings

Conversation

@jmagman

@jmagman jmagman commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

I don't know why these analyzer issues are being reported one-at-a-time in CI on #13284 instead of all at once, but #13332 was only one of a few analyzer issues:

darwin/Tests/CameraSessionPresetsTests.swift:28:9: error: variable 'currentFormat' was never mutated; consider changing to 'let' constant
    var currentFormat: CaptureDeviceFormat = captureFormatMock
    ~~~ ^
    let
darwin/Tests/CameraInitRaceConditionsTests.swift:62:24: warning: immutable value '_captureSessionQueue' was never used; consider replacing with '_' or removing it [#NoUsage]
60 | 
61 |   func testFlutterChannelInitializedWhenStartingImageStream() {
62 |     let (cameraPlugin, _captureSessionQueue) = createCameraPlugin()
darwin/Tests/AvailableCamerasTests.swift:49:11: warning: variable 'requiredTypes' was never mutated; consider changing to 'let' constant [#VariableNeverMutated]
 47 |       telephotoCamera.position = .back
 48 | 
 49 |       var requiredTypes: [AVCaptureDevice.DeviceType] = [
darwin/Tests/AvailableCamerasTests.swift:52:11: warning: variable 'cameras' was never mutated; consider changing to 'let' constant [#VariableNeverMutated]
 50 |         .builtInWideAngleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera,
 51 |       ]
 52 |       var cameras = [wideAngleCamera, frontFacingCamera, telephotoCamera, ultraWideCamera]
darwin/Tests/AvailableCamerasTests.swift:86:11: warning: variable 'requiredTypes' was never mutated; consider changing to 'let' constant [#VariableNeverMutated]
 84 |       frontFacingCamera.position = .front
 85 | 
 86 |       var requiredTypes: [AVCaptureDevice.DeviceType] = [
darwin/Tests/AvailableCamerasTests.swift:118:11: warning: variable 'requiredTypes' was never mutated; consider changing to 'let' constant [#VariableNeverMutated]
116 |       unspecifiedCamera.position = .unspecified
117 | 
118 |       var requiredTypes: [AVCaptureDevice.DeviceType] = [
darwin/Tests/CameraOrientationTests.swift:120:14: warning: weak variable 'weakDevice' was never mutated; consider changing to 'let' constant [#VariableNeverMutated::WeakMutability]
118 |     let captureSessionQueue = DispatchQueue(label: "capture_session_queue")
119 |     weak var weakPlugin: CameraPlugin?
120 |     weak var weakDevice = mockDevice
darwin/Tests/CameraOrientationTests.swift:157:14: warning: weak variable 'weakEventAPI' was never mutated; consider changing to 'let' constant [#VariableNeverMutated::WeakMutability]
155 |     }
156 | 
157 |     weak var weakEventAPI = mockEventAPI

This wasn't showing up in CI due to flutter/flutter#194517.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. 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.

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

@jmagman jmagman added the CICD Run CI/CD label Oct 19, 2026
@jmagman
jmagman marked this pull request as ready for review October 19, 2026 23:16

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

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.

Code Review

This pull request refactors several Swift test files to use let instead of var for non-mutated variables and adjusts closure capture lists in CameraOrientationTests.swift. The review feedback suggests simplifying the closure captures in CameraOrientationTests.swift by capturing mockDevice and mockEventAPI strongly rather than weakly, which avoids unnecessary force-unwrapping and optional chaining since no retain cycles are present in these test cases.

deviceDiscoverer: mockDeviceDiscoverer,
permissionManager: MockCameraPermissionManager(),
deviceFactory: { _ in weakDevice! },
deviceFactory: { _ in mockDevice },

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Bot review is right:

Capturing mockDevice weakly and force-unwrapping it is unnecessary here. Since mockDevice is a local variable in the test and does not hold any reference back to the CameraPlugin or the closure, capturing it strongly will not create a retain cycle. Simplifying this to a strong capture avoids the force-unwrap (!) and makes the code cleaner.

captureSessionQueue.async {
XCTAssertFalse(setDeviceOrientationCalled)
XCTAssertFalse(weakEventAPI?.deviceOrientationChangedCalled ?? false)
XCTAssertFalse(mockEventAPI.deviceOrientationChangedCalled)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Bot review is right:

Capturing mockEventAPI weakly is unnecessary because the dispatch queue will release the closure (and thus the captured reference) immediately after execution. Since there is no retain cycle, capturing it strongly simplifies the assertion and avoids the need for optional chaining and the nil-coalescing operator (?? false), which could otherwise lead to false positives if the mock were unexpectedly nil.

@jmagman jmagman added the autosubmit Merge PR when tree becomes green via auto submit App label Oct 20, 2026
@auto-submit
auto-submit Bot merged commit 759473e into flutter:main Oct 20, 2026
13 checks passed
ValentinVignal pushed a commit to ValentinVignal/flutter that referenced this pull request Oct 21, 2026
flutter/packages@618afba...1383427

2026-10-21 [email protected] [shared_preferences] Keep Kotlin
classes used through JNI in Android release builds
(flutter/packages#13311)
2026-10-20 [email protected] [webview_flutter_wkwebview] Roll back iOS
and macOS versions (flutter/packages#13354)
2026-10-20 [email protected] [camera]fix
resolution test failure due to hardware restriction
(flutter/packages#13356)
2026-10-20 [email protected] [google_maps_flutter_web] Fail fast and
deduplicate map setup in integration tests (flutter/packages#13092)
2026-10-20 [email protected] [camera_avfoundation] Fix Swift analyzer
issues in tests (flutter/packages#13340)
2026-10-20 [email protected] Sync release-material_ui-1.8.0 to
main (flutter/packages#13346)
2026-10-20 [email protected] [material_ui] add a `barFocusNode` to
`SearchAnchor.bar` (ref: flutter#186073)
(flutter/packages#12863)
2026-10-20 [email protected] [in_app_purchase_storekit] Expose
sk2Transaction on SK2PurchaseDetails (flutter/packages#13341)
2026-10-20 [email protected] Sync release-cupertino_ui-1.1.4 to
main (flutter/packages#13350)
2026-10-20 [email protected] [google_maps_flutter_web] Don't hang
`onMapCreated` when tiles fail to load (flutter/packages#13059)
2026-10-20 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm:
adaptive_text_selection_toolbar_test, material_button_test,
outlined_button_test, text_button_test (flutter/packages#13335)
2026-10-20 [email protected] Sync release-go_router-18.1.1 to
main (flutter/packages#13347)
2026-10-20 [email protected] [camera] Add zero-shutter-lag support
to camera_android_camerax and camera_avfoundation
(flutter/packages#13199)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
LongCatIsLooong pushed a commit to LongCatIsLooong/flutter that referenced this pull request Oct 22, 2026
flutter/packages@618afba...1383427

2026-10-21 [email protected] [shared_preferences] Keep Kotlin
classes used through JNI in Android release builds
(flutter/packages#13311)
2026-10-20 [email protected] [webview_flutter_wkwebview] Roll back iOS
and macOS versions (flutter/packages#13354)
2026-10-20 [email protected] [camera]fix
resolution test failure due to hardware restriction
(flutter/packages#13356)
2026-10-20 [email protected] [google_maps_flutter_web] Fail fast and
deduplicate map setup in integration tests (flutter/packages#13092)
2026-10-20 [email protected] [camera_avfoundation] Fix Swift analyzer
issues in tests (flutter/packages#13340)
2026-10-20 [email protected] Sync release-material_ui-1.8.0 to
main (flutter/packages#13346)
2026-10-20 [email protected] [material_ui] add a `barFocusNode` to
`SearchAnchor.bar` (ref: flutter#186073)
(flutter/packages#12863)
2026-10-20 [email protected] [in_app_purchase_storekit] Expose
sk2Transaction on SK2PurchaseDetails (flutter/packages#13341)
2026-10-20 [email protected] Sync release-cupertino_ui-1.1.4 to
main (flutter/packages#13350)
2026-10-20 [email protected] [google_maps_flutter_web] Don't hang
`onMapCreated` when tiles fail to load (flutter/packages#13059)
2026-10-20 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm:
adaptive_text_selection_toolbar_test, material_button_test,
outlined_button_test, text_button_test (flutter/packages#13335)
2026-10-20 [email protected] Sync release-go_router-18.1.1 to
main (flutter/packages#13347)
2026-10-20 [email protected] [camera] Add zero-shutter-lag support
to camera_android_camerax and camera_avfoundation
(flutter/packages#13199)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
suryaKommana2662 pushed a commit to suryaKommana2662/flutter that referenced this pull request Oct 29, 2026
flutter/packages@618afba...1383427

2026-10-21 [email protected] [shared_preferences] Keep Kotlin
classes used through JNI in Android release builds
(flutter/packages#13311)
2026-10-20 [email protected] [webview_flutter_wkwebview] Roll back iOS
and macOS versions (flutter/packages#13354)
2026-10-20 [email protected] [camera]fix
resolution test failure due to hardware restriction
(flutter/packages#13356)
2026-10-20 [email protected] [google_maps_flutter_web] Fail fast and
deduplicate map setup in integration tests (flutter/packages#13092)
2026-10-20 [email protected] [camera_avfoundation] Fix Swift analyzer
issues in tests (flutter/packages#13340)
2026-10-20 [email protected] Sync release-material_ui-1.8.0 to
main (flutter/packages#13346)
2026-10-20 [email protected] [material_ui] add a `barFocusNode` to
`SearchAnchor.bar` (ref: flutter#186073)
(flutter/packages#12863)
2026-10-20 [email protected] [in_app_purchase_storekit] Expose
sk2Transaction on SK2PurchaseDetails (flutter/packages#13341)
2026-10-20 [email protected] Sync release-cupertino_ui-1.1.4 to
main (flutter/packages#13350)
2026-10-20 [email protected] [google_maps_flutter_web] Don't hang
`onMapCreated` when tiles fail to load (flutter/packages#13059)
2026-10-20 [email protected] [material_ui]
Unskip web tests that pass on CanvasKit and Skwasm:
adaptive_text_selection_toolbar_test, material_button_test,
outlined_button_test, text_button_test (flutter/packages#13335)
2026-10-20 [email protected] Sync release-go_router-18.1.1 to
main (flutter/packages#13347)
2026-10-20 [email protected] [camera] Add zero-shutter-lag support
to camera_android_camerax and camera_avfoundation
(flutter/packages#13199)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC [email protected] on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: camera platform-ios platform-macos

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants