Skip to content

Propagate compilation failures and bound debug test JVM termination/report waits #342

Open

Description

@Ajaymamtora

Source-confirmed Java test/debug lifecycle defects (related to Ajaymamtora/dotfiles#229)

I reviewed the current adapter source and identified two independent correctness hazards. These are confirmed control-flow observations, not claims of reproduced real JDTLS/Gradle runtime failures.

  1. Compilation failure is ignored before debug/test launch. core/spec_builder/init.lua invokes pcall(deps.compile, module.base_dir, compile_mode) and discards both the protected-call status and any explicit returned failure. The code proceeds to resolve the classpath and launch JUnit, potentially executing stale classes after failed compilation.
  2. DAP result collection can await a test JVM indefinitely. core/result_builder.lua calls spec.context.terminated_command_event.wait() without a visible timeout or cancellation path before reading JUnit XML. If the launch fails, the debugger disconnects early, or the process termination event is never emitted, the Neotest run may never finish.

Suggested focused fix

  • Define a clear compilation success/failure contract, including whether deps.compile throws, returns false, or yields a result table. Propagate errors with actionable project/module context and never start a stale test binary after failure.
  • Return an invocation-owned cancellable process handle for the Java test JVM. Bound the termination/report wait, distinguish expected normal debug completion from user cancellation and infrastructure errors, and terminate only this JVM.
  • Use unique per-invocation report directories; reject missing/stale JUnit XML as infrastructure failure rather than accidental success/skip.
  • Keep JDTLS workspace/Java Debug & Test bundle ownership with the existing adapter; do not add a second JVM debugger process manager.

Regression matrix

  • Compile throws / reports false / missing JDTLS test bundle; assert no debug process launches.
  • Java/JUnit 4 and 5 passing/failing tests with authoritative XML in both normal and debug modes.
  • DAP attach fails before the test JVM starts; result future settles and owned tasks close.
  • DAP disconnects while paused at a real Java breakpoint; test result is cancelled/infrastructure failure, not passed.
  • Parameterized/nested JUnit, Gradle/Maven multi-module, concurrently launched tests (no report directory collisions), Windows wrapper.
  • Verify no leftover test JVM, socket, listeners or temp report after termination.

A focused PR with fail-first fixture coverage would address this. The requester has read access but the connected GitHub integration does not have write access to this repository, so this issue is an upstream report, not a claim that the code was fixed or tested. The consuming dotfiles project will retain Java as unverified until its live acceptance passes.

Related: Ajaymamtora/dotfiles#229.

Activity

  1. Ajaymamtora commented on Nov 13, 2026

    @Ajaymamtora
    Author

    Additional source-level Java lifecycle blocker — launch can hang before Neotest even receives a RunSpec (13 Nov 2026)

    Independent follow-up to the compile-failure and terminated-event observations in this issue. I inspected the current lua/neotest-java/build_tool/launcher.lua, core/spec_builder/init.lua, core/result_builder.lua and lua/neotest-java/init.lua.

    Additional P0: launch_debug_test can wait indefinitely before returning. The default job runner starts vim.system(...) with an exit callback that only sets terminated_command_event; launch_debug_test then calls test_command_started_listening.wait() without a deadline. The listening event is set exclusively when stdout contains the string Listening. If Java exits before printing that string (compilation/classpath/JUnit crash, executable launch failure), exits successfully without that exact text, writes readiness to stderr, or never starts listening, build_spec stays suspended and never even reaches the Neotest DAP strategy. A DAP-side timeout is insufficient if build_spec is already blocked.

    Resource ownership: default_job_runner.new(...).start currently discards the vim.system() return value, so the launch callback exposes no process handle to terminate during cancellation, timeout or editor shutdown. ResultBuilder.build_results awaits terminated_command_event.wait() without a bound and then reads reports without verifying an invocation-owned process completion state. The report-folder generator in lua/neotest-java/init.lua uses a timestamp of seconds (strftime("%d%m%y%H%M%S")), which can collide for concurrent or rapid same-module runs.

    Required owner-level fix (please do this in neotest-java, not a dotfiles monkey-patch):

    1. Refactor the launcher to return an invocation-owned handle with independent, bounded readiness and exit results (including exit code, stderr tail and cancellation state), and a targeted idempotent stop(); retain a compatible public contract or provide an explicit migration. Do not throw away the vim.system handle.
    2. If startup exits early, always resolve the readiness awaiter with a failure and clean the process. A successful process spawn is not proof of JDWP readiness. Apply a deadline to startup, report collection and shutdown; keep the main Neovim loop responsive.
    3. Propagate pcall(deps.compile, ...) failures and explicit false returns before classpath resolution/launch, so stale compiled classes cannot be used accidentally.
    4. Generate a unique per-invocation report directory (for example, a collision-resistant temp ID under the module build tree). Reject absent/stale XML or an unreported selected test as infrastructure failure.
    5. Add fail-first fixtures for: startup throws; process exits nonzero before Listening; exits zero before Listening; no readiness text until timeout; readiness followed by a hanging process; cancel while awaiting attach; two concurrent runs; compile throws/returns false; missing/empty/stale reports. Assert exactly-once completion and no child JVM/port/file leaks.
    6. Then run real JDTLS/JUnit 4/5 source-breakpoint, nested/parameterised, Maven/Gradle multi-module and Windows wrapper QA. Mocked callbacks are contract evidence, not live breakpoint evidence.

    The connected account currently has read-only repository access to rcasia/neotest-java, so this is an implementation blocker report, not a claim of a merged Java fix. The dependent dotfiles master #229 must continue marking Java unverified until there is a writable upstream/fork PR and actual runtime evidence.

  2. Ajaymamtora commented on Nov 13, 2026

    @Ajaymamtora
    Author

    Verified fork resolution; upstream adoption still pending (13 Nov 2026)

    This supersedes the earlier unverified / implementation-blocked status above for the owned fork, not for upstream main.

    • Implemented at the owning adapter, not via dotfiles patches. Owned fork PR fix(lifecycle): integrate verified Java invocation ownership Ajaymamtora/neotest-java#1 is merged at e9e1054c337e09606637a2d427bcaed79af5e444, integrating the exact tested head 2d485463069a1b7401416ddcdbb02ce4ef8260e9.
    • Upstream adoption PR fix(lifecycle): own Java debug JVMs and reject missing results #343 remains open. The fork merge does not mean this upstream issue is closed or upstream main fixed; upstream maintainer review/merge is still required.
    • Compilation exceptions, explicit false, real JDTLS unsuccessful build status, and build deadlines now stop before launch. JVMs have invocation-owned process handles, bounded readiness/exit/report/shutdown, targeted cancellation and abandoned-start/editor-exit cleanup. Invocation report directories are unique; absent/stale/partial reports fail truthfully instead of implying success.

    Observed verification

    • Native suite: 225 cases, 33 groups, zero failures. Native Maven E2E: 2/2 files, snapshots matched (that harness uses LSP mocks; it is not the live JDTLS evidence).
    • StyLua, Luacheck (41 files, zero warnings/errors), LuaLS and diff-whitespace checks passed locally; no GitHub Actions were used.
    • Real Mason JDTLS + Java Debug/Test on Neovim 0.13, two-module Gradle 9.8.2 fixture: JUnit 4 and 5 passing/failing results match authoritative JUnit XML in both Run and Debug, including Jupiter nested tests and two parameterized invocations. Jupiter source breakpoint line 9 -> step 10; Vintage line 6 -> step 7.
    • Cancellation while paused and deliberate failed attach settled as failed infrastructure, reaped only the invocation-owned JVM and removed its reports. Concurrent ownership/report isolation and early-exit/readiness/report deadlines have regression coverage; neither mocked callbacks nor failed startup were presented as successful live debugging.

    Limits retained honestly

    Windows runtime and live Maven multi-module JDTLS were not exercised. A forced-full Buildship build on a reopened workspace reported a prerequisite-project build-order error; compilation was correctly rejected rather than silently executing stale classes. The normal/default incremental workflow passed both complete live gates. These limits are not blanket certification of the entire suggested platform matrix.

    The consuming project can now pin the verified merged fork; upstream #342 remains open pending upstream adoption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions