Skip to content
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

Error when trying to import big file #465

Closed
D3SOX opened this issue Mar 17, 2021 · 5 comments · Fixed by #479
Closed

Error when trying to import big file #465

D3SOX opened this issue Mar 17, 2021 · 5 comments · Fixed by #479
Assignees
Labels
bug A bug report bug-confirmed A confirmed and reproducible bug report
Milestone

Comments

@D3SOX
Copy link

D3SOX commented Mar 17, 2021

Short description

The theme import lets you select any file and when selecting a big (non-JSON) file it crashes. There should probably be a filter for JSON files and an error dialog that tells you when the selected file is not a valid theme JSON.
Edit: I see there already is an error snackbar when it fails to parse the JSON so this is not related to the file type.
Nevertheless I'm not sure if such a filter is even possible with the API you're using

Steps to reproduce

  1. Go to the theme manager
  2. Tab on the plus and then on Import
  3. Select a relatively large file
  4. See error

Environment information

  • FlorisBoard Version: 0.3.8
  • Install Source: GitHub
  • Device: OnePlus 8T
  • Android version, ROM: 11, Paranoid Android Ruby Beta 4
~~~ 1615989180585.stacktrace ~~~

java.lang.OutOfMemoryError: Failed to allocate a 268501000 byte allocation with 100663296 free bytes and 119MB until OOM, target footprint 243324296, growth limit 268435456
	at java.util.Arrays.copyOf(Arrays.java:3257)
	at java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:124)
	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:596)
	at java.lang.StringBuffer.append(StringBuffer.java:367)
	at java.io.StringWriter.write(StringWriter.java:94)
	at kotlin.io.TextStreamsKt.copyTo(ReadWrite.kt:125)
	at kotlin.io.TextStreamsKt.copyTo$default(ReadWrite.kt:120)
	at kotlin.io.TextStreamsKt.readText(ReadWrite.kt:107)
	at dev.patrickgold.florisboard.ime.extension.ExternalContentUtils$Companion.readTextFromUri-gIAlu-s(ExternalContentUtils.kt:29)
	at dev.patrickgold.florisboard.ime.extension.AssetManager.loadAsset-gIAlu-s(AssetManager.kt:180)
	at dev.patrickgold.florisboard.ime.theme.ThemeManager.loadTheme-IoAF18A(ThemeManager.kt:268)
	at dev.patrickgold.florisboard.settings.ThemeManagerActivity$importTheme$1.onActivityResult(ThemeManagerActivity.kt:73)
	at dev.patrickgold.florisboard.settings.ThemeManagerActivity$importTheme$1.onActivityResult(ThemeManagerActivity.kt:52)
	at androidx.activity.result.ActivityResultRegistry$1.onStateChanged(ActivityResultRegistry.java:148)
	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(LifecycleRegistry.java:354)
	at androidx.lifecycle.LifecycleRegistry.forwardPass(LifecycleRegistry.java:265)
	at androidx.lifecycle.LifecycleRegistry.sync(LifecycleRegistry.java:307)
	at androidx.lifecycle.LifecycleRegistry.moveToState(LifecycleRegistry.java:148)
	at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(LifecycleRegistry.java:134)
	at androidx.lifecycle.ReportFragment.dispatch(ReportFragment.java:68)
	at androidx.lifecycle.ReportFragment$LifecycleCallbacks.onActivityPostStarted(ReportFragment.java:187)
	at android.app.Activity.dispatchActivityPostStarted(Activity.java:1362)
	at android.app.Activity.performStart(Activity.java:8061)
	at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3458)
	at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
	at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2067)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7701)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:952)
@D3SOX D3SOX added the bug A bug report label Mar 17, 2021
@patrickgold
Copy link
Member

Thanks for your bug report! It is possible for the API I use to specify MIME file type filters, though the problem is that a json file may be an application/json, text/plain or even something else, depending on where the json file was created. Thus I just set it to */* and rely on the theme parser to crash so I can catch that and display the "Something is wrong" snackbar.

Even if I manage to limit it to json only files it would still crash for a large json file, and as far as I know there's no way of seeing how large a data associated with an URI is before it is too late (OOM error).

@patrickgold patrickgold added the bug-confirmed A confirmed and reproducible bug report label Mar 17, 2021
@kj7rrv
Copy link

kj7rrv commented Mar 17, 2021 via email

@patrickgold
Copy link
Member

This has something to to with the JVM max heap size, and 22 MB is doable but not an 88MB file, definitely not if you have a Flictionary loaded at that time.

P.S. When replying to comments via email, make sure to add one or two additional newlines at the end of your text (but before the "On Mar 17, 2021 1..." line) to prevent the previous message to be included in your comment visibly. This helps keeping the discussion more tidy :)

@patrickgold
Copy link
Member

Above PR fixes the import theme crash for big files by limiting the maximum file size for themes to 512kB (a theme on average has ~2kB). Will be included in the next beta release today.

@D3SOX
Copy link
Author

D3SOX commented Mar 20, 2021

Works perfectly Screenshot_20210320-123053_FlorisBoard_Beta_1.png

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report bug-confirmed A confirmed and reproducible bug report
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants