Repository navigation
Fix NullPointerException when reading "stack" of an error with a null prototype - #2550
Open
average-web-dev wants to merge 1 commit into
Open
average-web-dev wants to merge 1 commit into
average-web-dev wants to merge 1 commit into
Conversation
… prototype NativeError.getStackDelegated() casts the error's prototype to ScriptableObject to look up the stack trace settings. If the prototype was set to null with Object.setPrototypeOf(), this threw a Java NullPointerException that scripts cannot catch. Fall back to the default settings when the prototype is not a ScriptableObject. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reading
stackof an error whose prototype was set tonullthrows a JavaNullPointerException. A script'stry/catchcan't catch it:This came up in the 1.9 backport #2544, where @gbrail
asked
whether the bug is 1.9 only or also on
master. It is partly both:getStackDelegated()casts the prototype toNativeError, so a plainobject as prototype (as transpiled
class MyError extends Error {}does)already throws a
ClassCastException. Onmaster, ConvertNativeErrorto descriptor #2295 changed the cast toScriptableObject, which fixed that case.nullprototype still fails onmaster, with aNullPointerExceptiononthe next line.
This PR fixes it on
master. #2544 is the backport of this PR to 1.9.Cause and fix
NativeError.getStackDelegated()casts the error's prototype toScriptableObjectto look up the stack trace settings (stackTraceLimit,prepareStackTrace), and then calls a method on it.The fix only reads the settings when the prototype is a
ScriptableObject.Otherwise it uses the defaults, as it already does when the prototype has no
settings attached.
Tests
New test
ErrorPropertiesTest.stackWithChangedPrototype, in all modes. Itcovers a plain object,
nulland aProxyas prototype, the same cases as in#2544. Without the fix the
nullcase fails. The full test suite passes.A note on how this was developed
I developed this PR with the help of an AI coding agent (Claude Code), and I
reviewed, tested and take responsibility for all of the changes. If the project
has concerns about or rules for AI-assisted contributions, please let me know.
I'm dyslexic, so I usually let AI help me write or proofread text like this
description. If anything reads unclear, please ask and I'll clarify.
🤖 Generated with Claude Code