lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r803903 - in /lucene/java/trunk: CHANGES.txt src/java/org/apache/lucene/util/CloseableThreadLocal.java src/test/org/apache/lucene/index/TestCloseableThreadLocal.java src/test/org/apache/lucene/util/TestCloseableThreadLocal.java
Date Thu, 13 Aug 2009 14:32:36 GMT
Author: mikemccand
Date: Thu Aug 13 14:32:36 2009
New Revision: 803903

URL: http://svn.apache.org/viewvc?rev=803903&view=rev
Log:
LUCENE-1805: allow CloseableThreadLocal.set(null)

Added:
    lucene/java/trunk/src/test/org/apache/lucene/util/TestCloseableThreadLocal.java
      - copied, changed from r803896, lucene/java/trunk/src/test/org/apache/lucene/index/TestCloseableThreadLocal.java
Removed:
    lucene/java/trunk/src/test/org/apache/lucene/index/TestCloseableThreadLocal.java
Modified:
    lucene/java/trunk/CHANGES.txt
    lucene/java/trunk/src/java/org/apache/lucene/util/CloseableThreadLocal.java

Modified: lucene/java/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/trunk/CHANGES.txt?rev=803903&r1=803902&r2=803903&view=diff
==============================================================================
--- lucene/java/trunk/CHANGES.txt (original)
+++ lucene/java/trunk/CHANGES.txt Thu Aug 13 14:32:36 2009
@@ -470,6 +470,10 @@
     of the instances are correct.  
     (Mike McCandless, Mark Miller, Michael Busch)
 
+22. LUCENE-1805: CloseableThreadLocal did not allow a null Object in get(), 
+    although it does allow it in set(Object). Fix get() to not assert the object
+    is not null. (Shai Erera via Mike McCandless)
+
 New features
 
  1. LUCENE-1411: Added expert API to open an IndexWriter on a prior

Modified: lucene/java/trunk/src/java/org/apache/lucene/util/CloseableThreadLocal.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/util/CloseableThreadLocal.java?rev=803903&r1=803902&r2=803903&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/util/CloseableThreadLocal.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/util/CloseableThreadLocal.java Thu Aug 13
14:32:36 2009
@@ -62,11 +62,7 @@
       } else
         return null;
     } else {
-      Object v = weakRef.get();
-      // This can never be null, because we hold a hard
-      // reference to the underlying object:
-      assert v != null;
-      return v;
+      return weakRef.get();
     }
   }
 

Copied: lucene/java/trunk/src/test/org/apache/lucene/util/TestCloseableThreadLocal.java (from
r803896, lucene/java/trunk/src/test/org/apache/lucene/index/TestCloseableThreadLocal.java)
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/util/TestCloseableThreadLocal.java?p2=lucene/java/trunk/src/test/org/apache/lucene/util/TestCloseableThreadLocal.java&p1=lucene/java/trunk/src/test/org/apache/lucene/index/TestCloseableThreadLocal.java&r1=803896&r2=803903&rev=803903&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/index/TestCloseableThreadLocal.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/util/TestCloseableThreadLocal.java Thu Aug
13 14:32:36 2009
@@ -1,7 +1,21 @@
-package org.apache.lucene.index;
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.
+ */
 
-import org.apache.lucene.util.CloseableThreadLocal;
-import org.apache.lucene.util.LuceneTestCase;
+package org.apache.lucene.util;
 
 public class TestCloseableThreadLocal extends LuceneTestCase {
   public static final String TEST_VALUE = "initvaluetest";
@@ -11,7 +25,23 @@
     String str = (String)tl.get();
     assertEquals(TEST_VALUE, str);
   }
-  
+
+  public void testNullValue() throws Exception {
+    // Tests that null can be set as a valid value (LUCENE-1805). This
+    // previously failed in get().
+    CloseableThreadLocal ctl = new CloseableThreadLocal();
+    ctl.set(null);
+    assertNull(ctl.get());
+  }
+
+  public void testDefaultValueWithoutSetting() throws Exception {
+    // LUCENE-1805: make sure default get returns null,
+    // twice in a row
+    CloseableThreadLocal ctl = new CloseableThreadLocal();
+    assertNull(ctl.get());
+    assertNull(ctl.get());
+  }
+
   public class InitValueThreadLocal extends CloseableThreadLocal {
     protected Object initialValue() {
       return TEST_VALUE;



Mime
View raw message