Uncaught ErrorException: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated in even though I am checkng for nulll

I am getting following error on line 42 of my code. But strange thing is I am already checking for null and the actual error seems to be happening on line 44. How to fix this issue?

Error

Uncaught ErrorException: htmlspecialchars(): Passing null to parameter
#1 ($string) of type string is deprecated in /var/www/mysite/mypage.php:42

Code

while($row3 = mysqli_fetch_assoc($result3))
{
   $emailbody .= "<b>Keyword:</b> ". htmlspecialchars($row2["keyword"]) ."<br>";

   if(!is_null($row3["summary"]))     //line 42
   {
      $emailbody .= "<b>Summary:</b> ". htmlspecialchars($row3["summary"]) ."<br>";
   }
}