Porting #4944 to 2.5.x + correcting a Notice