Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

java.lang.NullPointerException: NAME goog 12 #3484

Open
thebravoman opened this issue Oct 18, 2019 · 9 comments
Open

java.lang.NullPointerException: NAME goog 12 #3484

thebravoman opened this issue Oct 18, 2019 · 9 comments
Labels
internal-issue-created An internal Google issue has been created to track this GitHub issue

Comments

@thebravoman
Copy link

thebravoman commented Oct 18, 2019

Playing around with '@implements' and an error occurred when the method 'getSpecial' has an '@export'

GCC version is: closure-compiler-v20190819.jar

Running with

java -jar $CLOSURE_PATH --js step.js --generate_exports  --compilation_level ADVANCED_OPTIMIZATIONS > result.js

Error is:

java.lang.NullPointerException: NAME goog 12 [length: 4] [source_file: step.js]
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:895)
	at com.google.javascript.jscomp.RemoveUnusedCode.getVarForNameNode(RemoveUnusedCode.java:723)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseNameNode(RemoveUnusedCode.java:578)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseNode(RemoveUnusedCode.java:424)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseGetProp(RemoveUnusedCode.java:467)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseNode(RemoveUnusedCode.java:429)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseChildren(RemoveUnusedCode.java:1126)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseCall(RemoveUnusedCode.java:635)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseNode(RemoveUnusedCode.java:352)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseChildren(RemoveUnusedCode.java:1126)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseNode(RemoveUnusedCode.java:433)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseChildren(RemoveUnusedCode.java:1126)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseNode(RemoveUnusedCode.java:433)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseChildren(RemoveUnusedCode.java:1126)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseNode(RemoveUnusedCode.java:433)
	at com.google.javascript.jscomp.RemoveUnusedCode.access$1300(RemoveUnusedCode.java:95)
	at com.google.javascript.jscomp.RemoveUnusedCode$Continuation.apply(RemoveUnusedCode.java:1592)
	at com.google.javascript.jscomp.RemoveUnusedCode.traverseAndRemoveUnusedReferences(RemoveUnusedCode.java:273)
	at com.google.javascript.jscomp.RemoveUnusedCode.process(RemoveUnusedCode.java:252)
	at com.google.javascript.jscomp.PhaseOptimizer$NamedPass.process(PhaseOptimizer.java:326)
	at com.google.javascript.jscomp.PhaseOptimizer.process(PhaseOptimizer.java:235)
	at com.google.javascript.jscomp.Compiler.performOptimizations(Compiler.java:2413)
	at com.google.javascript.jscomp.Compiler.lambda$stage2Passes$1(Compiler.java:786)
	at com.google.javascript.jscomp.CompilerExecutor$2.call(CompilerExecutor.java:102)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

Example is:

/**
 * @interface
 */
var IStep = function() {}

/** @return {IStep|null} */
IStep.prototype.getSpecial = function() {}

/**
 * @implements {IStep}
 */
class Implementor1 {
    constructor(parent = null) {
        /** @type {IStep|null} */
        this._parent = parent;
    }

    getNotSpecial() {
        return new Date();
    }

    /**	
     * @export
     * @return {IStep|null}
     */
    getSpecial() {
        if (this.getNotSpecial().now() > 2529644667834) {
            return null;
        }
        return this._parent;
    }
}

class Implementor2 {
    constructor() {}

    /**
     * @return {IStep} null
     */
    getSpecial() {
        return new Implementor1()
    }
}

const array = []
array.push(new Implementor1(new Implementor1()))
array.push(new Implementor2())
console.log(new Implementor1().getNotSpecial())
console.log(array[1].getSpecial())
@thebravoman
Copy link
Author

Same error occurred for

/**
 * @const
 * @namespace
 */
var NN = {}

/**
 * @interface
 * @export
 */
NN.IStep = function() {}

Am I missing something here?

java.lang.NullPointerException: NAME goog 11 [length: 4] [source_file: step.js]
	at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:895)
	at com.google.javascript.jscomp.RemoveUnusedCode.getVarForNameNode(RemoveUnusedCode.java:723)

@evmar
Copy link
Contributor

evmar commented Oct 18, 2019

Created Google internal http://b/142964491

@evmar
Copy link
Contributor

evmar commented Oct 18, 2019

We suspect that using @export triggers a reference to goog.exportSymbol, so you need the Closure base library involved.

@thebravoman
Copy link
Author

I could not find an easy way to include goog.base. To include goog.require('goog.base') i need to have goog already defined.

Changing as

goog.require('goog.base')
/**
 * @const
 * @namespace
 */
var NN = {}

/**
 * @interface
 */
NN.IStep = function() {}

for files

├── goog
│   └── base.js
├── result.js
└── step.js

and compiling gives me

step.js:1: ERROR - [JSC_MISSING_MODULE_OR_PROVIDE] Required namespace "goog.base" never defined.
goog.require('goog.base')

Reading at https://developers.google.com/closure/library/docs/gettingstarted

I am missing something fundamental here, but probably that's a discussion for another place.

@thebravoman
Copy link
Author

Just copy pasted the content of closure/goog/base on top of my file. It is compiling and I can continue my learning from here.

Thanks

@thebravoman
Copy link
Author

On the '@export' documentation it is written that base should be included

@thebravoman
Copy link
Author

thebravoman commented Oct 19, 2019

On the export documentation
https://github.com/google/closure-compiler/wiki/Annotating-JavaScript-for-the-Closure-Compiler#export-export-sometype

It is written that base should be included

Code that uses the @export annotation must either:

    include closure/base.js, or
    define both goog.exportSymbol and goog.exportProperty with the same method signature in their own codebase.

So I suppose it is not an error really.

@evmar
Copy link
Contributor

evmar commented Oct 19, 2019

Just a guess, but I think you can include base.js as an additional input to your compilation, without modifying this file.

@evmar evmar added the internal-issue-created An internal Google issue has been created to track this GitHub issue label Oct 22, 2019
@DreierF
Copy link

DreierF commented Dec 1, 2019

I'm experiencing the same crash. For me this happens in a slightly different setting, but seems to have the same root cause.

import * as goog from '../goog.js';
let SOMETHING = goog.LOCALE;
export {SOMETHING};

Debugging into the compiler revealed that the scope only knows the variable global$$module$__$closure_library_converted$closure$goog$goog when it tries to look up goog.

Compiler version is v20191111.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal-issue-created An internal Google issue has been created to track this GitHub issue
Projects
None yet
Development

No branches or pull requests

3 participants