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

Enum.java:238:in `valueOf': java.lang.IllegalArgumentException: No enum constant jnr.constants.platform.AddressFamily.AF_AF_INET #1618

Closed
francis opened this Issue Apr 10, 2014 · 0 comments

Comments

Projects
None yet
2 participants
@francis
Copy link

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 Socket.new. Looking at the code, on line 540 of SocketUtils.java -

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.new(family, Socket::SOCK_STREAM, 0)
socket.close

jruby-1.7.11:~ $ ruby bug_af_af_inet.rb
Enum.java:238:in valueOf': java.lang.IllegalArgumentException: No enum constant jnr.constants.platform.AddressFamily.AF_AF_INET from AddressFamily.java:4:invalueOf'
from SocketUtils.java:540:in addressFamilyFromArg' from RubySocket.java:418:ininitDomain'
from RubySocket.java:337:in initFieldsFromArgs' from RubySocket.java:188:ininitialize19'
from RubySocket$INVOKER$i$initialize19.gen👎in call' from JavaMethod.java:1056:incall'
from JavaMethod.java:677:in call' from CachingCallSite.java:286:incacheAndCall'
from CachingCallSite.java:81:in callBlock' from CachingCallSite.java:85:incall'
from RubyClass.java:825:in newInstance' from RubyIO.java:852:innewInstance'
from RubyIO$INVOKER$s$0$0$newInstance.gen👎in call' from DynamicMethod.java:226:incall'
from DynamicMethod.java:222:in call' from MethodHandle.java:636:ininvokeWithArguments'
from InvocationLinker.java:191:in invocationFallback' from bug_af_af_inet.rb:5:infile'
from bug_af_af_inet.rb👎in load' from Ruby.java:811:inrunScript'
from Ruby.java:804:in runScript' from Ruby.java:673:inrunNormally'
from Ruby.java:522:in runFromMain' from Main.java:395:indoRunFromMain'
from Main.java:290:in internalRun' from Main.java:217:inrun'
from Main.java:197:in `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'
  family
end

@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
You can’t perform that action at this time.