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

Instrumenting .js-files with empty switch statement causes NullPointerException #179

Closed
lanzelot1989 opened this issue Jan 14, 2015 · 3 comments
Assignees

Comments

@lanzelot1989
Copy link

When instrumenting the js-files of our AngularJS website I noticed that this function causes a NullPointerException:

function(n) { switch (n.status) {} return t.reject(n) }

I use the following command

java -jar JSCover-all.jar -fs --local-storage -no-instrument=lib beautified instrumented

The stack trace looks like this
Exception in thread "main" java.lang.NullPointerException
at org.mozilla.javascript.ast.SwitchStatement.toSource(SwitchStatement.java:158)
at org.mozilla.javascript.ast.Block.toSource(Block.java:50)
at org.mozilla.javascript.ast.FunctionNode.toSource(FunctionNode.java:401)
at org.mozilla.javascript.ast.AstNode.printList(AstNode.java:454)
...
at org.mozilla.javascript.ast.AstNode.toSource(AstNode.java:300)
at jscover.instrument.SourceProcessor.instrumentSource(SourceProcessor.java:436)
at jscover.instrument.SourceProcessor.processSourceWithoutHeader(SourceProcessor.java:411)
at jscover.instrument.SourceProcessor.processSource(SourceProcessor.java:403)
at jscover.instrument.SourceProcessor.processSourceForFileSystem(SourceProcessor.java:395)
at jscover.instrument.InstrumenterService.instrumentJSForFileSystem(InstrumenterService.java:381)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:404)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:399)
at jscover.filesystem.FileSystemInstrumenter.copyFolder(FileSystemInstrumenter.java:390)
at jscover.filesystem.FileSystemInstrumenter.run(FileSystemInstrumenter.java:371)
at jscover.Main.runFileSystem(Main.java:479)
at jscover.Main.runJSCover(Main.java:449)
at jscover.Main.runMain(Main.java:417)
at jscover.Main.main(Main.java:406)

It would seem that the empty switch statement causes this problem.

Edit: I used your latest drone.io build.

@tntim96
Copy link
Owner

tntim96 commented Jan 14, 2015

This looks like a Rhino bug. I should be able to fix JSCover's Rhino fork.

@tntim96
Copy link
Owner

tntim96 commented Jan 14, 2015

You can try the fix from source, the latest drone.io build
or the maven snapshot. For maven you'll need to add sonatypes repository with:

        <pluginRepository>
            <id>Sonatype repository</id>
            <name>Sonatype's Maven repository</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
        </pluginRepository>

@lanzelot1989
Copy link
Author

Thanks a lot!

Instrumenting the file now works as expected.

However, I now get
the error "cannot read property '1' of undefined" when I call the web page with the instrumented files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants