commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ozeigerm...@apache.org
Subject svn commit: r421670 - in /jakarta/commons/proper/transaction/trunk/src: java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java test/org/apache/commons/transaction/memory/MapWrapperTest.java
Date Thu, 13 Jul 2006 17:42:53 GMT
Author: ozeigermann
Date: Thu Jul 13 10:42:52 2006
New Revision: 421670

URL: http://svn.apache.org/viewvc?rev=421670&view=rev
Log:
Fix for bug 38545. Transactional map wrapper did not allow for 
null values. Bug reported and patch 
supplied by Greg Steckman at 
http://issues.apache.org/bugzilla/show_bug.cgi?id=38545.

Modified:
    jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java
    jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java

Modified: jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java?rev=421670&r1=421669&r2=421670&view=diff
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java
(original)
+++ jakarta/commons/proper/transaction/trunk/src/java/org/apache/commons/transaction/memory/TransactionalMapWrapper.java
Thu Jul 13 10:42:52 2006
@@ -317,7 +317,7 @@
      * @see Map#containsKey(java.lang.Object) 
      */
     public boolean containsKey(Object key) {
-        return (get(key) != null);
+	return keySet().contains(key);
     }
 
     /**
@@ -529,6 +529,7 @@
             Set keySet = new HashSet();
             if (!cleared) {
                 keySet.addAll(wrapped.keySet());
+                keySet.removeAll(deletes);
             }
             keySet.addAll(adds.keySet());
             return keySet;
@@ -541,14 +542,12 @@
                 return null;
             }
 
-            Object changed = changes.get(key);
-            if (changed != null) {
-                return changed;
+            if(changes.containsKey(key)){
+                return changes.get(key);
             }
 
-            Object added = adds.get(key);
-            if (added != null) {
-                return added;
+            if(adds.containsKey(key)){
+                return adds.get(key);
             }
 
             if (cleared) {
@@ -563,7 +562,7 @@
             try {
                 readOnly = false;
                 deletes.remove(key);
-                if (wrapped.get(key) != null) {
+                if (wrapped.containsKey(key)) {
                     changes.put(key, value);
                 } else {
                     adds.put(key, value);

Modified: jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java?rev=421670&r1=421669&r2=421670&view=diff
==============================================================================
--- jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java
(original)
+++ jakarta/commons/proper/transaction/trunk/src/test/org/apache/commons/transaction/memory/MapWrapperTest.java
Thu Jul 13 10:42:52 2006
@@ -121,6 +121,37 @@
         report("value2", (String) txMap1.get("key1"));
     }
 
+    public void testContainsKeyWithNullValue() throws Throwable {
+
+        logger.info("Checking containsKey returns true when the value is null");
+
+        final Map map1 = new HashMap();
+
+        final TransactionalMapWrapper txMap1 = getNewWrapper(map1);
+
+        assertTrue(txMap1.isEmpty());
+
+        // make sure changes are propagated to wrapped map outside tx
+        txMap1.put("key1", null);
+        assertTrue(txMap1.containsKey("key1"));
+
+        // make sure changes are progated to wrapped map after commit
+        txMap1.startTransaction();
+        txMap1.put("key2", null);
+        assertTrue(txMap1.containsKey("key2"));
+        txMap1.remove("key1");
+        assertTrue(map1.containsKey("key1"));
+        txMap1.commitTransaction();
+        assertTrue(txMap1.containsKey("key2"));
+        assertFalse(txMap1.containsKey("key1"));
+
+        txMap1.startTransaction();
+        assertTrue(txMap1.containsKey("key2"));
+        txMap1.remove("key2");
+        assertFalse(txMap1.containsKey("key2"));
+        txMap1.commitTransaction();
+    }
+
     public void testComplex() throws Throwable {
 
         logger.info("Checking advanced and complex transaction features");



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


Mime
View raw message