How to display array length in Eclipse debugger?

When debugging a java program in Eclipse, I see (for example, in the Variables view) the contents of an arbitrary array, see the figure below (with the ByteArrayInputStream.buf field).

View Eclipse Variables with Array

But I can not find the array length field anywhere. Is there a way to show the length of an array in an Eclipse debugger? How can I do it?

+5
source share
2 answers

You can use the Expression view and evaluate the length member:

Tab screen

Keep in mind that the last index is less than the length!

While this works for public members, it seems that explicit members are required for protected members. Consider the following code:

 ... ByteArrayInputStream is = new ByteArrayInputStream(new byte[1769]); ... 

Now, when you evaluate is.buf , the Expressions view displays an array dump, as shown in the question, but the evaluation of is.buf.length not performed using <error(s)_during_the_evaluation> . If we add an explicit conversion to ByteArrayInputStream , the job will be done:

enter image description here

+3
source

Thanks @ ThorbjørnRavnAndersen for your reply (comment). You are right, the last segment of the array (in my case: [1700..1768]) contains the length.

The whole picture:

whole picture

+3
source

All Articles