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

ArrayIndexOutOfBoundsException in performTag method for Android #122

Open
UbadahJ opened this issue Jan 11, 2024 · 6 comments
Open

ArrayIndexOutOfBoundsException in performTag method for Android #122

UbadahJ opened this issue Jan 11, 2024 · 6 comments

Comments

@UbadahJ
Copy link

UbadahJ commented Jan 11, 2024

I am experiencing a recurring crash in my application, which seems to be related to an ArrayIndexOutOfBoundsException. The stack trace is as follows:

Exception java.lang.ArrayIndexOutOfBoundsException: length=9; index=9
    at io.github.aakira.napier.DebugAntilog.performTag (DebugAntilog.java:78)
    at io.github.aakira.napier.DebugAntilog.performLog (DebugAntilog.java:78)
    at io.github.aakira.napier.Antilog.rawLog$napier_release (Antilog.java:78)
    at io.github.aakira.napier.Napier.rawLog (Napier.kt:78)
    at io.github.aakira.napier.Napier.log (Napier.kt:78)
    at io.github.aakira.napier.Napier.e (Napier.kt:136)
    at io.github.aakira.napier.Napier.e$default (Napier.java:136)

Code Inspection:
Upon reviewing the related code, I noticed the potential cause in the performTag function:

private fun performTag(tag: String): String {
    val thread = Thread.currentThread().stackTrace

    return if (thread.size >= CALL_STACK_INDEX) {
        thread[CALL_STACK_INDEX].run {
            "${createStackElementTag(className)}\$$methodName"
        }
    } else {
        tag
    }
}

Possible Solution:
It appears that replacing thread.size >= CALL_STACK_INDEX with thread.size > CALL_STACK_INDEX could resolve the issue.

Question:
Is this indeed a bug, or am I missing some other aspect of the implementation that could be causing this error?

@robertvoigt030
Copy link

robertvoigt030 commented May 27, 2024

  thread[CALL_STACK_INDEX].run { ....

As it is private const val CALL_STACK_INDEX = 9 for Android Module and all other modules it is private const val CALL_STACK_INDEX = 8. So simply editing the constant CALL_STACK_INDEX to the value 8 for Android / Java module should fix this crash.

@LambergaR
Copy link

@AAkira is this getting fixed? :)

@Endless-Lemniscate
Copy link

Faced with same issue. Any updates?

@OSemenovBoyarka
Copy link

Same issue for me, but it reproduces only for minified version of the app.

@LambergaR
Copy link

well, this was a complete waste of another couple of hours ...

this can also happen on the .d method call, at least in the minified version

@robertvoigt030
Copy link

Still the same...any updates here?

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

No branches or pull requests

5 participants