Lombok: @Value and @FieldDefaults should skip static fields

Created on 5 Dec 2016  路  3Comments  路  Source: projectlombok/lombok

@Value and @FieldDefaults add the private and final modifiers to the fields if possible. This behavior is influenced by @NonFinal and @PackagePrivate.

For instance fields, this makes sense. But for package private static non-final fields, this is an unexpected side-effect of adding @Value

Most helpful comment

I'm just upgrading my Lombok JAR from 1.16.10 to 1.16.16 and this "correction" just killed all my projects.

My very simple use case is to put @UtilityClass and @FieldDefaults(makeFinal = true, level = AccessLevel.PUBLIC) to get a class to store my constants.

Now, everything is broken in all my projects and it makes Lombock useless for that kind of configuration.
I go back to do everything manualy.

All 3 comments

Would it be possible to add optional support for static fields in @FieldDefaults?

I'm just upgrading my Lombok JAR from 1.16.10 to 1.16.16 and this "correction" just killed all my projects.

My very simple use case is to put @UtilityClass and @FieldDefaults(makeFinal = true, level = AccessLevel.PUBLIC) to get a class to store my constants.

Now, everything is broken in all my projects and it makes Lombock useless for that kind of configuration.
I go back to do everything manualy.

Another simple use case : on my "POJO beans" (ex : @Entity @Data serializable classes), I use @FieldDefaults(level = AccessLevel.PRIVATE), as certainly almost everybody using Lombok.
Now I have to manually write that serialVersionUID is private.

But, in fact, I use it in a "lombok.config" file to have it by default on the entire project. So I have to search for all my static fields and manually make them private where needed...

It looks like 2 little things (combined with my previous post), but in the big company I'm working for, because all the newly (last 2 years) created applications (at least a dozen) use a parent Maven dependency configuration including Lombok, that king of modification causes a not so little work to do when updating...

Was this page helpful?
0 / 5 - 0 ratings