Fix NPE in InlineObjectLiterals when block-scoped function shadows hoisted var (fixes #4200) - #4333
Open
itzabhishekgour wants to merge 1 commit into
Open
Fix NPE in InlineObjectLiterals when block-scoped function shadows hoisted var (fixes #4200)#4333itzabhishekgour wants to merge 1 commit into
itzabhishekgour wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
@google-cla check |
itzabhishekgour
force-pushed
the
fix/issue-4200-npe
branch
from
August 14, 2026 23:06
e9ba873 to
968b16b
Compare
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.
Summary
Fixes #4200
InlineObjectLiterals.InliningBehavior.afterExitScopedereferences theReferenceCollectionreturned byreferenceMap.getReferences(v)without checking for null:Root Cause
t.getScope().getVarIterable()returns everyVarregistered bySyntacticScopeCreatorfor a scope, butreferenceMaponly contains an entry for aVarif at least oneNAMEreference to it was actually visited during traversal.When a block-scoped
functiondeclaration shadows a hoistedvarof the same name — e.g.var x; function x() {}inside the same non-hoist block — the two declarations are registered as separateVarobjects in separate scopes. EveryNAME "x"encountered inside the block resolves to the closer (block-scope) binding, so the hoist-scopeVarnever gets a matching reference collected viaaddReference().referenceMap.getReferences(v)then returnsnullfor it, and the subsequent.referencesfield access throws the NPE.InlineVariablesalready guards against exactly this case (InlineVariables.java:687);InlineObjectLiteralswas missing the equivalent check.Reachability
This precondition — an AST holding this shadowing pattern un-normalized — does not occur in the standard
Compiler.compile()pipeline, sinceNormalize(viaMakeDeclaredNamesUnique) always runs beforeInlineObjectLiteralsand eliminates this kind of shadowing beforehand. The original crash was found by a JQF fuzzer harness exercising this pass directly on a non-normalized AST. This fix is defense-in-depth: it makesInlineObjectLiteralsrobust against a violated precondition rather than closing a crash reachable through normal compilation.Verification
testNoCrash_issue4200_blockScopedFunctionDeclarationShadowsHoistedVartoInlineObjectLiteralsTest.java, usingdisableNormalize()to hold the AST in the vulnerable (non-normalized) state — this shadowing pattern is otherwise eliminated byNormalizebefore this pass ever runs.NullPointerException; with the fix restored, it passes.InlineObjectLiteralsTestsuite passes with no regressions.bazel test //:test/com/google/javascript/jscomp/InlineObjectLiteralsTest