Resolving line items with null product id

I am having this issue where some of the line items have null product id. I am trying to create a custom app to overcome the bad request error by mapping it to default item. But the code is not overriding as expected . Any suggestions on how to resolve this issue?