Skip to content

Commit

Permalink
Don't initialize already initialized final fields. Fixes #1829.
Browse files Browse the repository at this point in the history
  • Loading branch information
rspilker committed Oct 15, 2018
1 parent 11322a4 commit 7ee4ebb
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Lombok Changelog
* FEATURE: Lombok's `@NonNull` annotation can now be used on types (annotation on types has been introduced in JDK 8). `@Builder`'s `@Singular` annotation now properly deals with annotations on the generics type on the collection: `@Singular List<@NonNull String> names;` now does the right thing.
* FEATURE: You can now mix `@SuperBuilder` and `toBuilder`, and `toBuilder` no longer throws `NullPointerException` if an `@Singular`-marked collection field is `null`. [Issue #1324](https://github.com/rzwitserloot/lombok/issues/1324)
* BREAKING CHANGE: Lombok will now always copy specific annotations around (from field to getter, from field to builder 'setter', etcetera): A specific curated list of known annotations where that is the right thing to do (generally, `@NonNull` style annotations from various libraries), as well as any annotations you explicitly list in the `lombok.copyableAnnotations` config key in your `lombok.config` file. Also, lombok is more consistent about copying these annotations. (Previous behaviour: Lombok used to copy any annotation whose simple name was `NonNull`, `Nullable`, or `CheckForNull`). [Issue #1570](https://github.com/rzwitserloot/lombok/issues/1570) and [Issue #1634](https://github.com/rzwitserloot/lombok/issues/1634)
* BUGFIX: `@NoArgsConstructor(force=true)` would try to initialize already initialized final fields in Eclipse. [Issue #1829](https://github.com/rzwitserloot/lombok/issues/1829)
* BUGFIX: When using lombok to compile modularized (`module-info.java`-style) code, if the module name has dots in it, it wouldn't work. [Issue #1808](https://github.com/rzwitserloot/lombok/issues/1808)
* BUGFIX: Errors about lombok not reading a module providing `org.mapstruct.ap.spi` when trying to use lombok in jigsaw-mode on JDK 11. [Issue #1806](https://github.com/rzwitserloot/lombok/issues/1806)
* BUGFIX: Fix NetBeans compile on save. [Issue #1770](https://github.com/rzwitserloot/lombok/issues/1770)
Expand Down
1 change: 1 addition & 0 deletions src/core/lombok/eclipse/handlers/HandleConstructor.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ private static List<EclipseNode> fieldsNeedingExplicitDefaults(EclipseNode type,
for (EclipseNode node : type.down()) {
if (node.getKind() != Kind.FIELD) continue top;
FieldDeclaration fd = (FieldDeclaration) node.get();
if (fd.initialization != null) continue top;
if ((fd.modifiers & ClassFileConstants.AccFinal) == 0) continue top;
if ((fd.modifiers & ClassFileConstants.AccStatic) != 0) continue top;
for (EclipseNode ftp : fieldsToParam) if (node == ftp) continue top;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ public class NoArgsConstructorForce {
private final int[] i;
private final Object[] o;
private final java.util.List<?>[] fullQualifiedList;
private final String alreadyInitialized = "yes";

@java.lang.SuppressWarnings("all")
public NoArgsConstructorForce() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
private final int[] i;
private final Object[] o;
private final java.util.List<?>[] fullQualifiedList;
private final String alreadyInitialized = "yes";
public @java.lang.SuppressWarnings("all") NoArgsConstructorForce() {
super();
this.i = null;
Expand Down
1 change: 1 addition & 0 deletions test/transform/resource/before/NoArgsConstructorForce.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ public class NoArgsConstructorForce {
private final int[] i;
private final Object[] o;
private final java.util.List<?>[] fullQualifiedList;
private final String alreadyInitialized = "yes";
}

0 comments on commit 7ee4ebb

Please sign in to comment.