directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1541430 - /directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java
Date Wed, 13 Nov 2013 08:59:21 GMT
Author: elecharny
Date: Wed Nov 13 08:59:21 2013
New Revision: 1541430

URL: http://svn.apache.org/r1541430
Log:
Fixed some potential NPE when browsing an empty BTree

Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java?rev=1541430&r1=1541429&r2=1541430&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java
(original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/managed/TupleCursorImpl.java
Wed Nov 13 08:59:21 2013
@@ -88,6 +88,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public Tuple<K, V> next() throws EndOfFileExceededException, IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            throw new NoSuchElementException( "No tuple present" );
+        }
+
         ParentPos<K, V> parentPos = stack[depth];
 
         if ( parentPos.page == null )
@@ -287,6 +293,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public Tuple<K, V> prev() throws EndOfFileExceededException, IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            throw new NoSuchElementException( "No more tuple present" );
+        }
+
         ParentPos<K, V> parentPos = stack[depth];
 
         if ( parentPos.page == null )
@@ -366,6 +378,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public boolean hasNext() throws EndOfFileExceededException, IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            return false;
+        }
+        
         // Take the leaf and check if we have no mare values
         ParentPos<K, V> parentPos = stack[depth];
 
@@ -421,6 +439,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public boolean hasPrev() throws EndOfFileExceededException, IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            return false;
+        }
+
         // Take the leaf and check if we have no mare values
         ParentPos<K, V> parentPos = stack[depth];
 
@@ -513,6 +537,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public void moveToNextNonDuplicateKey() throws EndOfFileExceededException, IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            return;
+        }
+
         ParentPos<K, V> parentPos = stack[depth];
 
         if ( parentPos.page == null )
@@ -566,6 +596,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public void moveToPrevNonDuplicateKey() throws EndOfFileExceededException, IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            return;
+        }
+
         ParentPos<K, V> parentPos = stack[depth];
 
         if ( parentPos.page == null )
@@ -606,6 +642,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public void beforeFirst() throws IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            return;
+        }
+
         Page<K, V> child = null;
         
         for ( int i = 0; i < depth; i++ )
@@ -646,6 +688,12 @@ public class TupleCursorImpl<K, V> imple
      */
     public void afterLast() throws IOException
     {
+        // First check that we have elements in the BTree
+        if ( ( stack == null ) || ( stack.length == 0 ) )
+        {
+            return;
+        }
+
         Page<K, V> child = null;
 
         for ( int i = 0; i < depth; i++ )



Mime
View raw message