Problems reading Java Hashtables from Jruby 1.3.1

View: New views
4 Messages — Rating Filter:   Alert me  

Problems reading Java Hashtables from Jruby 1.3.1

by Guillermo Acilu-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Problems reading Java Hashtables from Jruby 1.3.1 Hello guys,

I am having a big problem and it looks like a bug in jruby.

I have two java hash tables: hash1 and hash2. Both hashes have the same key but different data. Both hashes are generated in Java classes executed from Ruby code. Then I need to read a process both hashes within the ruby code, so I do the following:

hash1.each { |key, data|
   puts hash2
    puts hash2[key]
}

All the first puts print the complete list of key/value pairs without any problems. The second line is NIL. Why?

Thanks in advance,

GA

Re: Problems reading Java Hashtables from Jruby 1.3.1

by Nick Sieger-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jun 23, 2009 at 2:24 AM, Guillermo Acilu <x2jruby@...> wrote:
Hello guys,

I am having a big problem and it looks like a bug in jruby.

I have two java hash tables: hash1 and hash2. Both hashes have the same key but different data. Both hashes are generated in Java classes executed from Ruby code. Then I need to read a process both hashes within the ruby code, so I do the following:

hash1.each { |key, data|
   puts hash2
    puts hash2[key]
}

All the first puts print the complete list of key/value pairs without any problems. The second line is NIL. Why?

It sounds like a bug to me too. If you could make a small reproduction with a simple Java class and a Ruby script and attach to a JIRA, that would great!

http://jira.codehaus.org/browse/JRUBY

/Nick


Re: Problems reading Java Hashtables from Jruby 1.3.1

by Michael Campbell-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Nick Sieger wrote:

> On Tue, Jun 23, 2009 at 2:24 AM, Guillermo Acilu <x2jruby@...
> <mailto:x2jruby@...>> wrote:
>
>     Hello guys,
>
>     I am having a big problem and it looks like a bug in jruby.
>
>     I have two java hash tables: hash1 and hash2. Both hashes have the
>     same key but different data. Both hashes are generated in Java
>     classes executed from Ruby code. Then I need to read a process both
>     hashes within the ruby code, so I do the following:
>
>     hash1.each { |key, data|
>        puts hash2
>         puts hash2[key]
>     }
>
>     All the first puts print the complete list of key/value pairs
>     without any problems. The second line is NIL. Why?
>
>
> It sounds like a bug to me too. If you could make a small reproduction
> with a simple Java class and a Ruby script and attach to a JIRA, that
> would great!


Make sure also you're seeing what you THINK you're seeing. "puts" can be deceiving.


 > ruby -e 'a = {"6", 10}; b = {6, 10}; puts a; puts b; p a; p b'
610
610
{"6"=>10}
{6=>10}


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Problems reading Java Hashtables from Jruby 1.3.1

by Charles Oliver Nutter-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Tue, Jun 23, 2009 at 2:24 AM, Guillermo Acilu<x2jruby@...> wrote:

> I have two java hash tables: hash1 and hash2. Both hashes have the same key
> but different data. Both hashes are generated in Java classes executed from
> Ruby code. Then I need to read a process both hashes within the ruby code,
> so I do the following:
>
> hash1.each { |key, data|
>    puts hash2
>     puts hash2[key]
> }
>
> All the first puts print the complete list of key/value pairs without any
> problems. The second line is NIL. Why?

1. Does the key requested in the second puts line exist in the target
hash? (I assume you checked this)
2. Are the keys in the hash something other than strings? If they're
symbols in Ruby or something that toString's to a normal looking
string, you may not be getting the right result. Check puts key.class

- Charlie

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email