vgritsenko 2003/07/30 19:51:32
Modified: store/src/java/org/apache/excalibur/store/impl
AbstractJispFilesystemStore.java
Log:
Fix eternal loop in the iterator. To reproduce:
* get cocoon running
* go to http://localhost:8888/samples/linkstatus
* go to http://localhost:8888/samples/status.html
* enjoy eternal loop
Revision Changes Path
1.15 +40 -34
avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java
Index: AbstractJispFilesystemStore.java
===================================================================
RCS file:
/home/cvs/avalon-excalibur/store/src/java/org/apache/excalibur/store/impl/AbstractJispFilesystemStore.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- AbstractJispFilesystemStore.java 29 Jul 2003 03:58:34 -0000 1.14
+++ AbstractJispFilesystemStore.java 31 Jul 2003 02:51:32 -0000 1.15
@@ -54,6 +54,7 @@
import java.io.Serializable;
import java.util.Collections;
import java.util.Enumeration;
+import java.util.NoSuchElementException;
import com.coyotegulch.jisp.BTreeIndex;
import com.coyotegulch.jisp.BTreeIterator;
@@ -319,9 +320,8 @@
{
try
{
- BTreeObjectEnumeration enum = new BTreeObjectEnumeration(new
BTreeIterator(m_Index), this);
- return enum;
- }
+ return new BTreeObjectEnumeration(new BTreeIterator(m_Index), this);
+ }
catch (Exception ignore)
{
return Collections.enumeration(Collections.EMPTY_LIST);
@@ -354,6 +354,7 @@
class BTreeObjectEnumeration implements Enumeration
{
+ private Object m_Next;
private BTreeIterator m_Iterator;
private AbstractJispFilesystemStore m_Store;
@@ -361,54 +362,59 @@
{
m_Iterator = iterator;
m_Store = store;
+
+ // Obtain first element. If any.
+ try
+ {
+ m_Next = m_Iterator.getKey();
+ }
+ catch (IOException ioe)
+ {
+ m_Store.getLogger().error("store(..): Exception", ioe);
+ m_Next = null;
+ }
}
public boolean hasMoreElements()
{
- boolean hasMore = false;
- Object tmp = null;
+ return (m_Next != null);
+ }
- try
+ public Object nextElement() throws NoSuchElementException
+ {
+ if (m_Next == null)
{
- tmp = m_Iterator.getKey();
+ throw new NoSuchElementException();
+ }
+
+ // Save current element
+ Object tmp = m_Next;
- if(m_Iterator.moveNext())
+ // Advance to the next element
+ try
+ {
+ if (m_Iterator.moveNext())
{
- hasMore = true;
+ m_Next = m_Iterator.getKey();
}
-
- /* resets iterator to the old state **/
- m_Iterator.moveTo((KeyObject)tmp);
- }
+ else
+ {
+ // Can't move to the next element - no more elements.
+ m_Next = null;
+ }
+ }
catch (IOException ioe)
{
m_Store.getLogger().error("store(..): Exception", ioe);
+ m_Next = null;
}
catch (ClassNotFoundException cnfe)
{
m_Store.getLogger().error("store(..): Exception", cnfe);
+ m_Next = null;
}
- return hasMore;
- }
-
- public Object nextElement()
- {
- Object tmp = null;
- try
- {
- tmp = m_Iterator.getKey();
- m_Iterator.moveNext();
- }
- catch (IOException ioe)
- {
- m_Store.getLogger().error("store(..): Exception", ioe);
- }
- catch (ClassNotFoundException cnfe)
- {
- m_Store.getLogger().error("store(..): Exception", cnfe);
- }
- // return the real key
+ // Return the real key
return ((JispKey) tmp).getKey();
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]