jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
  • JRuby
  • JRUBY-2313

Automatically convert RubyFile to java.io.File

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Won't Fix
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: Java Integration
  • Labels:
    None

Description

When I give a java method a Ruby file: File.new('/home/leon/test.txt')
which expects as java File. I get the following error:

TypeError: expected [java.io.File]; got: [org.jruby.RubyFile]; error: argument type mismatch

Would it be possible to do an automatic conversion here?

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • Work Log
  • History
  • Activity
Hide
Permalink
Thomas E Enebo added a comment - 25/Mar/08 10:17 AM

We have been talking about a conversion method (for consideration in later releases) toJava() and toJava(Class class) [in Java] which can pass underlying Java lightweight. With this method we can very quickly do Ruby->Java conversion and in the case of toJava(Class) it will make it possible to do:

io.toJava(java.io.File)
io.toJava(java.io.InputStream)
...

This will all happen under the covers and will magically work in our Java integration layer. So if you pass a Ruby file to something which expects a Java File it will end up calling toJava(java.io.File) on it. This is being considered as just a piece of some major work which will be happening in Java Integreation during our next major development cycle.

Show
Thomas E Enebo added a comment - 25/Mar/08 10:17 AM We have been talking about a conversion method (for consideration in later releases) toJava() and toJava(Class class) [in Java] which can pass underlying Java lightweight. With this method we can very quickly do Ruby->Java conversion and in the case of toJava(Class) it will make it possible to do:
io.toJava(java.io.File)
io.toJava(java.io.InputStream)
...
This will all happen under the covers and will magically work in our Java integration layer. So if you pass a Ruby file to something which expects a Java File it will end up calling toJava(java.io.File) on it. This is being considered as just a piece of some major work which will be happening in Java Integreation during our next major development cycle.
Hide
Permalink
LeonB added a comment - 25/Mar/08 10:39 AM

Thanks Thomas. Will wait for it then.

Show
LeonB added a comment - 25/Mar/08 10:39 AM Thanks Thomas. Will wait for it then.
Hide
Permalink
Charles Oliver Nutter added a comment - 12/Feb/09 10:43 PM

Resolving as wontfix...

The problem here is that Ruby's File is actually an open file stream/channel and Java's File is just a path abstraction. Coercing Ruby's File to Java's File would be misleading, and could cause people to create Ruby File objects to call Java APIs. I would suggest you use the following simple code to create an actual Java File. You can also encapsulate this in a method on Ruby's File, if you like:

java_file = java.io.File.new(ruby_file.path)
Show
Charles Oliver Nutter added a comment - 12/Feb/09 10:43 PM Resolving as wontfix... The problem here is that Ruby's File is actually an open file stream/channel and Java's File is just a path abstraction. Coercing Ruby's File to Java's File would be misleading, and could cause people to create Ruby File objects to call Java APIs. I would suggest you use the following simple code to create an actual Java File. You can also encapsulate this in a method on Ruby's File, if you like:
java_file = java.io.File.new(ruby_file.path)

People

  • Assignee:
    Charles Oliver Nutter
    Reporter:
    LeonB
Vote (0)
Watch (2)

Dates

  • Created:
    24/Mar/08 3:52 PM
    Updated:
    27/Oct/09 1:48 PM
    Resolved:
    12/Feb/09 10:43 PM
  • Atlassian JIRA (v5.0.4#731-sha1:3aa7374)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.