There can be a few reasons to prevent the above code to ever be reached.
Are you sure that you are running against a version of the Core/Platform that is legit for your resource? Is the same URI possibly already used somewhere else with the same order? … etc.
If you can’t spot any obvious reason I would suggest to debug RestServiceImpl to understand why your resource is not retained into those maps in the end.
As a last resort you could setup a unit test provoking the exception, and push the code on a temp branch for others to replay it. Here is an example of such unit test.