If it is dodgy components behind the 787 problems then surely Boeing should have checked and double checked them before installing said components into the Dreamliner in the first place, it is now going to cost Boeing money to replace the components.
How do you tell? If the deviation from requirement is in heat treatment, say, or something else not visible to the naked eye, then it's very difficult to pick up short of doing a full tear-down in a lab. And you simply can't do destructive testing on every part. There has to be some acceptance testing, but there are going to be issues that can get past that. You have ultimately to trust that your subcontractor is holding to the agreed specification, and that their QA are monitoring that. Your QA can do periodic audits to confirm that everything is proceeding along agreed lines, but you can't do that constantly.
And breaches can happen without anyone knowing. If the sub-contractor genuinely believes their parts are in spec, and it's not an obvious deviation, then it's very difficult to catch that.
There are also the rare cases where the sub-contractor is fully aware they are out of spec and are deliberately concealing it - such as with that Japanese passenger seat supplier a few years back.