ionic-team / ionic-team/capacitor
fix(android): remove unchecked Java compilation warnings
- Dominant language
- TypeScript
- Stars
- 16.7k
- Forks
- 1.3k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 10
Description
## Summary
Compiling the Capacitor Android library with `-Xlint:unchecked` reports eight
unchecked operations in the current 8.4.1 release and on `main`.
## Reproduction
From an Android app that includes `@capacitor/android@8.4.1`, configure Java
compile tasks with `-Xlint:unchecked` and run:
```text
./gradlew :capacitor-android:clean :capacitor-android:compileReleaseJavaWithJavac --console=plain
```
The default compilation emits the generic `Some input files use unchecked or
unsafe operations` note.
## Affected source
- `android/capacitor/src/main/java/com/getcapacitor/Plugin.java:679` constructs
a raw `CopyOnWriteArrayList` from a `List`.
- `android/capacitor/src/main/java/com/getcapacitor/BridgeWebChromeClient.java`
stores the permission and activity launchers as raw `ActivityResultLauncher`
values, producing six unchecked calls at lines 120, 267, 298, 350, 369, and
401.
## Expected behavior
The released Android library should compile without unchecked-operation notes.
Parameterizing the collection construction and the two launcher fields should
remove the warnings without changing behavior.
Contributor guide
Research direction
Inspect android/capacitor/src/main/java/com/getcapacitor/Plugin.java around line 679 and BridgeWebChromeClient.java, focusing on the raw collection and ActivityResultLauncher fields identified in the issue. Run ./gradlew :capacitor-android:clean :capacitor-android:compileReleaseJavaWithJavac --console=plain with -Xlint:unchecked enabled; done means the Android library compiles without unchecked-operation warnings and behavior is unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- mobile
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100