79615233

Date: 2025-05-10 07:03:41
Score: 0.5
Natty:
Report link

As @Slaw already suspected in the question comments while I composed this answer, its fundamentally a sequencing problem, hidden by a bit of compiler syntactic sugar.

JLS 14.20.3.2 states that this:

   /* task creation if option 1 */
   try (/* option 1 or 2 resource statement here */) {
        var taskFuture = taskExecutor.submit(() -> {
            task.run();
            return true;
        });
        var result = taskFuture.get(30_000, TimeUnit.MILLISECONDS);
        System.out.println("Got result: " + result);
    } catch (Exception e) {
        System.out.println("Caught exception: " + e);
        throw new RuntimeException(e);
    } /* finally if option 1 */

is fundamentally treated as this:

   /* task creation if option 1 */
   try{
        try (/* option 1 or 2 resource statement here */){
            var taskFuture = taskExecutor.submit(() -> {
                task.run();
                return true;
            });
            var result = taskFuture.get(30_000, TimeUnit.MILLISECONDS);
            System.out.println("Got result: " + result);
        }
    } catch (Exception e) {
        System.out.println("Caught exception: " + e);
        throw new RuntimeException(e);
    }  /* finally if option 1 */

Which already hints at the problem.

* my JVM's implementation (in `java.util.concurrent.ExecutorService`) waits for 1 day for tasks to bail before giving up, however, that time isn't specced.
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Slaw
  • Low reputation (1):
Posted by: Jannik S.