Skip to content

ArrayIndexOutOfBoundsException in performTag method for Android #122

Open
@UbadahJ

Description

@UbadahJ

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions