Suppose company A thought they developed something new and attempted to patent it. But in actuality company B already patented the same thing a few months ago. However when company A was filing the patent, the patent examiner overlooked company B's patent because there is simply too much existing patents to go over to check for infringement, and he granted company A's patent.
After a couple of years, company A starts to make and sell a product based on the patent, and company B saw it and rightfully decides to sue company A. It seems to me company A is very unlucky in the sense that they have to pay all the consequences even though the fault is on the patent examiner. What is typically done in this type of situation?