Skip to content

Uses Sequence instead of Stream to avoid errors due to unavailable Java 8 APIs#1943

Merged
JayShortway merged 1 commit into
mainfrom
sequence-instead-of-stream
Nov 28, 2024
Merged

Uses Sequence instead of Stream to avoid errors due to unavailable Java 8 APIs#1943
JayShortway merged 1 commit into
mainfrom
sequence-instead-of-stream

Conversation

@JayShortway

Copy link
Copy Markdown
Member

Motivation

Stream is a Java 8 API, which needs desugaring to function correctly across devices and API levels. This can lead to crashes such as RevenueCat/purchases-flutter#1213, which is only surfacing now because we fixed error-swallowing in #1894.

Changes

Fortunately, Kotlin's Sequence is a near drop-in replacement for Stream. This PR implements that replacement.

@JayShortway JayShortway added the pr:fix A bug fix label Nov 28, 2024
@JayShortway JayShortway requested a review from a team November 28, 2024 11:12
@JayShortway JayShortway self-assigned this Nov 28, 2024
@codecov

codecov Bot commented Nov 28, 2024

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.87%. Comparing base (991f8f7) to head (d4708b9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1943   +/-   ##
=======================================
  Coverage   81.87%   81.87%           
=======================================
  Files         260      260           
  Lines        8492     8493    +1     
  Branches     1226     1226           
=======================================
+ Hits         6953     6954    +1     
  Misses       1041     1041           
  Partials      498      498           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tonidero tonidero 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.

This is great! Maybe just removing the required version annotations... Tested it and seems to work as expected 💪

// This is using a lambda with a Sequence instead of returning the Sequence itself. This is so we keep
// the responsibility of closing the bufferedReader to this class. Note that the Sequence should
// be used synchronously, otherwise the bufferedReader will be closed before the Sequence is used.
@RequiresApi(Build.VERSION_CODES.N)

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.

I believe this is probably not needed anymore, as you mentioned over slack.

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.

Alright, will create a follow-up PR to clean these up if we decide they're not needed.

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.

For reference: #1944

@JayShortway JayShortway merged commit a38ceea into main Nov 28, 2024
@JayShortway JayShortway deleted the sequence-instead-of-stream branch November 28, 2024 12:18
This was referenced Nov 28, 2024
JayShortway pushed a commit that referenced this pull request Dec 2, 2024
**This is an automatic release.**

## RevenueCat SDK
### 🐞 Bugfixes
* Uses `Sequence` instead of `Stream` to avoid errors due to unavailable
Java 8 APIs (#1943) via JayShortway (@JayShortway)

### 🔄 Other Changes
* Increase integration test timeout (#1946) via Toni Rico (@tonidero)
* Removes `@RequiresApi(N)` from `FileHelper` and related classes
(#1944) via JayShortway (@JayShortway)
* [Paywalls V2] Minimizes Java API (#1942) via JayShortway
(@JayShortway)
* [Paywalls V2] Makes `TextComponent` public (#1939) via JayShortway
(@JayShortway)
* Introduces an `@InternalRevenueCatAPI` annotation (#1938) via
JayShortway (@JayShortway)
* [Paywalls V2] Moves any non-component file to a new `common` package.
(#1937) via JayShortway (@JayShortway)
* [Paywalls V2] `LocalizationKey` is an inline value class now. (#1936)
via JayShortway (@JayShortway)
* [Paywalls V2] Adds `PaywallComponentsData` (#1935) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `StickyFooterComponent` (#1934) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `PurchaseButtonComponent` (#1933) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `PackageComponent` (#1932) via JayShortway
(@JayShortway)
* Ensure the correct error message is shown when failing to open a Uri
in paywalls (#1922) via JayShortway (@JayShortway)
* [Paywalls V2] Adds `ButtonComponent` (#1931) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `StackComponent` (#1930) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `ComponentOverrides` (#1929) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `ImageComponent` (#1928) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `TextComponent` (#1927) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds all enum properties (#1926) via JayShortway
(@JayShortway)
* [Paywalls V2] Adds `SizeConstraints`, `Size`, `Padding` and `Shadow`
properties (#1925) via JayShortway (@JayShortway)
* [Paywalls V2] Adds `CornerRadiuses`, `Shape` and `MaskShape`
properties (#1924) via JayShortway (@JayShortway)
* [Paywalls V2] Adds `ImageUrls` and `ColorInfo` properties (#1923) via
JayShortway (@JayShortway)

Co-authored-by: revenuecat-ops <ops@revenuecat.com>
github-merge-queue Bot pushed a commit that referenced this pull request Apr 7, 2025
## Description
We still had a few leftover checks for Android 7, which are obsolete
since #1944 and #1943. This PR removes them, so Diagnostics can be used
from Android 5 and up.
github-merge-queue Bot pushed a commit that referenced this pull request Nov 20, 2025
### Description
Originally we used streams which weren't supported in Android < 24, but
that was removed in
#1943 and
#1944. However, we
have some leftover code checking for the android version to create the
events manager itself. This removes that, which makes events now
available for older android versions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants