Search code examples
javaeclipsedebuggingeclipse-jdt

Eclipse JDT - How to watch non-public variables?


I am not new to programming but I am just learning the Java language and Eclipse. I want to see how Java works internally for some of the various "standard" imported classes using Eclipse's debug facilities (JDT Debug). My setup (Oxygen w/ JDK SE8 on Windows 8.1) works fine as far as single stepping through the code but many of the imported Class variables are unable to be placed into a watchlist or expression monitor, which I think is because they are not defined as "public".

As an example: I want to learn how java.math.BigInteger works so I wrote a quick program which uses the pow() method. The program runs successfully, and when using debug mode I am able to track the flow fine as well. What I cannot seem to do is to see the values of the internal "default" (no access modifier) variables. Below are three such variables found in BigInteger.java (lines 2225-2231):

int powersOfTwo = partToSquare.getLowestSetBit();
long bitsToShift = (long)powersOfTwo * exponent;
if (bitsToShift > Integer.MAX_VALUE) {
    reportOverflow();
}

int remainingBits;

Any suggestions on how to expose these variables to JDT Debug for learning purposes?


Solution

  • I guess this is not about public vs. non-public but about fields vs. local variables.

    Compilation may drop information about local variables, so the debugger no longer has information about their names. In that case a watch expression using that name cannot be resolved. The Variables view should, however, still show the value, albeit with artificial names like arg0 ... You can still correlate the variable to what you see in the source code, as local variables are only added to the Variables view when during stepping you reach the corresponding declaration.