You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 -
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:-1: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:-1: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:-1: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:
defget_address_family(addrinfo)# jruby handles this wrong, so map it by handfamily=addrinfo[0][0]family=Socket::AF_INETiffamily == 'AF_INET'family=Socket::AF_INET6iffamily == 'AF_INET6'familyend
The text was updated successfully, but these errors were encountered:
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 -
jruby/core/src/main/java/org/jruby/ext/socket/SocketUtils.java
Line 540 in e86a6b5
you have:
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
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:in
valueOf'from SocketUtils.java:540:in
addressFamilyFromArg' from RubySocket.java:418:in
initDomain'from RubySocket.java:337:in
initFieldsFromArgs' from RubySocket.java:188:in
initialize19'from RubySocket$INVOKER$i$initialize19.gen:-1:in
call' from JavaMethod.java:1056:in
call'from JavaMethod.java:677:in
call' from CachingCallSite.java:286:in
cacheAndCall'from CachingCallSite.java:81:in
callBlock' from CachingCallSite.java:85:in
call'from RubyClass.java:825:in
newInstance' from RubyIO.java:852:in
newInstance'from RubyIO$INVOKER$s$0$0$newInstance.gen:-1:in
call' from DynamicMethod.java:226:in
call'from DynamicMethod.java:222:in
call' from MethodHandle.java:636:in
invokeWithArguments'from InvocationLinker.java:191:in
invocationFallback' from bug_af_af_inet.rb:5:in
file'from bug_af_af_inet.rb:-1:in
load' from Ruby.java:811:in
runScript'from Ruby.java:804:in
runScript' from Ruby.java:673:in
runNormally'from Ruby.java:522:in
runFromMain' from Main.java:395:in
doRunFromMain'from Main.java:290:in
internalRun' from Main.java:217:in
run'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:
The text was updated successfully, but these errors were encountered: