You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2016/10/23 20:18:56 UTC

[lang] LANG-1144: Multiple calls of org.apache.commons.lang3.concurrent.LazyInitializer.initialize() are possible

Repository: commons-lang
Updated Branches:
  refs/heads/master 96c8ea2fb -> dc53e49b4


LANG-1144: Multiple calls of org.apache.commons.lang3.concurrent.LazyInitializer.initialize() are possible

minimal clean-up


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/dc53e49b
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/dc53e49b
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/dc53e49b

Branch: refs/heads/master
Commit: dc53e49b4afa5d59c533cf2b4918402c37411fbd
Parents: 96c8ea2
Author: pascalschumacher <pa...@gmx.net>
Authored: Sun Oct 23 22:18:47 2016 +0200
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Oct 23 22:18:47 2016 +0200

----------------------------------------------------------------------
 .../commons/lang3/concurrent/LazyInitializer.java      | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/dc53e49b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
index a0f903c..ed84049 100644
--- a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
+++ b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
@@ -78,11 +78,12 @@ package org.apache.commons.lang3.concurrent;
  * @param <T> the type of the object managed by this initializer class
  */
 public abstract class LazyInitializer<T> implements ConcurrentInitializer<T> {
+
+    private static final Object noInit = new Object();
+
+    @SuppressWarnings("unchecked")
     /** Stores the managed object. */
-    
-    private static final Object NoInit = new Object();
-    
-    private volatile T object = (T) NoInit;
+    private volatile T object = (T) noInit;
 
     /**
      * Returns the object wrapped by this instance. On first access the object
@@ -98,10 +99,10 @@ public abstract class LazyInitializer<T> implements ConcurrentInitializer<T> {
         // volatile field
         T result = object;
 
-        if (result == NoInit) {
+        if (result == noInit) {
             synchronized (this) {
                 result = object;
-                if (result == NoInit) {
+                if (result == noInit) {
                     object = result = initialize();
                 }
             }


Re: [lang] LANG-1144: Multiple calls of org.apache.commons.lang3.concurrent.LazyInitializer.initialize() are possible

Posted by Pascal Schumacher <pa...@gmx.net>.
Am 24.10.2016 um 22:35 schrieb Oliver Heger:
>
> Minor nit: As the field is now a constant, it should - according to the
> Sun coding conventions - be named in uppercase: NO_INIT.
I thought that only applied to public constants, but I was wrong. I have 
changed the field name.

Thanks,
Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: [lang] LANG-1144: Multiple calls of org.apache.commons.lang3.concurrent.LazyInitializer.initialize() are possible

Posted by Oliver Heger <ol...@oliver-heger.de>.

Am 23.10.2016 um 22:18 schrieb pascalschumacher@apache.org:
> Repository: commons-lang
> Updated Branches:
>   refs/heads/master 96c8ea2fb -> dc53e49b4
> 
> 
> LANG-1144: Multiple calls of org.apache.commons.lang3.concurrent.LazyInitializer.initialize() are possible
> 
> minimal clean-up
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
> Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/dc53e49b
> Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/dc53e49b
> Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/dc53e49b
> 
> Branch: refs/heads/master
> Commit: dc53e49b4afa5d59c533cf2b4918402c37411fbd
> Parents: 96c8ea2
> Author: pascalschumacher <pa...@gmx.net>
> Authored: Sun Oct 23 22:18:47 2016 +0200
> Committer: pascalschumacher <pa...@gmx.net>
> Committed: Sun Oct 23 22:18:47 2016 +0200
> 
> ----------------------------------------------------------------------
>  .../commons/lang3/concurrent/LazyInitializer.java      | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/commons-lang/blob/dc53e49b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
> ----------------------------------------------------------------------
> diff --git a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
> index a0f903c..ed84049 100644
> --- a/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
> +++ b/src/main/java/org/apache/commons/lang3/concurrent/LazyInitializer.java
> @@ -78,11 +78,12 @@ package org.apache.commons.lang3.concurrent;
>   * @param <T> the type of the object managed by this initializer class
>   */
>  public abstract class LazyInitializer<T> implements ConcurrentInitializer<T> {
> +
> +    private static final Object noInit = new Object();
> +
> +    @SuppressWarnings("unchecked")
>      /** Stores the managed object. */

Minor nit: As the field is now a constant, it should - according to the
Sun coding conventions - be named in uppercase: NO_INIT.

Oliver

> -    
> -    private static final Object NoInit = new Object();
> -    
> -    private volatile T object = (T) NoInit;
> +    private volatile T object = (T) noInit;
>  
>      /**
>       * Returns the object wrapped by this instance. On first access the object
> @@ -98,10 +99,10 @@ public abstract class LazyInitializer<T> implements ConcurrentInitializer<T> {
>          // volatile field
>          T result = object;
>  
> -        if (result == NoInit) {
> +        if (result == noInit) {
>              synchronized (this) {
>                  result = object;
> -                if (result == NoInit) {
> +                if (result == noInit) {
>                      object = result = initialize();
>                  }
>              }
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org