jRuby-1.6.5:NoMethodError 未定义方法 '[]'对于 nil:NilClass
我的环境:
jRuby-1.6.5
Rails 2.3.8
Gems:
- actionmailer(2.3.8)
- actionpack(2.3.8)
- activerecord(2.3.8)
- activerecord-jdbc-adapter(1.1.1)
- activerecord-jdbcpostgresql-adapter(0.8.2)
- activeresource(2.3.8)
- activesupport (2.3.8)
- arel (2.2.1)
- bouncy-castle-java (1.5.0145.2)
- 构建器(3.0.0)
- 捆绑器(1.0.21)
- 水豚(0.4.1.2)
- 快速(0.8.9)
- 子进程(0.1.8)
- 列(0.3.2
- )配置(1.2.0)
- 黄瓜(0.10) .0)
- 黄瓜导轨 (0.3.2)
- culerity (0.2.15)
- database_cleaner(0.6.6)
- diff-lcs(1.1.2)
- factory_girl(1.3.3)
- fastercsv(1.5.4)
- ffi(1.0.7)
- gem_plugin(0.2.3)
- gherkin(2.3.5)
- jdbc-postgres(8.4。第702章)
- jruby-jars(1.5.5)
- jruby-openssl(0.7.3)
- json (1.4.6)
- json_pure(1.5.1)
- launchy(0.4.0)
- mime-types(1.16)
- nokogiri(1.4.4.2)
- rack(1.1.0)
- rack-test(0.5.7)
- rails(2.3.8)
- rake (0.8.7)
- rcov (0.9.9)
- rspec (1.3.1)
- rspec-rails (1.3.3)
- ruby-debug (0.10.4)
- ruby-debug-base (0.10.4)
- rubyzip (0.9.4)
- selenium-client (1.2.18)
- selenium-webdriver (0.1.4)
- 源 (0.0.1) )
- term-ansicolor(1.0.5)
- weakling(0.0.4)
- xpath(0.1.3)
使用jRuby-1.6.5和 metrical gem,遇到以下问题:
从应用程序的根目录执行 metrical
从 app 和 lib 文件夹解析所有 ruby 文件后,命令行输出以下内容:
NoMethodError: undefined method `[]' for nil:NilClass
initialize at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:232
get_elements at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:169
initialize at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:130
assemble_files at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:111
each at org/jruby/RubyArray.java:1612assemble_files at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:109
analyze at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:27
send at org/jruby/RubyKernel.java:2093
generate_report at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/base/generator.rb:130
each at org/jruby/RubyArray.java:1612
generate_report at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/base/generator.rb:128
add at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/base/report.rb:60
run_metric_fu at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/lib/metrical.rb:51
each at org/jruby/RubyArray.java:1612
run_metric_fu at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/lib/metrical.rb:51
run at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/lib/metrical.rb:18
(root) at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/bin/metrical:4
load at org/jruby/RubyKernel.java:1063
(root) at c:\jruby-1.6.5\bin\metrical:19
问题出在哪里我不知道,只是想知道如何绕过它,或者也许可以避免它,因为这非常令人恼火,因为我的团队无法看到给定代码的指标。
先感谢您。
My Environment:
jRuby-1.6.5
Rails 2.3.8
Gems:
- actionmailer (2.3.8)
- actionpack (2.3.8)
- activerecord (2.3.8)
- activerecord-jdbc-adapter (1.1.1)
- activerecord-jdbcpostgresql-adapter (0.8.2)
- activeresource (2.3.8)
- activesupport (2.3.8)
- arel (2.2.1)
- bouncy-castle-java (1.5.0145.2)
- builder (3.0.0)
- bundler (1.0.21)
- capybara (0.4.1.2)
- celerity (0.8.9)
- childprocess (0.1.8)
- columnize (0.3.2)
- configuration (1.2.0)
- cucumber (0.10.0)
- cucumber-rails (0.3.2)
- culerity (0.2.15)
- database_cleaner (0.6.6)
- diff-lcs (1.1.2)
- factory_girl (1.3.3)
- fastercsv (1.5.4)
- ffi (1.0.7)
- gem_plugin (0.2.3)
- gherkin (2.3.5)
- jdbc-postgres (8.4.702)
- jruby-jars (1.5.5)
- jruby-openssl (0.7.3)
- json (1.4.6)
- json_pure (1.5.1)
- launchy (0.4.0)
- mime-types (1.16)
- nokogiri (1.4.4.2)
- rack (1.1.0)
- rack-test (0.5.7)
- rails (2.3.8)
- rake (0.8.7)
- rcov (0.9.9)
- rspec (1.3.1)
- rspec-rails (1.3.3)
- ruby-debug (0.10.4)
- ruby-debug-base (0.10.4)
- rubyzip (0.9.4)
- selenium-client (1.2.18)
- selenium-webdriver (0.1.4)
- sources (0.0.1)
- term-ansicolor (1.0.5)
- weakling (0.0.4)
- xpath (0.1.3)
Using jRuby-1.6.5 and metrical gem, got the following problem:
Execute metrical from the root of the application
After parsing all ruby files from app and lib folders, command line outputs the following:
NoMethodError: undefined method `[]' for nil:NilClass
initialize at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:232
get_elements at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:169
initialize at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:130
assemble_files at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:111
each at org/jruby/RubyArray.java:1612assemble_files at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:109
analyze at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/generators/saikuro.rb:27
send at org/jruby/RubyKernel.java:2093
generate_report at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/base/generator.rb:130
each at org/jruby/RubyArray.java:1612
generate_report at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/base/generator.rb:128
add at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metric_fu-2.1.1/lib/base/report.rb:60
run_metric_fu at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/lib/metrical.rb:51
each at org/jruby/RubyArray.java:1612
run_metric_fu at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/lib/metrical.rb:51
run at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/lib/metrical.rb:18
(root) at c:/jruby-1.6.5/lib/ruby/gems/1.8/gems/metrical-0.0.7/bin/metrical:4
load at org/jruby/RubyKernel.java:1063
(root) at c:\jruby-1.6.5\bin\metrical:19
Where the problem lies I have no idea, just wondering how to bypass it, or maybe avoid it, because it's pretty irritating as my team can't see metrics for the given code.
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们看一下堆栈跟踪。它告诉你很多。
在堆栈顶部,您会看到
saikuro.rb:232
。是这样的:https://github.com/jscruggs/metric_fu/blob/4c12cfa9cf20e38d4d1e3e01455613ff48563ad8/lib/generators/saikuro.rb#L232
只有一个方法调用
[]
,所以可以安全地假设line.match(TYPE_REGEX)
为nil
。这是为什么?好吧,我们不知道。但从堆栈来看,我们相当确定我们在读取Saikuro::SFile
的@file_handle
时遇到了这种情况。我们没有找到与TYPE_REGEX=/Type:(.*) Name/
匹配的行。了解 Saikuro::SFile.new 正在获取哪些参数将非常有指导意义。尝试找到它并检查文件内容。
Let's take a look at the stack trace. It tells you a lot.
At the top of the stack, you see
saikuro.rb:232
. It is this:https://github.com/jscruggs/metric_fu/blob/4c12cfa9cf20e38d4d1e3e01455613ff48563ad8/lib/generators/saikuro.rb#L232
There is only one method call to
[]
, so it is safe to assume thatline.match(TYPE_REGEX)
isnil
. Why is that? Well, we don't know. But looking at the stack, we are fairly certain that we came to this situation while reading@file_handle
forSaikuro::SFile
. We did not find the line that matchesTYPE_REGEX=/Type:(.*) Name/
.It will be immensely instructive to know what parameters
Saikuro::SFile.new
is getting. Try hunting that down, and examine the file content.