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 `valueOf': java.lang.IllegalArgumentException: No enum constant jnr.constants.platform.AddressFamily.AF_AF_INET #1618

francis opened this issue Apr 10, 2014 · 0 comments


Copy link

@francis francis commented Apr 10, 2014

For jruby 1.7.11 running either on my iMac or Windows box, I get an illegal constant trying to lookup 'AF_INET' when calling Looking at the code, on line 540 of -

addressFamily = AddressFamily.valueOf("AF_" + domainString);

you have:

    addressFamily = AddressFamily.valueOf("AF_" + domainString);

Apparently, that extra AF_ is not needed if it already starts with AF_?

Here is a small text program that shows this problem:
jruby-1.7.11:~ $ cat bug_af_af_inet.rb

require 'socket'
addrinfo = Socket.getaddrinfo('localhost', 22)
family = addrinfo[0][0] # this is the string 'AF_INET' or 'AF_INET6'
socket =, Socket::SOCK_STREAM, 0)

jruby-1.7.11:~ $ ruby bug_af_af_inet.rb valueOf': java.lang.IllegalArgumentException: No enum constant jnr.constants.platform.AddressFamily.AF_AF_INET from'
from addressFamilyFromArg' from'
from initFieldsFromArgs' from'
from RubySocket$INVOKER$i$initialize19.gen👎in call' from'
from call' from'
from callBlock' from'
from newInstance' from'
from RubyIO$INVOKER$s$0$0$newInstance.gen👎in call' from'
from call' from'
from invocationFallback' from bug_af_af_inet.rb:5:infile'
from bug_af_af_inet.rb👎in load' from'
from runScript' from'
from runFromMain' from'
from internalRun' from'
from `main'

Switching back to MRI, you don't see this behavior:
jruby-1.7.11:~ $ rvm use ruby
ruby-2.1.1:~ $ ruby bug_af_af_inet.rb
ruby-2.1.1:~ $

A workaround is to map the constant yourself:

def get_address_family(addrinfo)
  # jruby handles this wrong, so map it by hand
  family = addrinfo[0][0]
  family = Socket::AF_INET if family == 'AF_INET'
  family = Socket::AF_INET6 if family == 'AF_INET6'
@enebo enebo closed this in e80982d Apr 10, 2014
enebo added a commit that referenced this issue Apr 10, 2014
@enebo enebo added this to the JRuby 1.7.12 milestone Apr 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants