Skip to content

fix(devloop): open the packages HotswapAgent needs in the app JVM - #27452

Merged
Artur- merged 10 commits into
mainfrom
fix/devloop-open-jdk-internal-loader
Nov 30, 2026
Merged

Artur- merged 10 commits into
mainfrom
fix/devloop-open-jdk-internal-loader

Conversation

@totally-not-ai

@totally-not-ai totally-not-ai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #27451

behavior deviation · flow-devloop-daemon · dev loop on a JetBrains Runtime (JBR)

Background — HotswapAgent ProxyPlugin. On a JBR, the dev loop redefines changed classes in place, including structural changes to interfaces. A JDK dynamic proxy class of such an interface is generated once, so HotswapAgent's ProxyPlugin has to regenerate it after the redefine; it does that through the JDK's proxy class cache in jdk.internal.loader.

When a method is added to or changed on an interface that has a loaded JDK proxy, for example one returned by Element.executeJs(Class), a plain apply restarts the app, because the loop sees a structural change to a proxied type; this PR does not change that. With apply --no-restart, though, the redefine stays in the JVM and the stale proxy throws AbstractMethodError on the next call. A later plain apply no longer sees a structural change, so it reports a hot reload and the error stays until a manual restart. The app JVM now opens the package the proxy regeneration needs, so HotswapAgent rebuilds the proxy and the new method works after apply --no-restart (the issue's steps, verified there with the same open passed through --jvm-args). It also opens every other package the IntelliJ and VS Code plugins open for a HotswapAgent launch, so code that hot reloads from the IDE also hot reloads under the dev loop. Turning the plain apply into a hot reload for such proxies would mean relaxing the loop's proxied-type check, which is left for a follow-up. Workaround until then: --jvm-args "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED".

Risks:

  • ⚠️ Behaviour change: the new opens go to every app JVM the loop launches, forked servers included. The open once found to break a WildFly boot is java.base/java.net (it lets HotswapAgent swap URLClassLoader.ucp); that one stays off forked servers. The IDE-parity opens have not been tried on WildFly or other forked servers.
  • ✅ No public API, security, memory, serialization, threading or performance impact.

Context. The embedded Maven goal runtime already opened jdk.internal.loader for its own reason (that duplicate is now dropped), so the problem only showed with the main-class launch and forked servers. Chosen over leaving it to the developer's --jvm-args, because the failure is silent apart from the app log, and the loop's own flags already carry HotswapAgent's other opens. The IntelliJ and VS Code plugins already open this package when they launch with HotswapAgent.

  • Added java.base/jdk.internal.loader to the --add-opens flags the dev loop gives the application JVM.
  • Added the other opens the IDE plugins pass and the dev loop lacked: java.base/sun.nio.ch, java.base/sun.security.action, java.desktop/com.sun.beans, java.desktop/com.sun.beans.introspect and java.desktop/com.sun.beans.util. No dev-loop failure is traced to these; they are there so both ways of running an app behave the same.
  • Removed the now-duplicate jdk.internal.loader open from the embedded Maven goal runtime's extra flags. It keeps only java.net, which forked servers still don't get, and its comments now say why one open is safe on a forked server and the other is not.
  • Added tests that every launch has each open the IDE plugins pass and that the embedded runtime adds only the java.net one, which the flags every launch gets (forked servers included) never carry.

HotswapAgent's ProxyPlugin needs it to regenerate the JDK proxy class
of a redefined interface. Without it, calling a method added to such an
interface, e.g. through an executeJs(Class) proxy, throws
AbstractMethodError until a restart.

Fixes #27451
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Type of change

  • Bugfix

private static final List<String> ADD_OPENS = List.of("java.base/java.lang",
"java.base/java.lang.reflect", "java.base/java.io",
"java.base/java.util", "java.desktop/java.beans");
"java.base/java.util", "java.base/jdk.internal.loader",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the opens here in sync with the vscode / intellij plugins?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Artur- For this package, yes: both the IntelliJ plugin and the VS Code plugin already open java.base/jdk.internal.loader, so this PR brings the dev loop in line with them.

The lists are still not the same:

  • Only the plugins open: java.base/sun.nio.ch, java.base/sun.security.action, java.desktop/com.sun.beans, java.desktop/com.sun.beans.introspect and java.desktop/com.sun.beans.util.
  • Only the dev loop opens: java.base/java.util, plus java.base/java.net for the embedded Maven runtime.

I kept this PR to the open the issue needs, because there's no known failure for the others yet. Aligning the full list fits better in its own PR. Should I open one?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the ones from the plugins in this pr

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Artur- Added them. The app JVM now also gets java.base/sun.nio.ch, java.base/sun.security.action, java.desktop/com.sun.beans, java.desktop/com.sun.beans.introspect and java.desktop/com.sun.beans.util, so it has every open the IntelliJ and VS Code plugins pass. The Javadoc says these are there for parity with the plugins, and a parameterized test checks each one. The dev loop keeps java.base/java.util, which the plugins don't open. These opens also reach forked servers. They haven't been tried on WildFly; the open that broke WildFly before was java.net, and forked servers still don't get it.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — collected 1 finding below that could not be attached to the diff.

Finding
📝 The comment in extraJvmFlags now contradicts the code: one of its opens does reach forked servers.

📝 The comment in extraJvmFlags now contradicts the code: one of its opens does reach forked servers.
extraJvmFlags still states that "None of it goes to a forked server, and the opens least of all", and the inline comment calls the opens "actively harmful there". With jdk.internal.loader in the base list, half of that pair now goes to every forked server, WildFly included.

The reason that is still safe — the ucp swap also needs java.base/java.net, which stays off — lives only in the PR description. It belongs here, since this comment is where the next person checks the invariant.

The embedded case also passes the same open twice now (base list plus extraJvmFlags). Harmless to the JVM, but it suggests extraJvmFlags should keep only java.net.
MavenGoalRuntime.java:783 · documentation

Every launch now opens jdk.internal.loader, so passing it again for the
embedded runtime only duplicated it. Explain why forked servers can
take that open but not the java.net one.
@totally-not-ai

Copy link
Copy Markdown
Contributor Author

Addressed the extraJvmFlags finding: the embedded runtime now adds only the java.net open, since every launch already has jdk.internal.loader. Its comments now explain that jdk.internal.loader alone can't swap URLClassLoader.ucp, so forked servers can take it but still not java.net. A new test pins the embedded runtime's extra flags.

@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

 1 710 files  ± 0   1 800 suites  ±0   2h 7m 13s ⏱️ + 1m 48s
13 940 tests +12  13 868 ✅ +12  72 💤 ±0  0 ❌ ±0 
14 618 runs  +12  14 546 ✅ +12  72 💤 ±0  0 ❌ ±0 

Results for commit 98c260f. ± Comparison against base commit 30a4cb0.

♻️ This comment has been updated with latest results.

Add the opens the IntelliJ and VS Code plugins give a HotswapAgent
launch and the dev loop lacked: sun.nio.ch, sun.security.action and
the com.sun.beans packages.
Turn the jdk.internal.loader test into one over all the IDE plugins'
opens, and say in the Javadoc which opens are there only for parity.
@totally-not-ai totally-not-ai Bot changed the title fix(devloop): open jdk.internal.loader to HotswapAgent in the app JVM fix(devloop): open the packages HotswapAgent needs in the app JVM Nov 26, 2026
@Artur-
Artur- requested review from vaadin-review-bot and removed request for vaadin-review-bot November 30, 2026 10:16

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 1 comment.

Finding
⚠️ The stale-proxy AbstractMethodError this is said to fix is already escalated to a restart by the loop, so the open changes nothing for that case.


/**
* The packages opened to HotswapAgent and its plugins.
* {@code jdk.internal.loader} is for its ProxyPlugin, which clears the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ The stale-proxy AbstractMethodError this is said to fix is already escalated to a restart by the loop, so the open changes nothing for that case.

DevLoopRedefiner collects every loaded JDK proxy (Proxy.isProxyClass) and reports a redefined interface that one of them implements under proxied. TransactionEngine.blockedReason turns structural + proxied into "structural change to a proxied type: the live proxy was generated from the old shape", and the apply escalates to a restart. A method added to a @JsDefinition interface whose proxy is loaded therefore restarts; a proxy that is not loaded yet is generated fresh from the new interface. AbstractMethodError is also in AppLog.RELOAD_FAILURE, which escalates as well.

With the open, ProxyPlugin can regenerate the proxy, but that escalation still fires, so the outcome is the same restart as before. Turning this into a hot reload would additionally mean relaxing the proxied check for interfaces the plugin can regenerate.

The new tests only assert that the flag is passed, so nothing demonstrates the reported failure is gone. Worth reproducing the issue against the current apply before claiming it fixed — the remaining opens still stand on their own as IDE parity.

Launch.java:94 · correctness

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right for a plain apply: with the proxy loaded, structural + proxied escalates to a restart before and after this change. The issue's steps use apply --no-restart, though, and that path is where the failure sticks. The redefine stays in the JVM, the stale proxy throws AbstractMethodError, and a later plain apply sees no structural change any more (the class is already redefined), so it reports a hot reload over a broken proxy. With the open, ProxyPlugin rebuilds the proxy and the new method works after apply --no-restart. The issue confirms this end to end with the same open passed through --jvm-args. The unit tests here only pin the flag, since the end-to-end check needs a JBR.

I reworded the PR description to say exactly that: the plain apply still restarts, and making it hot reload would mean relaxing the proxied-type check for JDK proxies. That's a follow-up, not part of this PR. No code change.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 1 comment.

Finding
📝 The ADD_OPENS comment describes a failure the loop's own escalation prevents on a plain apply.

* The packages opened to HotswapAgent and its plugins.
* {@code jdk.internal.loader} is for its ProxyPlugin, which clears the
* JDK's proxy class cache after an interface is redefined: without it the
* plugin fails, the stale proxy class stays, and calling a method added to

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 The ADD_OPENS comment describes a failure the loop's own escalation prevents on a plain apply.

The comment says the stale proxy "stays" and the added method "throws AbstractMethodError until the application is restarted". For a plain apply that is not what happens: TransactionEngine.blockedReason turns structural + proxied into an escalation and the loop restarts by itself. The surviving failure needs apply --no-restart, which is exactly the qualifier the PR description gained after this was raised.

The same wording is repeated in the javadoc of the new test in LaunchTest. Both read as if the open fixes something the loop already handles, which is the misreading the earlier review ran into.

Launch.java:96 · documentation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed: the ADD_OPENS comment and the LaunchTest Javadoc now say that a plain apply restarts when a proxied interface changes shape. They also say the stale proxy and its AbstractMethodError only stay after apply --no-restart, until a manual restart, because a later apply no longer sees a structural change to escalate. This matches the PR description. Comment-only change.

A plain apply already restarts when a proxied interface changes shape;
the AbstractMethodError only sticks after apply --no-restart, so the
ADD_OPENS comment and the test Javadoc now say so.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 1 comment.

Finding
🧪 Nothing pins that the shared open list never carries java.net, the one open a forked server must not get.

List<String> flags = launchWithAgents(repo).jvmFlags(text -> {
});

int open = flags.indexOf(target + "=ALL-UNNAMED");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Nothing pins that the shared open list never carries java.net, the one open a forked server must not get.

Before this change both opens of the pair sat behind the plugin.embedded() branch in extraJvmFlags, so one condition kept them off a forked server. Now the pair is split and only java.net is still gated; the shared list is handed to every launch, forked ones included.

The new tests assert presence for the listed opens and the exact contents of extraJvmFlags on both sides, but none asserts an absence. Moving java.net into ADD_OPENS — the same move this PR makes for jdk.internal.loader — would leave every unit test green while giving every forked server the open the module documents as making a WildFly boot unrecoverable.

LaunchTest.java:348 · tests

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added jvmFlags_doNotOpenJavaNet: it asserts that the flags every launch gets, forked servers included, never open java.base/java.net. Adding java.net to ADD_OPENS now fails it, and the existing tests still pin that the embedded runtime adds that open in its own extra flags. The PR description mentions the new check.

jdk.internal.loader moved into the list every launch gets, so the
embedded-only gate no longer keeps both opens off forked servers. Pin
that java.net, the one that breaks a WildFly boot, stays out of it.

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Nothing to flag — the changes look good.

@sonarqubecloud

Copy link
Copy Markdown

@Artur-
Artur- added this pull request to the merge queue Nov 30, 2026
Merged via the queue into main with commit f998ff9 Nov 30, 2026
66 checks passed
@Artur-
Artur- deleted the fix/devloop-open-jdk-internal-loader branch November 30, 2026 13:07
@github-actions

Copy link
Copy Markdown
Contributor

Documentation Bot: No documentation needed for this change.

This is a BEHAVIOR_CHANGE/bug fix confined to flow-devloop-daemon: it corrects the --add-opens flags the dev-loop daemon passes to the application JVM (plus matching test coverage) so HotswapAgent's ProxyPlugin can regenerate a stale JDK dynamic proxy after apply --no-restart hot-swaps a changed interface, instead of the call throwing a silent AbstractMethodError. It's an internal flag-composition fix with no new command, option, or documented contract for a reader to reach for — the dev loop CLI docs already describe --no-restart and --jvm-args the same way before and after this change, and the only genuinely new fact (untested forked-server opens) would only support a caveat/admonition, which is the shape this bot avoids opening PRs for.

Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.

Generated by Documentation Bot for #27452 · agent · 60.2 AIC · ⊞ 11.7K · ◷

vaadin-bot added a commit that referenced this pull request Nov 30, 2026
…7452) (CP: 25.4) (#27544)

This PR cherry-picks changes from the original PR #27452 to branch 25.4.

---

> Fixes #27451
> 
> **behavior deviation** · flow-devloop-daemon · dev loop on a JetBrains
Runtime (JBR)
> 
> **Background — HotswapAgent ProxyPlugin.** On a JBR, the dev loop
redefines changed classes in place, including structural changes to
interfaces. A JDK dynamic proxy class of such an interface is generated
once, so HotswapAgent's ProxyPlugin has to regenerate it after the
redefine; it does that through the JDK's proxy class cache in
`jdk.internal.loader`.
> 
> When a method is added to or changed on an interface that has a loaded
JDK proxy, for example one returned by `Element.executeJs(Class)`, a
plain `apply` restarts the app, because the loop sees a structural
change to a proxied type; this PR does not change that. With `apply
--no-restart`, though, the redefine stays in the JVM and the stale proxy
throws `AbstractMethodError` on the next call. A later plain `apply` no
longer sees a structural change, so it reports a hot reload and the
error stays until a manual restart. The app JVM now opens the package
the proxy regeneration needs, so HotswapAgent rebuilds the proxy and the
new method works after `apply --no-restart` (the issue's steps, verified
there with the same open passed through `--jvm-args`). It also opens
every other package the IntelliJ and VS Code plugins open for a
HotswapAgent launch, so code that hot reloads from the IDE also hot
reloads under the dev loop. Turning the plain `apply` into a hot reload
for such proxies would mean relaxing the loop's proxied-type check,
which is left for a follow-up. Workaround until then: `--jvm-args
"--add-opens java.base/jdk.internal.loader=ALL-UNNAMED"`.
> 
> **Risks:**
> - ⚠️ Behaviour change: the new opens go to every app JVM the loop
launches, forked servers included. The open once found to break a
WildFly boot is `java.base/java.net` (it lets HotswapAgent swap
`URLClassLoader.ucp`); that one stays off forked servers. The IDE-parity
opens have not been tried on WildFly or other forked servers.
> - ✅ No public API, security, memory, serialization, threading or
performance impact.
> 
> **Context.** The embedded Maven goal runtime already opened
`jdk.internal.loader` for its own reason (that duplicate is now
dropped), so the problem only showed with the main-class launch and
forked servers. Chosen over leaving it to the developer's `--jvm-args`,
because the failure is silent apart from the app log, and the loop's own
flags already carry HotswapAgent's other opens. The IntelliJ and VS Code
plugins already open this package when they launch with HotswapAgent.
> 
> - Added `java.base/jdk.internal.loader` to the `--add-opens` flags the
dev loop gives the application JVM.
> - Added the other opens the IDE plugins pass and the dev loop lacked:
`java.base/sun.nio.ch`, `java.base/sun.security.action`,
`java.desktop/com.sun.beans`, `java.desktop/com.sun.beans.introspect`
and `java.desktop/com.sun.beans.util`. No dev-loop failure is traced to
these; they are there so both ways of running an app behave the same.
> - Removed the now-duplicate `jdk.internal.loader` open from the
embedded Maven goal runtime's extra flags. It keeps only `java.net`,
which forked servers still don't get, and its comments now say why one
open is safe on a forked server and the other is not.
> - Added tests that every launch has each open the IDE plugins pass and
that the embedded runtime adds only the `java.net` one, which the flags
every launch gets (forked servers included) never carry.
> 
> 
> 
> 
>

Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dev loop on a JetBrains Runtime: a call through executeJs(Class) fails after a method of the interface changes

3 participants