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

null pointer exception in java extension #443

Closed
tmm1 opened this issue Apr 7, 2011 · 8 comments
Closed

null pointer exception in java extension #443

tmm1 opened this issue Apr 7, 2011 · 8 comments

Comments

@tmm1
Copy link

tmm1 commented Apr 7, 2011

repro:

require 'rubygems'
require 'nokogiri'

p [:version=, Nokogiri::VERSION]

doc = Nokogiri::HTML::DocumentFragment.parse('<p>this is a string.</p>')
nodes = doc.search('text()')
p nodes
p nodes.first.ancestors('pre, code')

mri:

ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10.5.0]
[:version=, "1.5.0.beta.4"]
[#<Nokogiri::XML::Text:0x80b601b8 "this is a string.">]
[]

jruby:

jruby 1.6.0 (ruby-1.8.7-p330) (2011-04-06 aa7d946) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_24) [darwin-x86_64-java]
[:version=, "1.5.0.beta.4"]
[#<Nokogiri::XML::Text:0x7e4 "this is a string.">]
XmlNodeSet.java:184:in `include_p': java.lang.NullPointerException
  from XmlNodeSet$i$1$0$include_p.gen:65535:in `call'
  from CachingCallSite.java:282:in `cacheAndCall'
  from CachingCallSite.java:139:in `call'
  from CallOneArgNode.java:57:in `interpret'
  from NewlineNode.java:103:in `interpret'
@yokolet
Copy link
Member

yokolet commented Apr 7, 2011

Thanks for giving reproducing sample code. I confirmed NPE was also raised on a master branch. I'll have a look.

@flavorjones
Copy link
Member

Great catch. This appears to be a bug in NodeSet:

require 'rubygems'
require 'nokogiri'

p [:version=, Nokogiri::VERSION]

doc = Nokogiri::XML("<root></root>")
node_set = Nokogiri::XML::NodeSet.new(doc, [])
node_set.include?(doc.root)

results in

[:version=, "1.5.0.beta.4"]
XmlNodeSet.java:145:in `include_p': java.lang.NullPointerException
    from XmlNodeSet$i$1$0$include_p.gen:65535:in `call'
    from CachingCallSite.java:282:in `cacheAndCall'
    from CachingCallSite.java:139:in `call'
    from /home/mike/bar.rb:10:in `__file__'
    from /home/mike/bar.rb:-1:in `load'
    from Ruby.java:670:in `runScript'
    from Ruby.java:574:in `runNormally'
    from Ruby.java:423:in `runFromMain'
    from Main.java:278:in `doRunFromMain'
    from Main.java:198:in `internalRun'
    from Main.java:164:in `run'
    from Main.java:148:in `run'
    from Main.java:128:in `main'

@yokolet
Copy link
Member

yokolet commented Apr 7, 2011

Fixed by rev. 407b582.

On master branch, the sample code printed as in below. So, the issue should be fixed.

[:version=, "1.5.0.beta.4"]
[#<Nokogiri::XML::Text:0x7ea "this is a string.">]
[]

@flavorjones
Copy link
Member

(pure-java) making empty NodeSets with null nodes member safe to operate on. Closed by 694f885.

@tmm1
Copy link
Author

tmm1 commented Apr 7, 2011

👍 thanks

@tmm1
Copy link
Author

tmm1 commented Apr 7, 2011

I can't seem to figure out how to build a new java gem off of master. It keeps failing with:

rake aborted!
Don't know how to build task 'pkg/nokogiri-1.5.0.beta.4.1'

@tmm1
Copy link
Author

tmm1 commented Apr 7, 2011

diff --git a/Rakefile b/Rakefile
index 6e0c6a0..9937e14 100644
--- a/Rakefile
+++ b/Rakefile
@@ -80,11 +80,8 @@ if java
   end

   gem_build_path = File.join 'pkg', HOE.spec.full_name
-  # references to tgz_build_path are to work around a rake bug
-  tgz_build_path = File.join 'pkg', "#{HOE.spec.name}-#{HOE.spec.version}"

-  task gem_build_path => [:compile, tgz_build_path] do
-    cp_r tgz_build_path, gem_build_path, :verbose => true
+  task gem_build_path => :compile do
     cp 'lib/nokogiri/nokogiri.jar',
        File.join(gem_build_path, 'lib', 'nokogiri'),
        :verbose => true

@flavorjones
Copy link
Member

Thanks. See 89056e7

nathanl pushed a commit to nathanl/nokogiri that referenced this issue May 17, 2011
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

3 participants