findbugs - Spotbugs + Java: EI_EXPOSE_REP2 may expose internal representation by storing an externally mutable object into MySer

Small question regarding a Spotbugs finding I am having a hard time fixing.In this super simple class:

Small question regarding a Spotbugs finding I am having a hard time fixing.

In this super simple class:

import io.micrometer.observation.ObservationRegistry;

@Service
public final class MyService {

  private final ObservationRegistry observationRegistry;

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

I am getting flagged on the observationRegistry with

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

I tried invoking a possible clone() method on the registry, but no luck.

How do I fix this?

Small question regarding a Spotbugs finding I am having a hard time fixing.

In this super simple class:

import io.micrometer.observation.ObservationRegistry;

@Service
public final class MyService {

  private final ObservationRegistry observationRegistry;

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

I am getting flagged on the observationRegistry with

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

I tried invoking a possible clone() method on the registry, but no luck.

How do I fix this?

Share Improve this question asked Mar 27 at 22:04 PatPandaPatPanda 5,12828 gold badges116 silver badges251 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 1

Did you read the whole description? https://spotbugs.readthedocs.io/en/latest/bugDescriptions.html#ei2-may-expose-internal-representation-by-incorporating-reference-to-mutable-object-ei-expose-rep2

EI2: May expose internal representation by incorporating reference to mutable object (EI_EXPOSE_REP2) This code stores a reference to an externally mutable object into the internal representation of the object. If instances are accessed by untrusted code, and unchecked changes to the mutable object would compromise security or other important properties, you will need to do something different. Storing a copy of the object is better approach in many situations.

The whole point here is making internal data available externally, I'm not sure this is valid here since "untrusted code" might be able to just "attack" your registered handlers or read their outputs. Also, I might misunderstand this but if your instances can be accessed by "untrusted code", I'm not sure this will save you from anything. I guess the solution here is rather not adding sensitive data to your Observations (and supress the warning).

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744065752a4552616.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信