I have a very large app that takes a value and makes it disappear SOMEWHERE and I want to see where it is going. So what I'm looking for the is the value of the variable so I can find out what variable is holding it. I'm hoping there is some sort of technique, possibly involving a classloader or reflection?
-
can you use an ide? if it inside a class it's private? it's a local variable? if has setter and getters? you can take approach of observer pattern if is that, or just debug with your ide an inspect it. – nachokk Sep 18 '13 at 19:16
-
possible duplicate of [how to use conditional breakpoint in eclipse?](http://stackoverflow.com/questions/7194326/how-to-use-conditional-breakpoint-in-eclipse) – Kowser Sep 18 '13 at 19:26
-
It is good that you asked, however needed to try a bit more. Please upvote that answer. – Kowser Sep 18 '13 at 19:28
-
That approach seems flawed: How do you know the value is moved rather than simply overwritten or otherwise discarded? – meriton Sep 18 '13 at 19:38
-
The value begins in a file and I can see the value in the output of the program. Unfortunately, the amount of reflection makes it nearly impossible to find where the value of the file is read and stored. – A.J.Gibson Sep 18 '13 at 19:50
5 Answers
Don't think there is an easy way to do it through the debugger, as it lets you specify the variable names, not the value names :)
You should be able to get handles to your classes and iterate through them and iterate through each field in the class, like in: java: get all variable names in a class
Based on your value you are looking for, you probably know the type you are seeking, so I'd recommend adding some type checks before you do your checks. If you have a method do this for you, then you can build a list with the results, which you would then be able to inspect easily with the debugger.

- 1
- 1

- 19,579
- 27
- 94
- 160
If you are using Eclipse, or most IDE's for that matter, you can set break points, and use the debugger to step through your processes and see what each variables value is at that point in the code.
If you aren't using Eclipse, or most IDE's for that matter, you might consider doing so, so that you can use the debug feature.

- 23,275
- 22
- 95
- 156
depends on your IDE but the common ones (Eclipse, Netbeans, IntelliJ) allow you to set watches
- variables which you'll see their values during debug. Also, if you set breakpoints - you can hover over the variable and it'll show its value.

- 53,191
- 11
- 86
- 129
-
I am using Eclipse. The problem is that in the hundred of classes involved, I have no idea which class is doing the work. I'm trying to find out where to set the breakpoint where SOME VARIABLE is being set to a known value. It is a reverse of what breakpoints do. With a breakpoint, you know what code you want to examine and you can learn what values variable have. I know what values I want to look at, but I don't know what class holds the variable. Basically: I want to know what variable is being to a value I know. – A.J.Gibson Sep 18 '13 at 19:23
-
If you're using setters it's easy cause there's only one line where you'll need to set a breakpoint. Otherwise, you need to have at least one point in the code that you know when its being called, and start debugging from there (using "step in/out/over" options of the debugger). If there's a log it could help too ;) – Nir Alfasi Sep 18 '13 at 19:26
-
Believe it or not, I don't even have one point in the code where I know it's being used, I just know it's in the input and in the output. – A.J.Gibson Sep 18 '13 at 19:52
-
@A.J.Gibson if there is no documentation, no "main" method, no helpful code comments, no keywords you can use to search, no log and no developer that can provide a quick training (and show you the general flow, critical points in the code etc) - then my friend, you'll have to do it the hard way: start adding breakpoints to every class, in every constructor and debug it over and over again until you understand at least the basic flow. There's no magic here. Sorry. – Nir Alfasi Sep 18 '13 at 20:06
-
And just to make matters worse, if you find one variable set to this Value, there is no guarantee that there aren't 100 OTHER variables set to the SAME value. Or that that variable will remain set to that value for any length of time. I think, if you really want help, you're going to have to take a step backwards and ask for help with what you want to do, rather than a half-baked attempt at describing an IDE feature that, as it turns out, doesn't exist. – arcy Sep 18 '13 at 20:16
Have you looked into using an IDE such as Eclipse? There are some pretty nifty debugging features that let you track variables throughout the program and set break points in the code where the program will pause and you can look at all states and even change them.

- 76
- 7
If you want to capture a certain value during the iteration of a loop, Catch the value programatically using a If loop and the value.
You can use some intercept to identify the class that has last set the value.
Are you getting any exception ?

- 425
- 1
- 5
- 15