Skip to content

loading jruby ext can fail with NullPointerException #711

Description

@kares

in an embedded use-case (e.g. with jar-dependencies instructed to use the snakeyaml from the parent class-path)
the input stream (for META-INF/maven/org.snakeyaml/snakeyaml-engine/pom.properties) can easily end up as null:

NameError: cannot load (ext) (org.jruby.ext.psych.PsychLibrary)
  org/jruby/ext/jruby/JRubyUtilLibrary.java:219:in `load_ext'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/psych.rb:9:in `<main>'
  org/jruby/RubyKernel.java:1187:in `require'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/core_ext/kernel_require.rb:148:in `require'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems.rb:610:in `load_yaml'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/package.rb:549:in `read_checksums'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/package.rb:611:in `block in verify'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/package/tar_reader.rb:27:in `new'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/package.rb:610:in `block in verify'
  org/jruby/RubyIO.java:1198:in `open'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/package/file_source.rb:29:in `with_read_io'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/package.rb:609:in `verify'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/rubygems/package.rb:590:in `spec'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/rubygems_integration.rb:208:in `spec_from_gem'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/runtime.rb:218:in `block in prune_gem_cache'
  org/jruby/RubyArray.java:3149:in `delete_if'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/runtime.rb:217:in `prune_gem_cache'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/runtime.rb:144:in `prune_cache'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/runtime.rb:136:in `cache'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/cli/install.rb:65:in `block in run'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/settings.rb:131:in `temporary'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/cli/install.rb:64:in `run'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/cli.rb:257:in `block in install'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/settings.rb:131:in `temporary'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/cli.rb:256:in `install'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/cli.rb:31:in `dispatch'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/cli.rb:25:in `start'
  bin/bundle:33:in `block in <main>'
  uri:classloader:/META-INF/jruby.home/lib/ruby/stdlib/bundler/friendly_errors.rb:120:in `with_friendly_errors'
  bin/bundle:25:in `<main>'
Java::JavaLang::NullPointerException: inStream parameter is null
  java.base/java.util.Objects.requireNonNull(Objects.java:246)
  java.base/java.util.Properties.load(Properties.java:406)
  org.jruby.ext.psych.PsychLibrary.load(PsychLibrary.java:57)
  org.jruby.ext.jruby.JRubyUtilLibrary.loadExtension(JRubyUtilLibrary.java:242)
  org.jruby.ext.jruby.JRubyUtilLibrary.load_ext(JRubyUtilLibrary.java:219)
  org.jruby.ext.jruby.JRubyUtilLibrary$INVOKER$s$1$0$load_ext.call(JRubyUtilLibrary$INVOKER$s$1$0$load_ext.gen)
  org.jruby.runtime.callsite.CachingCallSite.cacheAndCall(CachingCallSite.java:466)
  org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:244)
  org.jruby.ir.interpreter.InterpreterEngine.processCall(InterpreterEngine.java:314)
  org.jruby.ir.interpreter.StartupInterpreterEngine.interpret(StartupInterpreterEngine.java:66)
  org.jruby.ir.interpreter.Interpreter.INTERPRET_ROOT(Interpreter.java:98)
  org.jruby.ir.interpreter.Interpreter.execute(Interpreter.java:83)
  org.jruby.ir.interpreter.Interpreter.execute(Interpreter.java:32)
  org.jruby.ir.IRTranslator.execute(IRTranslator.java:41)
  org.jruby.Ruby.runInterpreter(Ruby.java:1269)
  org.jruby.Ruby.loadFile(Ruby.java:3060)

and extra != null check should be added https://github.com/ruby/psych/blob/master/ext/java/org/jruby/ext/psych/PsychLibrary.java#L57

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions