commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1090139 - /commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/tools/Service.java
Date Fri, 08 Apr 2011 06:52:55 GMT
Author: simonetripodi
Date: Fri Apr  8 06:52:55 2011
New Revision: 1090139

URL: http://svn.apache.org/viewvc?rev=1090139&view=rev
Log:
DISCOVERY-3: Enumeration in Service broken
fix suggested by Matthew Pocock (no patch available, just reported the working fix)

Modified:
    commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/tools/Service.java

Modified: commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/tools/Service.java
URL: http://svn.apache.org/viewvc/commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/tools/Service.java?rev=1090139&r1=1090138&r2=1090139&view=diff
==============================================================================
--- commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/tools/Service.java
(original)
+++ commons/proper/discovery/trunk/src/java/org/apache/commons/discovery/tools/Service.java
Fri Apr  8 06:52:55 2011
@@ -17,6 +17,7 @@
 package org.apache.commons.discovery.tools;
 
 import java.util.Enumeration;
+import java.util.NoSuchElementException;
 
 import org.apache.commons.discovery.ResourceClass;
 import org.apache.commons.discovery.ResourceClassIterator;
@@ -90,18 +91,19 @@ public class Service {
             (new DiscoverClasses<T>(loaders)).findResourceClasses(servicesIter);
 
         return new Enumeration<S>() {
-            private S object = null;
+            private S object = getNextClassInstance();
 
             public boolean hasMoreElements() {
-                if (object == null) {
-                    object = getNextClassInstance();
-                }
                 return object != null;
             }
 
             public S nextElement() {
+                if (object == null) {
+                    throw new NoSuchElementException();
+                }
+
                 S obj = object;
-                object = null;
+                object = getNextClassInstance();
                 return obj;
             }
 



Mime
View raw message