Created
June 14, 2024 12:17
-
-
Save ali-star/60aa0d7b4b30b423d5cc4a5dcf0e00b6 to your computer and use it in GitHub Desktop.
An extension function to map the Leak class to Throwable
This file contains 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
private fun Leak.toThrowable(): Throwable = Throwable("Memory Leak").apply { | |
val stackTraceElements = ArrayList<StackTraceElement>().apply { | |
val header = StackTraceElement( | |
/* declaringClass = */ "[MemoryLeak] $shortDescription", | |
/* methodName = */ "", | |
/* fileName = */ "", | |
/* lineNumber = */ 0, | |
) | |
add(header) | |
val leakTrace = leakTraces.toString().split("\n").map { | |
StackTraceElement( | |
/* declaringClass = */ "", | |
/* methodName = */ it, | |
/* fileName = */ "", | |
/* lineNumber = */ 0, | |
) | |
} | |
addAll(leakTrace) | |
}.toTypedArray() | |
stackTrace = stackTraceElements | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment