J.V · Java 25 practice question

An optimizing JVM speculatively executes expressions that appear after a statement which ends up throwing an exception at runtime. What does the Java Language Specification require regarding those speculatively executed expressions?

Choose one answer
Check answer and explanation

Correct answer: The optimized code must hide the speculative execution from the user-visible state of the program

Explanation

If optimized code speculatively executes expressions or statements following the point where an exception occurs, it must hide that speculative execution from the program's user-visible state.

Common trap

Speculative effects must never leak into user-visible state, whether or not the exception is caught locally. Speculative execution is permitted as long as its effects are hidden when an earlier exception occurs.

Source: JLS SE 25 §11.3. Run-Time Handling of an Exception
Checked against the cited text on 2026-11-25.

Report an error in this question