为什么我的对象已被IntelliJ IDEA的调试器无声地更改?

hic*_*cup 5 java debugging intellij-idea

我正在调试(Shift + F9)offer(E e)JDK8 API的方法java.util.concurrent.ConcurrentLinkedQueue

我发现IntelliJ IDEA head在调试过程中会无声地更改此队列的字段,

但是运行模式(Shift + F10)不会更改字段,为什么?

并且没有代码更改此字段中的内容offer(E e),这让我感到困惑。

然后,我尝试了另一个IDE(Eclipse Mars.1版本(4.5.1)),它没有这种问题。

我的测试有一些结果:

  • 运行模式(Shift + F10)
head: 1159190947 
head: 1159190947 
head: 1159190947 
head: 1159190947 
Run Code Online (Sandbox Code Playgroud)
  • 调试模式(逐步:F8)
head: 1989972246 
head: 1791930789 
head: 1791930789 
head: 1791930789 
Run Code Online (Sandbox Code Playgroud)
  • 调试模式(恢复程序:F9)
head: 1989972246 
head: 1989972246 
head: 1791930789 
head: 1791930789 
Run Code Online (Sandbox Code Playgroud)

版本信息:
IntelliJ IDEA 2018.1(Ultimate Edition)
Build#IU-181.4203.550,建于2018年3月27日
JRE:1.8.0_162-b12 amd64
JVM:Oracle Corporation
Windows 10 10.0的Java HotSpot(TM)64位服务器VM

IntelliJ IDEA的2018年2月3日(社区版)IntelliJ IDEA的2019.1(终极版) 有同样的问题。

import java.lang.reflect.Field;
import java.util.concurrent.ConcurrentLinkedQueue;

public class ConcurrentLinkedQueueTest {

    public static void main(String[] args) {
        ConcurrentLinkedQueue<String> queue = new ConcurrentLinkedQueue<>();
        print(queue);
        queue.offer("aaa");
        print(queue);
        queue.offer("bbb");
        print(queue);
        queue.offer("ccc");
        print(queue);
    }

    /**
     * ??????head???identityHashCode
     * @param queue
     */
    private static void print(ConcurrentLinkedQueue queue) {
        Field field = null;
        boolean isAccessible = false;
        try {
            field = ConcurrentLinkedQueue.class.getDeclaredField("head");
            isAccessible = field.isAccessible();
            if (!isAccessible) {
                field.setAccessible(true);
            }
            System.out.println("head: " + System.identityHashCode(field.get(queue)));
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            field.setAccessible(isAccessible);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

yol*_*ole 5

默认情况下,IntelliJ IDEA toString()在对象上调用该方法以在“监视”视图中获取其表示。在中ConcurrentLinkedQueue,该toString()方法遍历集合,该集合可以head通过方法中的updateHead()调用来更新字段first()(可能在其他地方,我没有研究整个实现。

如果转到首选项| 构建,执行,部署| 调试器 数据视图 Java并关闭“启用toString()对象视图”,您应该不再观察到此行为。