Carsten Hammer created NETBEANS-5136:
----------------------------------------
Summary: double checked locking idiom wrong in inspect and
transform
Key: NETBEANS-5136
URL: https://issues.apache.org/jira/browse/NETBEANS-5136
Project: NetBeans
Issue Type: Bug
Components: java - Refactoring
Affects Versions: 12.2
Reporter: Carsten Hammer
The pattern implemented in
[https://bz.apache.org/netbeans/show_bug.cgi?id=248740] seems to be wrong
according to
[https://docs.google.com/document/d/1mAeEgQu4H4ADxa03k7YaVDjIP5vJBvjVIjg3DIvoc8E/edit]
The right pattern looks like this:
# 334, Second code example. *_This is a serious error!_* The current code can
return null if multiple threads race to initialize the field. Here’s how the
code should look:
*// Double-check idiom for lazy initialization of instance fields*
private volatile FieldType field;
private FieldType getField() {
FieldType result = field;
if (result != null) // First check (no locking)
return result;
synchronized(this) {
if (field == null) // Second check (with locking)
field = computeFieldValue();
return field;
}
}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists