【问题标题】:Objects garbage collected in debug mode在调试模式下收集的对象垃圾
【发布时间】:2019-03-02 07:56:49
【问题描述】:

我有一个简单的 JUnit 测试

@Test
public void validateMoney() throws IOException {

    ObjectMapper mapper = new ObjectMapper();
    mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    FileInputStream fileStream = new FileInputStream("src/test/resources/IndividualMoney.json");
    Money money = mapper.readValue(fileStream, Money.class);
    List<Person> people = personService.execute(money);

每当我在 Linux 中的 java Oxygen 上运行调试并尝试访问人员列表时,我都会在检索值时得到 com.sun.jdi.objectcollectedexception。我读过类似的问题,其中一个解决方案是取消选中 window/preferences/debug Show method result after a step operation 我取消选中它,但结果是一样的

【问题讨论】:

    标签: java spring eclipse junit


    【解决方案1】:

    您可以使用(调用)人员列表来确保它不会被 GC。

    List<Person> people = personService.execute(money);
    people.forEach(System.out::println);
    

    现在,people.forEach(System.out::println) 上的调试标志应该允许您浏览 people 列表。

    这能解决您的问题吗?

    【讨论】:

      猜你喜欢
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      • 2012-12-28
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多