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

Intermittent IndexOutOfBoundsException on render #157

Closed
damianw opened this issue Aug 22, 2019 · 6 comments
Closed

Intermittent IndexOutOfBoundsException on render #157

damianw opened this issue Aug 22, 2019 · 6 comments
Milestone

Comments

@damianw
Copy link

damianw commented Aug 22, 2019

  • Markwon version: 4.0.2

I'm not really sure how to reproduce the issue, but am seeing occasional crash reports from Crashlytics like this:

Caused by java.lang.IndexOutOfBoundsException: setSpan (4007 ... 4043) ends beyond length 4007
       at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1327)
       at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:688)
       at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:680)
       at io.noties.markwon.SpannableBuilder.spannableStringBuilder(SpannableBuilder.java:323)
       at io.noties.markwon.MarkwonImpl.render(MarkwonImpl.java:61)
      // ...

I've not been able to reproduce the problem, nor does it seem specific to any device/API level/manufacturer. Perhaps some kind of race condition?

@noties
Copy link
Owner

noties commented Aug 23, 2019

Hello @damianw !

Can you please share the configuration that you use for Markwon (plugins) and approximate markdown that is used? I haven't seen such crashes myself, but from the stacktrace it seems that underlying text and spans-list are out of sync (text is removed but spans are present, or spans are set but text that is never added). But we need more info to pin-point the issue

@noties
Copy link
Owner

noties commented Aug 24, 2019

Hello @damianw !

After looking at this, I wanted to ask if your markdown is lengthy (like over 9000 characters in length), or does your widget has a text limit set? And which one do you use: TextView, EditText or something else?

@damianw
Copy link
Author

damianw commented Aug 26, 2019

@noties Thanks for looking into it! I was able to figure out the problem: we're using a Markwon instance in multiple places to concurrently render different documents, and Markwon instances re-use the MarkwonVisitorImpl. I had just assumed that instances were thread-safe but I guess that they are not. Right now to solve the issue, I'm just going to build a new Markwon instance whenever I need it instead of having a singleton.

It would be nice to support such use cases or at least document that an instance cannot be used from multiple threads concurrently. Thanks for your help, though!

@noties
Copy link
Owner

noties commented Aug 27, 2019

Hello @damianw !

You are bringing attention to an important issue actually. Why exactly a (mutable) Visitor is reused for a Markwon instance... It's kind of legacy and I think there must be no performance-wise downsides if visitor won't be reused (thus making Markwon thread-safe). I'm going to take a look

@noties noties added this to the 4.1.1 milestone Aug 27, 2019
@noties
Copy link
Owner

noties commented Aug 28, 2019

Pushed new 4.1.1-SNAPSHOT version with working implementation

@noties noties mentioned this issue Aug 29, 2019
noties added a commit that referenced this issue Aug 29, 2019
* `markwon-ext-tables`: fix padding between subsequent table blocks ([#159])
* `markwon-images`: print a single warning instead full stacktrace in case when SVG or GIF 
are not present in the classpath ([#160])
* Make `Markwon` instance thread-safe by using a single `MarkwonVisitor` for each `render` call ([#157])
* Add `CoreProps.CODE_BLOCK_INFO` with code-block info (language)

[#159]: #159
[#160]: #160
[#157]: #157
@noties noties closed this as completed Aug 29, 2019
@damianw
Copy link
Author

damianw commented Aug 29, 2019

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants