Repository navigation
fix(devloop): open the packages HotswapAgent needs in the app JVM - #27452
Conversation
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
Type of change
|
| 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", |
There was a problem hiding this comment.
Are the opens here in sync with the vscode / intellij plugins?
There was a problem hiding this comment.
@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.introspectandjava.desktop/com.sun.beans.util. - Only the dev loop opens:
java.base/java.util, plusjava.base/java.netfor 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?
There was a problem hiding this comment.
Add the ones from the plugins in this pr
There was a problem hiding this comment.
@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
left a comment
There was a problem hiding this comment.
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.
|
Addressed the |
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.
vaadin-review-bot
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
📝 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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
🧪 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
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
✅ Nothing to flag — the changes look good.
|
|
Documentation Bot: No documentation needed for this change. This is a Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.
|
…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>



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 plainapplyrestarts the app, because the loop sees a structural change to a proxied type; this PR does not change that. Withapply --no-restart, though, the redefine stays in the JVM and the stale proxy throwsAbstractMethodErroron the next call. A later plainapplyno 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 afterapply --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 plainapplyinto 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:
java.base/java.net(it lets HotswapAgent swapURLClassLoader.ucp); that one stays off forked servers. The IDE-parity opens have not been tried on WildFly or other forked servers.Context. The embedded Maven goal runtime already opened
jdk.internal.loaderfor 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.java.base/jdk.internal.loaderto the--add-opensflags the dev loop gives the application JVM.java.base/sun.nio.ch,java.base/sun.security.action,java.desktop/com.sun.beans,java.desktop/com.sun.beans.introspectandjava.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.jdk.internal.loaderopen from the embedded Maven goal runtime's extra flags. It keeps onlyjava.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.java.netone, which the flags every launch gets (forked servers included) never carry.