0

Method local variables would still be accessible while the method has not ended as the reference must be stored somewhere to prevent the Java garbage collector from collecting it. Is there any class or method either in Java or through JNI which can give me access to it or the method stack or locate the object reference?

Assume I am running the Main class from my main class via reflection

The local variable map in the thread class only contains soft reference to string encoder and decoder and the rest of the 8 entries are null.

Android_Dev
  • 41
  • 1
  • 7
  • Possible duplicate of [Can I get information about the local variables using Java reflection?](https://stackoverflow.com/questions/6816951/can-i-get-information-about-the-local-variables-using-java-reflection) – Christian Jul 30 '18 at 10:46
  • I know it is not possible using pure reflection, as they are part of the thread, also name is not important to me just the reference either as object or pointer (long value) – Android_Dev Jul 30 '18 at 11:00
  • 1
    "Method local variables would still be accessible while the method has not ended" this is not exactly true, as stack might be overriden if some variable will go out of scope, like here: https://ideone.com/2e7Ted so then it would be hard to predict what you will have on that stack. So what you are trying to do? Why you need access that local variables? – GotoFinal Jul 30 '18 at 14:09
  • Not sure what "overriden if some variable will go out of scope" in the case you showed the garbage collector was explicitly called and the application would crash if you tried to use the object after the method anyway. In my case i know the object exists as otherwise application would not work/continue, therefore it is still in the stack like the weak reference object. – Android_Dev Jul 30 '18 at 14:30
  • it does not need to be called explicitly here, just removed from stack - but seems that this is not the case here. But again: why you need that? – GotoFinal Jul 30 '18 at 14:32
  • It's my own application I am trying to see what can be accessed from outside and how without reverse engineering or Bytecode manipulation. – Android_Dev Jul 30 '18 at 14:38
  • You can do near anything if you will attach yourself as a debugger, but then you need jdk – GotoFinal Jul 30 '18 at 14:54

0 Answers0