You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tamaya.apache.org by pl...@apache.org on 2015/01/16 21:51:33 UTC

incubator-tamaya git commit: TAMAYA-53 Fixed bugs found by FindBugs.

Repository: incubator-tamaya
Updated Branches:
  refs/heads/master ce4eeebb3 -> 103cb951b


TAMAYA-53 Fixed bugs found by FindBugs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/commit/103cb951
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/tree/103cb951
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tamaya/diff/103cb951

Branch: refs/heads/master
Commit: 103cb951b14326ad74fe74e4e16c11746db00c98
Parents: ce4eeeb
Author: Oliver B. Fischer <pl...@apache.org>
Authored: Fri Jan 16 21:51:15 2015 +0100
Committer: Oliver B. Fischer <pl...@apache.org>
Committed: Fri Jan 16 21:51:15 2015 +0100

----------------------------------------------------------------------
 .../propertysource/SystemPropertySource.java    | 17 +++++++++---
 .../tamaya/modules/json/JSONPropertySource.java | 28 +++++++++++++++++---
 .../apache/tamaya/modules/json/JSONVisitor.java |  2 +-
 3 files changed, 39 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/103cb951/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
----------------------------------------------------------------------
diff --git a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
index 50d788d..abfebeb 100644
--- a/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
+++ b/java8/core/src/main/java/org/apache/tamaya/core/propertysource/SystemPropertySource.java
@@ -22,6 +22,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
 
 /**
  * This {@link org.apache.tamaya.spi.PropertySource} manages the system properties.
@@ -29,6 +31,12 @@ import java.util.Properties;
 public class SystemPropertySource extends PropertiesPropertySource {
 
     /**
+     * Lock for internal synchronization.
+     */
+    private StampedLock propertySourceLock = new StampedLock();
+
+
+    /**
      * previous System.getProperties().hashCode()
      * so we can check if we need to reload
      */
@@ -50,10 +58,11 @@ public class SystemPropertySource extends PropertiesPropertySource {
     @Override
     public Map<String, String> getProperties() {
 
+        Lock writeLock = propertySourceLock.asWriteLock();
         // only need to reload and fill our map if something has changed
-        if (previousHash != System.getProperties().hashCode()) {
-
-            synchronized (this) {
+        try {
+            writeLock.lock();
+            if (previousHash != System.getProperties().hashCode()) {
 
                 if (previousHash != System.getProperties().hashCode()) {
 
@@ -68,6 +77,8 @@ public class SystemPropertySource extends PropertiesPropertySource {
                     previousHash = systemProperties.hashCode();
                 }
             }
+        } finally {
+            writeLock.unlock();
         }
 
         return super.getProperties();

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/103cb951/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
index 58cd248..0826bf7 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONPropertySource.java
@@ -31,6 +31,8 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.StampedLock;
 
 import static java.lang.String.format;
 
@@ -41,6 +43,12 @@ public class JSONPropertySource
     private InputResource source;
     private HashMap<String, String> values;
 
+    /**
+     * Lock for internal synchronization.
+     */
+    private StampedLock propertySourceLock = new StampedLock();
+
+
     public JSONPropertySource(File file) {
         this(file, 0);
     }
@@ -52,10 +60,16 @@ public class JSONPropertySource
 
     @Override
     public int getOrdinal() {
-        synchronized (this) {
+        Lock writeLock = propertySourceLock.asWriteLock();
+
+        try {
+            writeLock.lock();
+
             if (values == null) {
                 readSource();
             }
+        } finally {
+            writeLock.unlock();
         }
 
         return priority;
@@ -75,13 +89,19 @@ public class JSONPropertySource
 
     @Override
     public Map<String, String> getProperties() {
-        synchronized (this) {
+        Lock writeLock = propertySourceLock.asWriteLock();
+
+        try {
+            writeLock.lock();
+
             if (values == null) {
                 readSource();
             }
-        }
 
-        return Collections.unmodifiableMap(values);
+            return Collections.unmodifiableMap(values);
+        } finally {
+            writeLock.unlock();
+        }
     }
 
     protected void readSource() {

http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/103cb951/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
----------------------------------------------------------------------
diff --git a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
index 3868431..f52afbf 100644
--- a/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
+++ b/modules/json/src/main/java/org/apache/tamaya/modules/json/JSONVisitor.java
@@ -66,7 +66,7 @@ public class JSONVisitor {
         }
     }
 
-    private class VisitingContext {
+    private static class VisitingContext {
         private String namespace;
         private final ObjectNode node;
         private final Iterator<Map.Entry<String, JsonNode>> elements;