Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JRuby thrown NullPointerException on File.open of nonexistent uri #6219

@JohnPhillips31416

Description

@JohnPhillips31416

JRuby version: 9.2.11.1

For the folllowing file

fname = "uri:classloader:/a/b/c/d.e"

puts "fname is #{fname} = #{File.path(fname)}"

File.open(fname) do |file|
  puts "Opened #{file.name}"
end

I get NullPointerException not 'No such file or directory' if the file does not exist

$ ruby -v
jruby 9.2.11.1 (2.5.7) 2020-03-25 b1f55b1a40 OpenJDK 64-Bit Server VM 11.0.6+10 on 11.0.6+10 +jit [darwin-x86_64]
$ ruby foo.rb 
fname is uri:classloader:/a/b/c/d.e = uri:classloader:/a/b/c/d.e
Unhandled Java exception: java.lang.NullPointerException
java.lang.NullPointerException: null
      openInputStream at org/jruby/util/URLResource.java:153
          openChannel at org/jruby/util/URLResource.java:158
                 open at org/jruby/util/io/PosixShim.java:438
          cloexecOpen at org/jruby/RubyIO.java:1269
          sysopenFunc at org/jruby/RubyIO.java:1257
      sysopenInternal at org/jruby/RubyIO.java:1249
              sysopen at org/jruby/RubyIO.java:1234
      fileOpenGeneric at org/jruby/RubyFile.java:1471
             openFile at org/jruby/RubyFile.java:1448
           initialize at org/jruby/RubyFile.java:365
                 call at org/jruby/RubyFile$INVOKER$i$0$3$initialize.gen:-1
                 call at org/jruby/runtime/callsite/CachingCallSite.java:84
          newInstance at org/jruby/RubyClass.java:939
                 open at org/jruby/RubyIO.java:1156
                 call at org/jruby/RubyIO$INVOKER$s$0$0$open.gen:-1
                 call at org/jruby/internal/runtime/methods/DynamicMethod.java:204
         cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:386
                 call at org/jruby/runtime/callsite/CachingCallSite.java:184
             callIter at org/jruby/runtime/callsite/CachingCallSite.java:191
    invokeOther4:open at foo.rb:6
               <main> at foo.rb:6
  invokeWithArguments at java/lang/invoke/MethodHandle.java:710
                 load at org/jruby/ir/Compiler.java:89
            runScript at org/jruby/Ruby.java:1205
          runNormally at org/jruby/Ruby.java:1128
          runNormally at org/jruby/Ruby.java:1146
          runFromMain at org/jruby/Ruby.java:958
        doRunFromMain at org/jruby/Main.java:412
          internalRun at org/jruby/Main.java:304
                  run at org/jruby/Main.java:234
                 main at org/jruby/Main.java:206

$  rbenv shell 2.5.8
$ ruby -v
ruby 2.5.8p224 (2020-03-31 revision 67882) [x86_64-darwin18]
$ ruby foo.rb 
fname is uri:classloader:/a/b/c/d.e = uri:classloader:/a/b/c/d.e
Traceback (most recent call last):
	2: from foo.rb:6:in `<main>'
	1: from foo.rb:6:in `open'
foo.rb:6:in `initialize': No such file or directory @ rb_sysopen - uri:classloader:/a/b/c/d.e (Errno::ENOENT)
$ 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions