Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: JRuby 1.7.0.RC1
-
Component/s: Parser
-
Labels:None
-
Number of attachments :
Description
Hi there,
I've been trying out the great new coverage changes made in JRUBY-6106. I have a Sinatra app for which simplecov is now working perfectly, but I've hit an interesting problem when trying the same thing on a Rails app.
I'm building against the current git master
(4e471f489ee6e6aa5d74d64893d709c85a312ee1) with:
ant clean && ant jar-jruby-complete
When I use the resulting jar to run my Rails app with simplecov enabled, I get exceptions like this:
CoverageModule.java:40:in `result': java.lang.NullPointerException
from CoverageModule$INVOKER$s$0$0$result.gen:-1:in `call'
from CachingCallSite.java:292:in `cacheAndCall'
from CachingCallSite.java:135:in `call'
from CallNoArgNode.java:63:in `interpret'
from CallOneArgNode.java:57:in `interpret'
After a bit of debugging I think I've tracked the problem down to what might be two different issues.
The first issue comes about when calling require on an empty file (or a file consisting of nothing but comments). This seems to cause a null to be added to the coverage data, which blows up when generating results. I can reproduce that with:
$ GEM_HOME=$PWD/test_gems java -jar lib/jruby-complete.jar -S gem install simplecov $ echo > empty.rb $ cat | GEM_HOME=$PWD/test_gems java -jar lib/jruby-complete.jar -I. --debug --1.9 - require "rubygems" require 'simplecov' SimpleCov.start require "empty.rb" ^D
For me, that blows up with an exception like the one shown above.
I'm finding the other issue a bit harder to nail down. The ParserConfiguration.coverLine(int i) method takes a line number and marks it off as being covered. But when running my Rails app under simplecov, I see that 'i' isn't always positive--I see numbers ranging from -9 and up, and the negative number causes a RuntimeException when it tries to access an invalid array offset.
I haven't made much headway in figuring out why the parser would report a negative line number--it only seems to happen in my app when parsing .erb files, but I can't reproduce the problem when loading the same .erb templates from the command line. I thought I'd just check if line numbers sometimes being negative was expected before diving in further.
I've attached a patch that sorts things out for my local instance, but realise I'm probably just masking the symptoms. I thought it might help to show the spots I'm talking about, though.
Thanks for all your great work, and please let me know if I can do any debugging from this end.
Cheers,
Mark
Great investigation!
I had not considered the case of a file with no lines; it should indeed initialize to at least an empty array, so future array dereferences don't cause NPE.
The other one is definitely more confusing, for the reasons you state: I wouldn't expect the parser to produce negative line numbers.
I'll have a look at your patch. Without knowing why the parser produces negative line numbers, masking the issue might be the simplest fix. It's possible that bad line numbers are being fed to ERB processing somehow, or those negative line numbers might actually be expected. It may be that we should not be doing coverage processing at all for eval-related parses that don't have an explicit file, but I (or someone) would have to research to see if that's the case.