For your information: FindBugs notes that the generated code for lazy getters may not be correct:Bug: Synchronization performed on java.util.concurrent.atomic.AtomicReference in XXXXXX (place with @Getter(lazy = true)).Maybe you could 'carefully review' the lazy getter's code :)
This method performs synchronization an object that is an instance of a class from the java.util.concurrent package (or its subclasses). Instances of these classes have their own concurrency control mechanisms that are orthogonal to the synchronization provided by the Java keyword
synchronized. For example, synchronizing on anAtomicBooleanwill not prevent other threads from modifying theAtomicBoolean.Such code may be correct, but should be carefully reviewed and documented, and may confuse people who have to maintain the code at a later date.
Confidence: Normal, Rank: Scary (8)
Pattern: JLM_JSR166_UTILCONCURRENT_MONITORENTER
Type: JLM, Category: MT_CORRECTNESS (Multithreaded correctness)
The problem might just be that the lazy getters make use of the AtomicReference; according to Roel Spilker (http://stackoverflow.com/questions/12160250/lombok-lazy-getter-for-mutable-collections/12160664#12160664) that one will probably be going anyway. I don't know whether the reason for that is this bug, but it might just as well be.
Op woensdag 30 mei 2012 11:59:51 UTC+2 schreef Reinier Zwitserloot het volgende:
--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
@Getter(lazy=true) double[] cached = expensive(arg1, arg2, arg3...);Your proposed implementation will always call the extensive operation, every time the getter is called, if the expensive operation returns null. Also, your proposal creates a second field (for the lock). Our current implementation works even if "expensive" returns null, and has a unique lock per lazy getter without adding extra fields.