google / closure-compiler

A JavaScript checker and optimizer.
https://developers.google.com/closure/compiler/
Apache License 2.0
7.41k stars 1.15k forks source link

INTERNAL COMPILER ERROR: Cannot invoke "com.google.javascript.rhino.PMap.isEmpty()" because "that" is null #4151

Closed thheller closed 9 months ago

thheller commented 9 months ago

We run into an INTERNAL COMPILER ERROR, When trying to process the bwip-js npm code with the Closure Compiler.

It reproduces with the current google-closure-compiler npm release (20230802.0.0), but the full trace when running via shadow-cljs is a bit more informative due to running with -XX:-OmitStackTraceInFastThrow. That stacktrace is down below.

The steps to reproduce with just google-closure-compiler are:

mkdir repro
cd repro
npm init -y
npm install google-closure-compiler
curl -O https://unpkg.com/bwip-js@4.2.0/dist/bwip-js.js
npx google-closure-compiler --js bwip-js.js

It seems to fail in two locations "randomly", which I guess is due to different hash ordering. One is

Node(BLOCK): node_modules/bwip-js/dist/bwip-js.js:19468:25
    $_.encb = function() {
  Parent(FUNCTION ): node_modules/bwip-js/dist/bwip-js.js:19468:14
    $_.encb = function() {

but on a different run you might get

  Node(BLOCK): bwip-js.js:6351:30
    $_.drawlayer = function() {
  Parent(FUNCTION ): bwip-js.js:6351:19
    $_.drawlayer = function() {

The NPE they run into is the same from com.google.javascript.rhino.HamtPMap.equivalent (HamtPMap.java:412) though.


Please report this problem.

Cannot invoke "com.google.javascript.rhino.PMap.isEmpty()" because "that" is null
  Node(BLOCK): node_modules/bwip-js/dist/bwip-js.js:19468:25
    $_.encb = function() {
  Parent(FUNCTION ): node_modules/bwip-js/dist/bwip-js.js:19468:14
    $_.encb = function() {

    com.google.javascript.jscomp.Compiler.throwInternalError (Compiler.java:3269)
    com.google.javascript.jscomp.NodeTraversal.throwUnexpectedException (NodeTraversal.java:509)
    com.google.javascript.jscomp.NodeTraversal.traverseRoots (NodeTraversal.java:553)
    com.google.javascript.jscomp.NodeTraversal$Builder.traverseRoots (NodeTraversal.java:473)
    com.google.javascript.jscomp.FlowSensitiveInlineVariables.process (FlowSensitiveInlineVariables.java:277)
    com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process (PhaseOptimizer.java:240)
    com.google.javascript.jscomp.PhaseOptimizer.process (PhaseOptimizer.java:179)
    com.google.javascript.jscomp.Compiler.performTranspilationAndOptimizations (Compiler.java:2969)
    com.google.javascript.jscomp.Compiler.lambda$stage2Passes$7 (Compiler.java:1031)
    com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread (CompilerExecutor.java:126)
    com.google.javascript.jscomp.Compiler.runInCompilerThread (Compiler.java:1079)
    com.google.javascript.jscomp.Compiler.stage2Passes (Compiler.java:1028)
    com.google.javascript.jscomp.Compiler.compile (Compiler.java:914)
    jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    java.lang.reflect.Method.invoke (Method.java:578)
    clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:167)
    clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:102)
    shadow.build.closure/convert-sources-simple*/fn--165003/fn--165004 (closure.clj:2063)
    shadow.build.closure/convert-sources-simple*/fn--165003 (closure.clj:2061)
    shadow.build.closure/convert-sources-simple* (closure.clj:2060)
    shadow.build.closure/convert-sources-simple* (closure.clj:1924)
    shadow.build.closure/convert-sources-simple (closure.clj:2234)
    shadow.build.closure/convert-sources-simple (closure.clj:2184)
    shadow.build.compiler/maybe-closure-convert (compiler.clj:1385)
    shadow.build.compiler/maybe-closure-convert (compiler.clj:1378)
    shadow.build.compiler/compile-all (compiler.clj:1634)
    shadow.build.compiler/compile-all (compiler.clj:1497)
    shadow.build.api/compile-sources (api.clj:261)
    shadow.build.api/compile-sources (api.clj:253)
    shadow.build/compile (build.clj:512)
    shadow.build/compile (build.clj:493)
    shadow.cljs.devtools.server.remote-ext/do-build/fn--23096 (remote_ext.clj:104)
    clojure.core/binding-conveyor-fn/fn--5823 (core.clj:2047)
    java.util.concurrent.FutureTask.run (FutureTask.java:317)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
    java.lang.Thread.run (Thread.java:1623)
Caused by:
NullPointerException: Cannot invoke "com.google.javascript.rhino.PMap.isEmpty()" because "that" is null
    com.google.javascript.rhino.HamtPMap.equivalent (HamtPMap.java:412)
    com.google.javascript.jscomp.MaybeReachingVariableUse$ReachingUses.equalMaps (MaybeReachingVariableUse.java:164)
    com.google.javascript.rhino.HamtPMap.equivalent (HamtPMap.java:439)
    com.google.javascript.rhino.HamtPMap.equivalent (HamtPMap.java:446)
    com.google.javascript.rhino.HamtPMap.equivalent (HamtPMap.java:411)
    com.google.javascript.jscomp.MaybeReachingVariableUse$ReachingUses.equals (MaybeReachingVariableUse.java:160)
    com.google.javascript.jscomp.DataFlowAnalysis.flow (DataFlowAnalysis.java:304)
    com.google.javascript.jscomp.DataFlowAnalysis.analyze (DataFlowAnalysis.java:225)
    com.google.javascript.jscomp.FlowSensitiveInlineVariables.enterScope (FlowSensitiveInlineVariables.java:206)
    com.google.javascript.jscomp.NodeTraversal.pushScope (NodeTraversal.java:1155)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:936)
    com.google.javascript.jscomp.NodeTraversal.traverseFunction (NodeTraversal.java:1008)
    com.google.javascript.jscomp.NodeTraversal.handleFunction (NodeTraversal.java:859)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:905)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseFunction (NodeTraversal.java:1008)
    com.google.javascript.jscomp.NodeTraversal.handleFunction (NodeTraversal.java:859)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:905)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseFunction (NodeTraversal.java:1008)
    com.google.javascript.jscomp.NodeTraversal.handleFunction (NodeTraversal.java:859)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:905)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseFunction (NodeTraversal.java:1008)
    com.google.javascript.jscomp.NodeTraversal.handleFunction (NodeTraversal.java:859)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:905)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseChildren (NodeTraversal.java:1136)
    com.google.javascript.jscomp.NodeTraversal.handleScript (NodeTraversal.java:847)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:902)
    com.google.javascript.jscomp.NodeTraversal.traverseBranch (NodeTraversal.java:953)
    com.google.javascript.jscomp.NodeTraversal.traverseRoots (NodeTraversal.java:549)
    com.google.javascript.jscomp.NodeTraversal$Builder.traverseRoots (NodeTraversal.java:473)
    com.google.javascript.jscomp.FlowSensitiveInlineVariables.process (FlowSensitiveInlineVariables.java:277)
    com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process (PhaseOptimizer.java:240)
    com.google.javascript.jscomp.PhaseOptimizer.process (PhaseOptimizer.java:179)
    com.google.javascript.jscomp.Compiler.performTranspilationAndOptimizations (Compiler.java:2969)
    com.google.javascript.jscomp.Compiler.lambda$stage2Passes$7 (Compiler.java:1031)
    com.google.javascript.jscomp.CompilerExecutor.runInCompilerThread (CompilerExecutor.java:126)
    com.google.javascript.jscomp.Compiler.runInCompilerThread (Compiler.java:1079)
    com.google.javascript.jscomp.Compiler.stage2Passes (Compiler.java:1028)
    com.google.javascript.jscomp.Compiler.compile (Compiler.java:914)
    jdk.internal.reflect.DirectMethodHandleAccessor.invoke (DirectMethodHandleAccessor.java:104)
    java.lang.reflect.Method.invoke (Method.java:578)
    clojure.lang.Reflector.invokeMatchingMethod (Reflector.java:167)
    clojure.lang.Reflector.invokeInstanceMethod (Reflector.java:102)
    shadow.build.closure/convert-sources-simple*/fn--165003/fn--165004 (closure.clj:2063)
    shadow.build.closure/convert-sources-simple*/fn--165003 (closure.clj:2061)
    shadow.build.closure/convert-sources-simple* (closure.clj:2060)
    shadow.build.closure/convert-sources-simple* (closure.clj:1924)
    shadow.build.closure/convert-sources-simple (closure.clj:2234)
    shadow.build.closure/convert-sources-simple (closure.clj:2184)
    shadow.build.compiler/maybe-closure-convert (compiler.clj:1385)
    shadow.build.compiler/maybe-closure-convert (compiler.clj:1378)
    shadow.build.compiler/compile-all (compiler.clj:1634)
    shadow.build.compiler/compile-all (compiler.clj:1497)
    shadow.build.api/compile-sources (api.clj:261)
    shadow.build.api/compile-sources (api.clj:253)
    shadow.build/compile (build.clj:512)
    shadow.build/compile (build.clj:493)
    shadow.cljs.devtools.server.remote-ext/do-build/fn--23096 (remote_ext.clj:104)
    clojure.core/binding-conveyor-fn/fn--5823 (core.clj:2047)
    java.util.concurrent.FutureTask.run (FutureTask.java:317)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1144)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:642)
    java.lang.Thread.run (Thread.java:1623)```
lauraharker commented 9 months ago

We got a recent report of this from inside Google with the same stack trace. It should be fixed with https://github.com/google/closure-compiler/commit/23e25dae584075decfd7c7e3ecc876cd8f55d42d (and npm nightly builds should restart soon - https://github.com/google/closure-compiler-npm)