Skip to content

Enum#valueOf thread safety issue #2014

@pierre

Description

@pierre

The following snippet sometimes throws ArgumentError: wrong number of arguments (1 for 2):

threads = (0..5).map do
  Thread.new { Java::java.util.concurrent.TimeUnit.value_of('NANOSECONDS') }
end

threads.each { |thread| thread.join }

Raw compiled trace (-Xbacktrace.style=raw):

ArgumentError: wrong number of arguments (1 for 2)
         getStackTrace at java/lang/Thread.java:1589
      getBacktraceData at org/jruby/runtime/backtrace/TraceType.java:175
          getBacktrace at org/jruby/runtime/backtrace/TraceType.java:39
      prepareBacktrace at org/jruby/RubyException.java:223
              preRaise at org/jruby/exceptions/RaiseException.java:213
              preRaise at org/jruby/exceptions/RaiseException.java:194
                <init> at org/jruby/exceptions/RaiseException.java:110
     newRaiseException at org/jruby/Ruby.java:3889
      newArgumentError at org/jruby/Ruby.java:3402
  findCallableArityOne at org/jruby/java/invokers/RubyToJavaInvoker.java:265
                  call at org/jruby/java/invokers/StaticMethodInvoker.java:56
                  call at org/jruby/internal/runtime/methods/AliasMethod.java:69
          cacheAndCall at org/jruby/runtime/callsite/CachingCallSite.java:334
                  call at org/jruby/runtime/callsite/CachingCallSite.java:185
           processCall at org/jruby/ir/interpreter/Interpreter.java:307
             interpret at org/jruby/ir/interpreter/Interpreter.java:564
       INTERPRET_BLOCK at org/jruby/ir/interpreter/Interpreter.java:659
       commonYieldPath at org/jruby/runtime/InterpretedIRBlockBody.java:50
                  call at org/jruby/runtime/IRBlockBody.java:67
                  call at org/jruby/runtime/Block.java:106
                  call at org/jruby/RubyProc.java:301
                  call at org/jruby/RubyProc.java:230
                   run at org/jruby/internal/runtime/RubyRunnable.java:99
                   run at java/lang/Thread.java:745

Adding a trace in RubyToJavaInvoker#findCallableArityOne, the looked up method is:

public static java.lang.Enum java.lang.Enum.valueOf(java.lang.Class,java.lang.String)

Tested both on JRuby 1.7.11 and 1.7.16.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions