diff options
6 files changed, 66 insertions, 4 deletions
diff --git a/doc/changelog.markdown b/doc/changelog.markdown index a775e0c6..0746459e 100644 --- a/doc/changelog.markdown +++ b/doc/changelog.markdown @@ -2,7 +2,7 @@ Lombok Changelog ---------------- ### v1.16.7 "Edgy Guinea Pig" -* New edge +* BUGFIX: `@Value` and `@FieldDefaults` no longer make uninitialized static fields final. [Issue #928](https://github.com/rzwitserloot/lombok/issues/928). ### v1.16.6 (August 18th, 2015) * FEATURE: `@Helper` can be placed on method-local inner classes to make all methods in the class accessible to the rest of the method. [Full documentation](https://projectlombok.org/features/experimental/Helper.html). diff --git a/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java b/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java index 7d0702db..33e796b7 100644 --- a/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java +++ b/src/core/lombok/eclipse/handlers/HandleFieldDefaults.java @@ -96,7 +96,9 @@ public class HandleFieldDefaults extends EclipseAnnotationHandler<FieldDefaults> if (makeFinal && (field.modifiers & ClassFileConstants.AccFinal) == 0) { if (!hasAnnotation(NonFinal.class, fieldNode)) { - field.modifiers |= ClassFileConstants.AccFinal; + if ((field.modifiers & ClassFileConstants.AccStatic) == 0 || field.initialization != null) { + field.modifiers |= ClassFileConstants.AccFinal; + } } } diff --git a/src/core/lombok/javac/handlers/HandleFieldDefaults.java b/src/core/lombok/javac/handlers/HandleFieldDefaults.java index 335ab1fe..95effded 100644 --- a/src/core/lombok/javac/handlers/HandleFieldDefaults.java +++ b/src/core/lombok/javac/handlers/HandleFieldDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2014 The Project Lombok Authors. + * Copyright (C) 2012-2015 The Project Lombok Authors. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -90,7 +90,9 @@ public class HandleFieldDefaults extends JavacAnnotationHandler<FieldDefaults> { if (makeFinal && (field.mods.flags & Flags.FINAL) == 0) { if (!hasAnnotationAndDeleteIfNeccessary(NonFinal.class, fieldNode)) { - field.mods.flags |= Flags.FINAL; + if ((field.mods.flags & Flags.STATIC) == 0 || field.init != null) { + field.mods.flags |= Flags.FINAL; + } } } diff --git a/test/transform/resource/after-delombok/ValueStaticField.java b/test/transform/resource/after-delombok/ValueStaticField.java new file mode 100644 index 00000000..cec136f4 --- /dev/null +++ b/test/transform/resource/after-delombok/ValueStaticField.java @@ -0,0 +1,29 @@ +final class ValueStaticField { + private static int x; + private static final String PASSWORD = "Ken sent me"; + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public ValueStaticField() { + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public boolean equals(final java.lang.Object o) { + if (o == this) return true; + if (!(o instanceof ValueStaticField)) return false; + return true; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public int hashCode() { + int result = 1; + return result; + } + @java.lang.Override + @java.lang.SuppressWarnings("all") + @javax.annotation.Generated("lombok") + public java.lang.String toString() { + return "ValueStaticField()"; + } +}
\ No newline at end of file diff --git a/test/transform/resource/after-ecj/ValueStaticField.java b/test/transform/resource/after-ecj/ValueStaticField.java new file mode 100644 index 00000000..4ce84a02 --- /dev/null +++ b/test/transform/resource/after-ecj/ValueStaticField.java @@ -0,0 +1,24 @@ +import lombok.Value; +final @Value class ValueStaticField { + private static int x; + private static final String PASSWORD = "Ken sent me"; + <clinit>() { + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") boolean equals(final java.lang.Object o) { + if ((o == this)) + return true; + if ((! (o instanceof ValueStaticField))) + return false; + return true; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int hashCode() { + int result = 1; + return result; + } + public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() { + return "ValueStaticField()"; + } + public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") ValueStaticField() { + super(); + } +}
\ No newline at end of file diff --git a/test/transform/resource/before/ValueStaticField.java b/test/transform/resource/before/ValueStaticField.java new file mode 100644 index 00000000..f731758a --- /dev/null +++ b/test/transform/resource/before/ValueStaticField.java @@ -0,0 +1,5 @@ +import lombok.Value; +@Value class ValueStaticField { + static int x; + static String PASSWORD = "Ken sent me"; +} |