wwag110465 / js-test-driver

Automatically exported from code.google.com/p/js-test-driver
0 stars 0 forks source link

Coverage module can't be loaded by sun.misc.Launcher$AppClassLoader #381

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Start JsTestDriver server on port 9876 and capture a browser.
2. Add attached file (SampleTestRunnerWithCoverage.java) to JsTestDriver 
project and try to run this file as java application from IDE.

I'm getting following exception:
setting runnermode QUIET
Exception in thread "main" java.lang.RuntimeException: java.io.IOException: 
Stream closed
    at com.google.jstestdriver.coverage.ClassFileLoader.load(ClassFileLoader.java:41)
    at com.google.jstestdriver.coverage.CoverageJsAdder.processPlugins(CoverageJsAdder.java:47)
    at com.google.jstestdriver.model.RunDataFactory.get(RunDataFactory.java:73)
    at com.google.jstestdriver.ActionRunner.runActions(ActionRunner.java:57)
    at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfigurationWithFlags(JsTestDriverImpl.java:342)
    at com.google.jstestdriver.embedded.JsTestDriverImpl.runConfiguration(JsTestDriverImpl.java:233)
    at com.google.jstestdriver.coverage.SampleTestRunnerWithCoverage.main(SampleTestRunnerWithCoverage.java:31)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
Caused by: java.io.IOException: Stream closed
    at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:134)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
    at com.google.jstestdriver.coverage.ClassFileLoader.load(ClassFileLoader.java:37)
    ... 11 more

It turns out that expression 
"getClass().getClassLoader().getResourceAsStream(path)" in method 
ClassFileLoader.load(String path) evaluates to null. It seems the cause is that 
the value of "path" variable starts with '/' 
("/com/google/jstestdriver/coverage/javascript/LCOV.js").
The Javadoc is not too clear on this point, but it seems 
ClassLoader.getResourceAsStream() method does not like leading "/", because all 
names are absolute (on contrary Class.getResourceAsStream() expects absolute 
paths to have leading "/").
Useful links on the topic:
http://www.javaworld.com/javaworld/javaqa/2003-08/01-qa-0808-property.html?page=
2
http://weaklyreachable.blogspot.com/2010/06/leading-slash-vs-classloadergetresou
rce.html

But I don't really understand why it's working. :) Maybe some ClassLoader 
implementations tolerate leading "/".
The solution is to replace 
"getClass().getClassLoader().getResourceAsStream(path)" with 
"getClass().getResourceAsStream(path)".

In my case "getClass().getClassLoader()" is resolved to 
sun.misc.Launcher$AppClassLoader.

I've attached a patch, that fixes above-mentioned problem.

Original issue reported on code.google.com by Sergey.S...@gmail.com on 11 Jun 2012 at 11:52

Attachments: