Eclipse: Debugging & inspection of variables causes com.sun.jdi.ObjectCollectedException

10,455

Solution 1

Right click the variable, then click "Show Logical Structure", uncheck any collection.

Solution 2

While execution of your code is stopped at a breakpoint:

  1. Right-click the variable in the Variables pane
  2. Clicking on the collections (such as the Array in the image below) will uncheck them
  3. Now you can inspect the variable

enter image description here

Solution 3

This bug has been fixed in Eclipse 4.18

https://www.eclipse.org/eclipse/news/4.18/jdt.php

Stabilized logical structures in Variables view with active GC

The Debug view no longer breaks when logical structures are shown while the application's garbage collector is active (com.sun.jdi.ObjectCollectedException occurred while retrieving value).

Share:
10,455

Related videos on Youtube

LeO
Author by

LeO

Updated on September 16, 2022

Comments

  • LeO
    LeO over 1 year

    I debug my program and add here and there a breakpoint. After a stop I want to inspect some of the variables and get sometimes a com.sun.jdi.ObjectCollectedException. After searching in different sources I figured out that most likely the object was Garbage Collected. Clicking here and there I could retrieve my object by nevertheless in the Variables view I cannot inspect the variable.

    -vmargs
    -Dosgi.requiredJavaVersion=1.8
    [email protected]/eclipse-workspace
    -XX:+UseG1GC
    -XX:+UseStringDeduplication
    --add-modules=ALL-SYSTEM
    -Dosgi.requiredJavaVersion=1.8
    -Xms512m
    -Xmx4096m
    --add-modules=ALL-SYSTEM
    

    I'm running under Linux/OpenSuSe with OpenJDK 1.8.0_151. Any hints how to avoid that kind of GC problems? Is this some kind of setting in the IDE?

    • LMC
      LMC about 6 years
      If the object was garbage collected you are inspecting it at the wrong place, the object is alive before that breakpoint.
    • LeO
      LeO about 6 years
      Yeah, but after a while keeping the editor open the object cannot be inspected any further. Therefore I assume its GCed
    • Jeremy Bunn
      Jeremy Bunn over 5 years
  • M46
    M46 almost 5 years
    Works for me but I don't understand why?
  • javaPlease42
    javaPlease42 over 4 years
    Note: The variable that you right click must be a collection and not an Object.