Skip to content

Prevent variable nullification on later imports#120

Open
m-dzianishchyts wants to merge 2 commits intodflib:mainfrom
m-dzianishchyts:119-fix-variable-nullifying-on-import
Open

Prevent variable nullification on later imports#120
m-dzianishchyts wants to merge 2 commits intodflib:mainfrom
m-dzianishchyts:119-fix-variable-nullifying-on-import

Conversation

@m-dzianishchyts
Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes #119.

Details

When JShell needs to recompile an earlier snippet due to a later snippet affecting its type context (e.g., new wildcard imports), it calls ExecutionControl.redefine() to hot-swap the wrapper class bytecode. The inherited DirectExecutionControl.redefine() unconditionally throws NotImplementedException. JShell then falls back to installing a new wrapper class without re-running the initializer, silently zeroing the static field that backs the user's variable.

We can acknowledge the redefinition and only update the loader's bytecode cache. The already-loaded class stays in place, its static fields are preserved. Subsequent snippets are compiled against the recompiled wrapper's signature, which for import-driven recompilations is equivalent to the original, so field and method resolution keeps working against the existing loaded class.

Testing

Integration test reproduces the bug in a single-cell Jupyter execution. Passes with the fix.

@m-dzianishchyts m-dzianishchyts marked this pull request as draft April 24, 2026 18:00
@m-dzianishchyts m-dzianishchyts marked this pull request as ready for review April 24, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Adding an import in a later cell nullifies variables defined in earlier cells

1 participant