Getter construction defective with small boolean lazy field #449

Closed
lombokissues opened this Issue Jul 14, 2015 · 8 comments

Projects

None yet

1 participant

@lombokissues
Collaborator

Migrated from Google Code (issue 376)

@lombokissues
Collaborator

๐Ÿ‘ค k.tinnefeld ย  ๐Ÿ•— May 24, 2012 at 11:14 UTC

What steps will reproduce the problem?

  1. Create test class in eclipse

import lombok.Data;
import lombok.Getter;

@ Data
public class BooleanLazyDefective {

@ Getter(lazy = true)
private final boolean flag = expensive();

private boolean expensive() {
    return true;
}

}

  1. enjoy seven errors "The method getFlag() is undefined for the type BooleanLazyDefective"

What is the expected output? What do you see instead?

The lombok computed getter "isFlag" is being used in the places mentioned. Tries to read "getFlag" instead.

Using delombok, the error is the other way round: a lazy getter "getFlag" is generated, but "isFlag" is accessed in seven locations.

The single part annotations @ ToString etc. behave exactly the same, restricted to their resp. domain.

What version of the product are you using? On what operating system?

Lombok 0.11.0 on Eclipse 3.7.2, Win 7 64 Bit, Java 6 u 30.

Please provide any additional information below.

@lombokissues
Collaborator

๐Ÿ‘ค k.tinnefeld ย  ๐Ÿ•— Jun 12, 2012 at 19:55 UTC

The javac/delombok issue is quite easily fixed by memorizing the original getter name.

cf. https://bitbucket.org/tinne/lombok-fixes/changeset/e67fab1703c7

@lombokissues
Collaborator

๐Ÿ‘ค k.tinnefeld ย  ๐Ÿ•— Jun 12, 2012 at 21:19 UTC

The eclipse issue is harder as it needs to check isProperty getters not only on boolean, but also on AtomicReference<AtomicReference> fields, and those must not refer to big Boolean properties.

This is solved by https://bitbucket.org/tinne/lombok-fixes/changeset/47a17156675a

Test file:

import java.util.concurrent.atomic.AtomicReference;
import lombok.Data;
import lombok.Getter;

@ Data
public class BoolTest {

@ Getter(lazy = true)
private final boolean flag = expensive();

@ Getter(lazy = true)
private final Boolean falsePositive = ! expensive(); 

public AtomicReference<AtomicReference<Boolean>> isFalsePositive() { return null; }  

private boolean expensive() {
    return true;
}

}

@lombokissues
Collaborator

๐Ÿ‘ค r.spilker ย  ๐Ÿ•— Jun 18, 2012 at 18:14 UTC

Hi K,

Thanks for taking the time to investigate this problem. I didn't look at your patch. We can (regrettable) legally only allow patches via a pull request on github. If you do that you can also add your name to the AUTHORS file so you get the credits and we are legally safe.

After you submit a pull request I can look into the code, potentially give feedback and/or merge it.

I can confirm that javac/delombok generates getXxx instead of isXxx but calls isXxx in equals, hashCode and toString. On the other hand, in Eclipse the right method name is generated, but the wrong one is called in equals, hashCode and toString, even leading to the generation of intermediate local variables of type Object.

@lombokissues
Collaborator

๐Ÿ‘ค r.spilker ย  ๐Ÿ•— Jun 18, 2012 at 18:58 UTC

The fix for javac is to move the call to determine the name to before generating the method body, in which the type is changed.

@lombokissues
Collaborator

๐Ÿ‘ค k.tinnefeld ย  ๐Ÿ•— Jun 18, 2012 at 20:48 UTC

On github, this is now tinne/lombok@e67fab1

@lombokissues
Collaborator

๐Ÿ‘ค r.spilker ย  ๐Ÿ•— Jun 18, 2012 at 21:45 UTC

Fixed in 37cbe2d

@lombokissues lombokissues removed the accepted label Jul 14, 2015
@lombokissues
Collaborator

End of migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment