Finish reading if there are no more pages.

git-svn-id: https://hyracks.googlecode.com/svn/branches/fullstack_rsd_fixes@3335 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java
index 74a4c55..a584b4b 100644
--- a/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java
+++ b/hyracks/hyracks-control/hyracks-control-nc/src/main/java/edu/uci/ics/hyracks/control/nc/dataset/DatasetPartitionReader.java
@@ -3,9 +3,9 @@
  * Licensed 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 from
- * 
+ *
  *     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.
@@ -66,12 +66,12 @@
 
         if (readSize < buffer.capacity()) {
             long localPageOffset = offset - resultState.getPersistentSize();
-            if (localPageOffset <= 0) {
-            	return readSize;
-            }
             int localPageIndex = (int) (localPageOffset / datasetMemoryManager.getPageSize());
             int pageOffset = (int) (localPageOffset % datasetMemoryManager.getPageSize());
             Page page = resultState.getPage(localPageIndex);
+            if (page == null) {
+            	return readSize;
+            }
             readSize += buffer.remaining();
             buffer.put(page.getBuffer().array(), pageOffset, buffer.remaining());
         }