forked from johngray1965/PdfiumAndroidKt
-
Notifications
You must be signed in to change notification settings - Fork 0
Honor AlreadyClosedBehavior in openPage/openTextPage (v1.0.35-based, for the Expensify JitPack pin) #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
wildan-m
wants to merge
4
commits into
Expensify:main
Choose a base branch
from
wildan-m:already-closed-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Honor AlreadyClosedBehavior in openPage/openTextPage (v1.0.35-based, for the Expensify JitPack pin) #2
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
29195ff
Honor AlreadyClosedBehavior in openPage/openTextPage
wildan-m fcfe694
Add jitpack.yml: build only :pdfiumandroid on JDK 17
wildan-m e6c06c2
jitpack: accept Android SDK/NDK licenses before build
wildan-m 6e60e76
Add instrumentation regression test for the openPage() Already-closed…
wildan-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| jdk: | ||
| - openjdk17 | ||
| before_install: | ||
| - yes | "${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager" --licenses > /dev/null 2>&1 || true | ||
| - yes | sdkmanager --licenses > /dev/null 2>&1 || true | ||
| install: | ||
| - ./gradlew :pdfiumandroid:publishToMavenLocal -x test --no-daemon |
54 changes: 54 additions & 0 deletions
54
pdfiumandroid/src/androidTest/java/io/legere/pdfiumandroid/AlreadyClosedOpenPageTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| package io.legere.pdfiumandroid | ||
|
|
||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import com.google.common.truth.Truth.assertThat | ||
| import io.legere.pdfiumandroid.base.BasePDFTest | ||
| import io.legere.pdfiumandroid.util.AlreadyClosedBehavior | ||
| import io.legere.pdfiumandroid.util.Config | ||
| import io.legere.pdfiumandroid.util.pdfiumConfig | ||
| import org.junit.After | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| /** | ||
| * E/App #93839 (Sentry APP-1VG) — Android "Already closed" crash on receipt PDF render. | ||
| * | ||
| * The production crash is a non-deterministic renderer-thread-vs-teardown race: a render | ||
| * lands on PdfDocument.openPage(0) after the document was already close()d. The app sets | ||
| * AlreadyClosedBehavior.IGNORE (react-native-pdf patch 002) so such a late call should be | ||
| * swallowed — but stock io.legere:pdfiumandroid 1.0.35 has openPage()/openTextPage() throw | ||
| * unconditionally, ignoring IGNORE, so the IllegalStateException crashes the renderer thread. | ||
| * | ||
| * This forces that exact frame deterministically: IGNORE -> newDocument -> close() -> openPage(0) | ||
| * | ||
| * Baseline (openPage does NOT honor IGNORE): FAILS — IllegalStateException("Already closed") | ||
| * at PdfDocument.openPage(PdfDocument.kt) == APP-1VG | ||
| * Fork (openPage honors IGNORE): PASSES — openPage returns instead of throwing | ||
| */ | ||
| @RunWith(AndroidJUnit4::class) | ||
| class AlreadyClosedOpenPageTest : BasePDFTest() { | ||
|
|
||
| @After | ||
| fun tearDown() { | ||
| // Don't leak the IGNORE config into other test classes. | ||
| pdfiumConfig = Config() | ||
| } | ||
|
|
||
| @Test | ||
| fun openPageAfterClose_withIgnore_doesNotCrash() { | ||
| val pdfBytes = getPdfBytes("f01.pdf") | ||
| assertThat(pdfBytes).isNotNull() | ||
|
|
||
| // Configure exactly as the app does (react-native-pdf patch 002): IGNORE via the | ||
| // PdfiumCore constructor. (PdfiumCore.init overwrites the global pdfiumConfig, so | ||
| // setting the global directly would be wiped by construction.) | ||
| val core = PdfiumCore(config = Config(alreadyClosedBehavior = AlreadyClosedBehavior.IGNORE)) | ||
| val doc = core.newDocument(pdfBytes) | ||
| doc.close() | ||
|
|
||
| // The exact crashing call from the APP-1VG stack. With IGNORE set this must NOT throw. | ||
| // On stock 1.0.35 it throws IllegalStateException("Already closed") here. | ||
| val page = doc.openPage(0) | ||
| assertThat(page).isNotNull() | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wildan-m, I don't think this should be needed, shouldn't this already be published to our local Maven repository?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eVoloshchak nothing's pre-published —
com.github.Expensify:…is a JitPack coordinate, so JitPack builds this repo from source on demand, and withoutjitpack.ymlit fails (its default JDK 11 can't run the Hilt plugin, which needs 17 — tag.1errored withNo build artifacts found).