Harden REPL in presence of values that fail to initialize #14702
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The right hand side of value definitions in the REPL are computed in the static
initializer for the wrapper object created for that input line (e.g. rs$line$1).
If any of these definitions throws an exception, the wrapper class will fail to
initialize, and further attempts to use the class will throw NoClassDefFoundError.
In this PR, we avoid all reflective access on a wrapper class once we notice
that it failed to initialize, and mark that wrapper object as invalid in the REPL
state. We discard all input from the failed wrapper (which may have been multi-line
containing many statements and definitions); any types, terms, aliases, or imports
defined there will not override any existing with the same name, and will not be
accessible in subsequent runs.
We also avoid crashing the REPL when the input is of the form
val _ = ???
,where the RHS throws any subclass of java.lang.Error that is non-fatal.
Fixes #4416
Fixes #14473
Fixes #14701