Closure-compiler: Bad JSdoc comments on getters and setters can cause INTERNAL COMPILER ERROR

Created on 1 Jun 2017  路  3Comments  路  Source: google/closure-compiler

I came across a strange issue today that seems to be caused by a bad jsdoc on class setters and getters.
If a user specifies a type for a getter, but doesn't specify the type for its associated setter, the compiler crashes with an INTERNAL COMPILER ERROR:

The following is a very simple example:

class BasicClass
{
    constructor()
    {
        this.value = true;
    }

    /**
     * @returns {boolean} Get That value
     */
    get thatValue()
    {
        return this.value;
    }

    /**
     * @param value Set that value
     */
    set thatValue(value)
    {
        this.value = value;
    }
}

I'm also getting the same error if I don't specify a type for both the getter and the setter. i.e.

    /**
     * @returns Get That value
     */
    get thatValue()
    {
        return this.value;
    }

    /**
     * @param value Set that value
     */
    set thatValue(value)
    {
        this.value = value;
    }

If I add the {boolean} type specifier to the setter, the class compiles without any issue. If I remove the jsdoc entirely, there's also no issue.

Compiler command line:

closure-compiler --warning_level QUIET --language_out ES5 --strict_mode_input false --js ClosureTest.js --js_output_file output.js

Compiler version:

Closure Compiler (http://github.com/google/closure-compiler)
Version: v20170521
Built on: 2017-05-22 12:38

Error output:

java.lang.RuntimeException: INTERNAL COMPILER ERROR.
Please report this problem.

null
  Node(CLASS): ClosureTest.js:7:0
class BasicClass
  Parent(SCRIPT): ClosureTest.js:7:0
class BasicClass

    at com.google.javascript.jscomp.Es6RewriteClass.visitNonMethodMember(Es6RewriteClass.java:383)
    at com.google.javascript.jscomp.Es6RewriteClass.visitClass(Es6RewriteClass.java:147)
    at com.google.javascript.jscomp.Es6RewriteClass.visit(Es6RewriteClass.java:95)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:629)
    at com.google.javascript.jscomp.NodeTraversal.traverseChildren(NodeTraversal.java:701)
    at com.google.javascript.jscomp.NodeTraversal.handleScript(NodeTraversal.java:579)
    at com.google.javascript.jscomp.NodeTraversal.traverseBranch(NodeTraversal.java:604)
    at com.google.javascript.jscomp.NodeTraversal.traverse(NodeTraversal.java:305)
    at com.google.javascript.jscomp.NodeTraversal.traverseEs6(NodeTraversal.java:553)
    at com.google.javascript.jscomp.TranspilationPasses.processTranspile(TranspilationPasses.java:252)
    at com.google.javascript.jscomp.Es6RewriteClass.process(Es6RewriteClass.java:64)
    at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:298)
    at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:232)
    at com.google.javascript.jscomp.Compiler.check(Compiler.java:1114)
    at com.google.javascript.jscomp.Compiler.performChecksAndTranspilation(Compiler.java:914)
    at com.google.javascript.jscomp.Compiler.access$000(Compiler.java:95)
    at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:848)
    at com.google.javascript.jscomp.Compiler$3.call(Compiler.java:845)
    at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:93)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NullPointerException

Most helpful comment

There is already a change in progress that I think might fix this.

All 3 comments

There is already a change in progress that I think might fix this.

The change is being uploaded tomorrow.

Excellent, thank you for looking in to this!

Was this page helpful?
0 / 5 - 0 ratings