You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Spotbugs检测到的EI_EXPOSE_REP2漏洞:外部可变对象存入MyService.observationRegistry的问题

如何修复Spotbugs检测到的EI_EXPOSE_REP2漏洞:外部可变对象存入MyService.observationRegistry的问题

我最近碰到个Spotbugs的检测问题,琢磨好久都没搞定,想请教下大家怎么解决。

事情是这样的,我写了一个特别简单的类:

import io.micrometer.observation.ObservationRegistry;

@Service
public final class MyService {

  private final ObservationRegistry observationRegistry;

  public MyService(final ObservationRegistry registry) {
     this.observationRegistry = registry;
    }

}

结果Spotbugs在observationRegistry这个字段上给我标了个警告:

may expose internal representation by storing an externally mutable object into MyService.observationRegistry

我本来想试试调用registry的clone()方法来复制对象,结果发现这个方法根本不存在,完全行不通。

有没有大佬能告诉我,这个问题该怎么修复呀?

备注:内容来源于stack exchange,提问作者PatPanda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 19:54:50