简体   繁体   中英

Findbugs creating issues with Lombok builder

I am breaking my head and time on this weird issue with Lombok builder.

Lets say we have a class

@builder
class DateTest {
 @Column (name="insert_time")
 private Date curDate;
  }

Now on running findbugs it will complain this error EI_EXPOSE_REP2. The reason being builder do not use a copy of Date object.

What is the proper fix for it? The point is I do not want to change the date datatype to String just for workaround and I dont want to suppress the findbugs error as it is not actually going to solve our problem. Anyone found some proper fix for it?

There is no way to achieve that with Lombok. The Lombok builders will not create copies, neither the constructors or setters. The proper fix is not to use the autogenerated builder, at least not at class level.

You get around the issue by using a constructor function instead that does the copying for you:

@Builder
private DateTest createDateTest(Date curDate) {
    …
}

Of course, you cannot profit from the autogenerated constructor then, but at least you get the builder.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM