You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by "Carsten Hammer (Jira)" <ji...@apache.org> on 2020/12/10 10:24:00 UTC

[jira] [Updated] (NETBEANS-5136) double checked locking idiom wrong in inspect and transform

     [ https://issues.apache.org/jira/browse/NETBEANS-5136?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Carsten Hammer updated NETBEANS-5136:
-------------------------------------
    Description: 
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:

 
{code:java}
// 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;    
   }
}
{code}

  was:
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;

   }

}


> 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
>            Priority: Critical
>
> 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:
>  
> {code:java}
> // 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;    
>    }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists