You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by da...@apache.org on 2008/01/22 01:18:17 UTC

svn commit: r614068 - /db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/CachedPage.java

Author: dag
Date: Mon Jan 21 16:18:16 2008
New Revision: 614068

URL: http://svn.apache.org/viewvc?rev=614068&view=rev
Log:
DERBY-3215 Potential NullPointerException in CachedPage class

Merged fix (two patches) from trunk as

svn merge -r 596852:596853 https://svn.apache.org/repos/asf/db/derby/code/trunk
svn merge -r 597122:597123 https://svn.apache.org/repos/asf/db/derby/code/trunk

The offending code is in an unused argument to newException, remove
two instances of that and restructures the code for better readability
by testing for the exceptional condition first. Also removes some
unused imports.


Modified:
    db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/CachedPage.java

Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/CachedPage.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/CachedPage.java?rev=614068&r1=614067&r2=614068&view=diff
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/CachedPage.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/store/raw/data/CachedPage.java Mon Jan 21 16:18:16 2008
@@ -23,22 +23,17 @@
 
 import org.apache.derby.iapi.reference.SQLState;
 
-import org.apache.derby.impl.store.raw.data.BasePage;
-
 import org.apache.derby.iapi.store.raw.log.LogInstant;
-import org.apache.derby.iapi.store.raw.ContainerHandle;
 import org.apache.derby.iapi.store.raw.PageKey;
 
 import org.apache.derby.iapi.services.cache.Cacheable;
 import org.apache.derby.iapi.services.cache.CacheManager;
-import org.apache.derby.iapi.services.context.ContextService;
 
 import org.apache.derby.iapi.services.monitor.Monitor;
 
 import org.apache.derby.iapi.services.sanity.SanityManager;
 
 import org.apache.derby.iapi.services.io.FormatIdUtil;
-import org.apache.derby.iapi.services.io.StoredFormatIds;
 
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.error.ExceptionSeverity;
@@ -768,72 +763,70 @@
 		FileContainer myContainer = 
             (FileContainer) containerCache.find(identity.getContainerId());
 
-		if (myContainer != null) 
-        {
-			try 
-            {
-				myContainer.writePage(
-                    identity.getPageNumber(), pageData, syncMe);
+		if (myContainer == null)
+		{
+			StandardException nested =
+				StandardException.newException(
+					SQLState.DATA_CONTAINER_VANISHED,
+					identity.getContainerId());
+			throw dataFactory.markCorrupt(
+				StandardException.newException(
+					SQLState.FILE_WRITE_PAGE_EXCEPTION, nested,
+					identity));
+		}
+
+		try
+		{
+			myContainer.writePage(
+				identity.getPageNumber(), pageData, syncMe);
+
+			//
+			// Do some in memory unlogged bookkeeping tasks while we have
+			// the container.
+			//
+
+			if (!isOverflowPage() && isDirty())
+			{
+
+				// let the container knows whether this page is a not
+				// filled, non-overflow page
+				myContainer.trackUnfilledPage(
+					identity.getPageNumber(), unfilled());
 
+				// if this is not an overflow page, see if the page's row
+				// count has changed since it come into the cache.
 				//
-				// Do some in memory unlogged bookkeeping tasks while we have
-				// the container. 
+				// if the page is not invalid, row count is 0.	Otherwise,
+				// count non-deleted records on page.
 				//
+				// Cannot call nonDeletedRecordCount because the page is
+				// unlatched now even though nobody is changing it
+				int currentRowCount = internalNonDeletedRecordCount();
 
-				if (!isOverflowPage() && isDirty())
+				if (currentRowCount != initialRowCount)
 				{
+					myContainer.updateEstimatedRowCount(
+						currentRowCount - initialRowCount);
 
-					// let the container knows whether this page is a not 
-                    // filled, non-overflow page
-					myContainer.trackUnfilledPage(
-                        identity.getPageNumber(), unfilled());
-
-					// if this is not an overflow page, see if the page's row
-					// count has changed since it come into the cache.
-					//
-					// if the page is not invalid, row count is 0.  Otherwise,
-					// count non-deleted records on page.
-					//
-					// Cannot call nonDeletedRecordCount because the page is
-					// unlatched now even though nobody is changing it
-					int currentRowCount = internalNonDeletedRecordCount();
-
-					if (currentRowCount != initialRowCount)
-					{
-						myContainer.updateEstimatedRowCount(
-                            currentRowCount - initialRowCount);
-
-						setContainerRowCount(
-                            myContainer.getEstimatedRowCount(0));
+					setContainerRowCount(
+						myContainer.getEstimatedRowCount(0));
 
-						initialRowCount = currentRowCount;
-					}
+					initialRowCount = currentRowCount;
 				}
-
-			} 
-            catch (IOException ioe) 
-            {
-				// page cannot be written
-				throw StandardException.newException(
-                    SQLState.FILE_WRITE_PAGE_EXCEPTION, 
-                    ioe, identity, new Integer(myContainer.getPageSize()));
-			}
-			finally
-			{
-				containerCache.release(myContainer);
-				myContainer = null;
 			}
-		} 
-		else
+
+		}
+		catch (IOException ioe)
 		{
-			StandardException nested = 
-                StandardException.newException(
-                    SQLState.DATA_CONTAINER_VANISHED, 
-                    identity.getContainerId());
-			throw dataFactory.markCorrupt(
-                StandardException.newException(
-                    SQLState.FILE_WRITE_PAGE_EXCEPTION, nested, 
-                    identity, new Integer(myContainer.getPageSize())));
+			// page cannot be written
+			throw StandardException.newException(
+				SQLState.FILE_WRITE_PAGE_EXCEPTION,
+				ioe, identity);
+		}
+		finally
+		{
+			containerCache.release(myContainer);
+			myContainer = null;
 		}
 
 		synchronized (this)