A small service prepares a text Handle for a one-request report and must close the temporary resource correctly on any error. After a recent change, two observable symptoms appeared: the same request sometimes creates multiple different Handles, and the temporary file remains on disk if reading ends with an exception.
prepare(String requestId) method must return the same result for the same requestId within one JVM if preparation has already been performed.prepare("r-17") twice in a row.prepare("boom"), where reading simulates a failure after the file is created.r-17 returns the same Handle, and that for boom the exception does not leave a temporary file behind.prepare("r-17") should return the same object or an equivalent result for the same requestId.javac and java without additional frameworksUse line comments to explain the problem, its impact, the fix and how to test it.