A.J.Gibson
A.J.Gibson

Reputation: 1

When Debugging in Java, is there a way to detect if ANY variable is set to a given value?

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?

Upvotes: 0

Views: 980

Answers (5)

BlackHatSamurai
BlackHatSamurai

Reputation: 23503

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.

Upvotes: 0

Jess
Jess

Reputation: 425

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 ?

Upvotes: 0

James Oravec
James Oravec

Reputation: 20381

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.

Upvotes: 1

Mike-Marshall
Mike-Marshall

Reputation: 76

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.

Upvotes: 0

Nir Alfasi
Nir Alfasi

Reputation: 53535

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.

Upvotes: 0

Related Questions