commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ohe...@apache.org
Subject svn commit: r1463687 - in /commons/proper/configuration/trunk/src: main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java
Date Tue, 02 Apr 2013 19:05:57 GMT
Author: oheger
Date: Tue Apr  2 19:05:56 2013
New Revision: 1463687

URL: http://svn.apache.org/r1463687
Log:
Fixed a potential NPE in DefaultReloadingDetectorFactory.

The refreshDelay property of the parameters object can now be null.

Modified:
    commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java
    commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java

Modified: commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java?rev=1463687&r1=1463686&r2=1463687&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java
(original)
+++ commons/proper/configuration/trunk/src/main/java/org/apache/commons/configuration/builder/DefaultReloadingDetectorFactory.java
Tue Apr  2 19:05:56 2013
@@ -40,7 +40,9 @@ public class DefaultReloadingDetectorFac
             FileBasedBuilderParametersImpl params)
             throws ConfigurationException
     {
-        return new FileHandlerReloadingDetector(handler,
-                params.getReloadingRefreshDelay());
+        Long refreshDelay = params.getReloadingRefreshDelay();
+        return (refreshDelay != null) ? new FileHandlerReloadingDetector(
+                handler, refreshDelay) : new FileHandlerReloadingDetector(
+                handler);
     }
 }

Modified: commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java?rev=1463687&r1=1463686&r2=1463687&view=diff
==============================================================================
--- commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java
(original)
+++ commons/proper/configuration/trunk/src/test/java/org/apache/commons/configuration/builder/TestDefaultReloadingDetectorFactory.java
Tue Apr  2 19:05:56 2013
@@ -18,6 +18,7 @@ package org.apache.commons.configuration
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
 
 import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.configuration.io.FileHandler;
@@ -50,13 +51,29 @@ public class TestDefaultReloadingDetecto
         FileHandler handler = new FileHandler();
         FileBasedBuilderParametersImpl params =
                 new FileBasedBuilderParametersImpl();
-        final long refreshDelay = 10000L;
+        final Long refreshDelay = 10000L;
         params.setReloadingRefreshDelay(refreshDelay);
         FileHandlerReloadingDetector detector =
                 (FileHandlerReloadingDetector) factory.createReloadingDetector(
                         handler, params);
         assertSame("Wrong file handler", handler, detector.getFileHandler());
-        assertEquals("Wrong refresh delay", refreshDelay,
+        assertEquals("Wrong refresh delay", refreshDelay.longValue(),
                 detector.getRefreshDelay());
     }
+
+    /**
+     * Tests whether an undefined refresh delay is handled correctly.
+     */
+    @Test
+    public void testCreateReloadingDetectorDefaultRefreshDelay()
+            throws ConfigurationException
+    {
+        FileHandler handler = new FileHandler();
+        FileBasedBuilderParametersImpl params =
+                new FileBasedBuilderParametersImpl();
+        FileHandlerReloadingDetector detector =
+                (FileHandlerReloadingDetector) factory.createReloadingDetector(
+                        handler, params);
+        assertTrue("No default refresh delay", detector.getRefreshDelay() != 0);
+    }
 }



Mime
View raw message