diff --git a/layout/html/table/src/nsTableFrame.cpp b/layout/html/table/src/nsTableFrame.cpp
index 39944c5e5782..530054379803 100644
--- a/layout/html/table/src/nsTableFrame.cpp
+++ b/layout/html/table/src/nsTableFrame.cpp
@@ -7006,7 +7006,7 @@ nsTableFrame::PaintBCBorders(nsPresContext* aPresContext,
break;
case eAjaRowOwner:
side = NS_SIDE_BOTTOM;
- row = iter.prevRow; // and fall through
+ row = (iter.IsBottomMostTable()) ? iter.row : iter.prevRow; // and fall through
case eRowOwner:
if (row) {
::GetStyleInfo(*row, side, style, color, iter.IsBottomMostTable());
diff --git a/layout/tables/nsTableFrame.cpp b/layout/tables/nsTableFrame.cpp
index 39944c5e5782..530054379803 100644
--- a/layout/tables/nsTableFrame.cpp
+++ b/layout/tables/nsTableFrame.cpp
@@ -7006,7 +7006,7 @@ nsTableFrame::PaintBCBorders(nsPresContext* aPresContext,
break;
case eAjaRowOwner:
side = NS_SIDE_BOTTOM;
- row = iter.prevRow; // and fall through
+ row = (iter.IsBottomMostTable()) ? iter.row : iter.prevRow; // and fall through
case eRowOwner:
if (row) {
::GetStyleInfo(*row, side, style, color, iter.IsBottomMostTable());