/*
 * Minimal Object Storage Library, (C) 2015 Minio, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.minio.client;

import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.Manifest;

enum MinioProperties {
    INSTANCE;
    private String version = null;

    public String getVersion() {
        if (version == null) {
            synchronized (INSTANCE) {
                if (version == null) {
                    try {
                        Enumeration<URL> resources = getClass().getClassLoader().getResources("META-INF/MANIFEST.MF");
                        while (resources.hasMoreElements()) {
                            Manifest manifest = new Manifest(resources.nextElement().openStream());
                            for (Object k : manifest.getMainAttributes().keySet()) {
                                String versionString = "Minio-Client-Java-Version";
                                if (k.toString().equals(versionString)) {
                                    version = manifest.getMainAttributes().getValue((Attributes.Name) k);
                                }
                            }
                        }
                        if (version == null) {
                            version = "dev";
                        }
                    } catch (IOException e) {
                        version = "unknown";
                    }
                }
            }
        }
        return version;
    }
}

@@ -716,24 +716,76 @@
 numeration;%0A
+import java.util.concurrent.atomic.AtomicReference;%0A
 import java.
@@ -886,22 +886,45 @@
 private 
+final AtomicReference%3C
 String
+%3E
  version
@@ -926,20 +926,49 @@
 rsion = 
+new AtomicReference%3CString%3E(
 null
+)
 ;%0A%0A    p
@@ -999,35 +999,73 @@
 ) %7B%0A        
-if (version
+String result = version.get();%0A        if (result
  == null) %7B%0A
@@ -1121,32 +1121,38 @@
      if (version
+.get()
  == null) %7B%0A    
@@ -1740,19 +1740,21 @@
  version
- = 
+.set(
 manifest
@@ -1803,16 +1803,17 @@
 Name) k)
+)
 ;%0A      
@@ -1931,16 +1931,22 @@
 (version
+.get()
  == null
@@ -1988,16 +1988,19 @@
 sion
- = 
+.set(
 %22dev%22
+)
 ;%0A  
@@ -2100,19 +2100,21 @@
  version
- = 
+.set(
 %22unknown
@@ -2114,16 +2114,17 @@
 unknown%22
+)
 ;%0A      
@@ -2131,32 +2131,76 @@
               %7D%0A
+                    result = version.get();%0A
                 
@@ -2240,23 +2240,22 @@
  return 
-version
+result
 ;%0A    %7D%0A

Fix race condition in retrieving version from manifest