I'm trying to check the stack safety of some very complex code, and would like a way to check the current depth of the call stack and get the result as an integer. I can kind of see how I'd stitch something together, but it involves imports and creating an exception... is there an easier or more elegant way?
For context, I have some very sophisticated, FP-heavy code that I suspect is not stack safe for arbitrary input. I have a lot of general ideas on how to check that, but I don't know that there isn't some black magic in play, so I'd like to check the actual stack depth.
EDIT: Someone suggested this as a duplicate, but:
- When I try to use that method, it gives me inconsistent results - sometimes I get what looks like reasonable stack depth, others I get "10" for everything, including a test I wrote to intentionally stack overflow. I'm hoping there's an alternate method available.
- Even if it is the best available, the question refers to Java, and it might be easier for future people investigating the Scala situation to find that it is in fact the same without having to ask.