Skip to content

Commit

Permalink
Fixes #1236: Getter(lazy=true) now emits an error when used on a tran…
Browse files Browse the repository at this point in the history
…sient field
  • Loading branch information
rspilker committed Dec 5, 2016
1 parent 0727c8b commit cf82dcf
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 4 deletions.
5 changes: 3 additions & 2 deletions doc/changelog.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ Lombok Changelog

### v1.16.11 "Edgy Guinea Pig"
* v1.16.10 is the latest release
* CHANGE: `@Value` and `@FieldDefaults` no longer touch static fields [Issue #1254](https://github.com/rzwitserloot/lombok/issues/1254)
* FEATURE: `var` is the mutable sister of `val`. For now experimental, and opt-in using `ALLOW` in the flagUsage configuration key. Thanks for the contribution, Bulgakov Alexander.
* BUGFIX: Annotation Processors that use ecj internally (dagger) no longer give linkage errors [Issue #1218](https://github.com/rzwitserloot/lombok/issues/1218)
* CHANGE: `@Value` and `@FieldDefaults` no longer touch static fields [Issue #1254](https://github.com/rzwitserloot/lombok/issues/1254)
* BUGFIX: `val` in lambda expressions now work as expected [Issue #911](https://github.com/rzwitserloot/lombok/issues/911)
* BUGFIX: `Getter(lazy=true)` now emits an error message when used on a transient field [Issue #1236](https://github.com/rzwitserloot/lombok/issues/1236)
* BUGFIX: Annotation Processors that use ecj internally (dagger) no longer give linkage errors [Issue #1218](https://github.com/rzwitserloot/lombok/issues/1218)
* PLATFORM: Red Hat JBoss Developer Studio is now correctly identified by the installer [Issue #1164](https://github.com/rzwitserloot/lombok/issues/1164)
* BUGFIX: delombok: for-loops with initializers that are not local variables would be generated incorrectly [Issue #1076](https://github.com/rzwitserloot/lombok/issues/1076)

Expand Down
6 changes: 5 additions & 1 deletion src/core/lombok/eclipse/handlers/HandleGetter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 The Project Lombok Authors.
* Copyright (C) 2009-2016 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
Expand Down Expand Up @@ -183,6 +183,10 @@ public void createGetterForField(AccessLevel level,
errorNode.addError("'lazy' requires the field to be private and final.");
return;
}
if ((field.modifiers & ClassFileConstants.AccTransient) != 0) {
errorNode.addError("'lazy' is not supported on transient fields.");
return;
}
if (field.initialization == null) {
errorNode.addError("'lazy' requires field initialization.");
return;
Expand Down
6 changes: 5 additions & 1 deletion src/core/lombok/javac/handlers/HandleGetter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009-2014 The Project Lombok Authors.
* Copyright (C) 2009-2016 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
Expand Down Expand Up @@ -182,6 +182,10 @@ public void createGetterForField(AccessLevel level,
source.addError("'lazy' requires the field to be private and final.");
return;
}
if ((fieldDecl.mods.flags & Flags.TRANSIENT) != 0) {
source.addError("'lazy' is not supported on transient fields.");
return;
}
if (fieldDecl.init == null) {
source.addError("'lazy' requires field initialization.");
return;
Expand Down
26 changes: 26 additions & 0 deletions test/transform/resource/after-delombok/GetterLazyTransient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class GetterLazyTransient {
private final java.util.concurrent.atomic.AtomicReference<java.lang.Object> nonTransientField = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
private final transient int transientField = 2;
private final transient int nonLazyTransientField = 3;
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public int getNonTransientField() {
java.lang.Object value = this.nonTransientField.get();
if (value == null) {
synchronized (this.nonTransientField) {
value = this.nonTransientField.get();
if (value == null) {
final int actualValue = 1;
value = actualValue;
this.nonTransientField.set(value);
}
}
}
return (java.lang.Integer) value;
}
@java.lang.SuppressWarnings("all")
@javax.annotation.Generated("lombok")
public int getNonLazyTransientField() {
return this.nonLazyTransientField;
}
}
28 changes: 28 additions & 0 deletions test/transform/resource/after-ecj/GetterLazyTransient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class GetterLazyTransient {
private final @lombok.Getter(lazy = true) java.util.concurrent.atomic.AtomicReference<java.lang.Object> nonTransientField = new java.util.concurrent.atomic.AtomicReference<java.lang.Object>();
private final transient @lombok.Getter(lazy = true) int transientField = 2;
private final transient @lombok.Getter int nonLazyTransientField = 3;
GetterLazyTransient() {
super();
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getNonTransientField() {
java.lang.Object value = this.nonTransientField.get();
if ((value == null))
{
synchronized (this.nonTransientField)
{
value = this.nonTransientField.get();
if ((value == null))
{
final int actualValue = 1;
value = actualValue;
this.nonTransientField.set(value);
}
}
}
return (java.lang.Integer) value;
}
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int getNonLazyTransientField() {
return this.nonLazyTransientField;
}
}
10 changes: 10 additions & 0 deletions test/transform/resource/before/GetterLazyTransient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class GetterLazyTransient {
@lombok.Getter(lazy=true)
private final int nonTransientField = 1;

@lombok.Getter(lazy=true)
private final transient int transientField = 2;

@lombok.Getter
private final transient int nonLazyTransientField = 3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 'lazy' is not supported on transient fields.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5 'lazy' is not supported on transient fields.

0 comments on commit cf82dcf

Please sign in to comment.