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
scala>Stooges.Larry
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.Enumeration$$$$anonfun$$scala$$Enumeration$$$$nameOf$$2.apply(Enumeration.scala:176)
at scala.Enumeration$$$$anonfun$$scala$$Enumeration$$$$nameOf$$2.apply(Enumeration.scala:171)
at scala.collection.TraversableLike$$WithFilter$$$$anonfun$$foreach$$1.apply(TraversableLike.scala:1218)
at scala.collection.IndexedSeqLike$$class.foreach(IndexedSeqLike.scala:87)
at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:20)
at scala.collection.TraversableLike$$WithFilter.foreach(TraversableLike.scala:1217)
at scala.Enumeration.scala$$Enumeration$$$$nameOf(Enumeration.scala:171)
at scala.Enumeration$$Val.toString(Enumeration.scala:237)
at scala.runtime.ScalaRunTime$$.stringOf(ScalaRunTime.scala:145)
at RequestResult$$.<init>(<console>:9)
at RequestResult$$.<clinit>(<console>)
at RequestResult$$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1$$$$anonfun$$apply$$13.apply(Interpreter.scala:798)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1$$$$anonfun$$apply$$13.apply(Interpreter.scala:798)
at scala.util.control.Exception$$Catch.apply(Exception.scala:79)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1.apply(Interpreter.scala:797)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1.apply(Interpreter.scala:797)
at scala.util.control.Exception$$Catch.apply(Exception.scala:79)
at scala.tools.nsc.Interpreter$$Request.loadAndRun(Interpreter.scala:796)
at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:445)
at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:435)
at scala.tools.nsc.InterpreterLoop.interpretStartingWith(InterpreterLoop.scala:345)
at scala.tools.nsc.InterpreterLoop.command(InterpreterLoop.scala:322)
at scala.tools.nsc.InterpreterLoop.processLine...
scala>Stooges.Curly
java.lang.IllegalArgumentException: wrong number of arguments
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.Enumeration$$$$anonfun$$scala$$Enumeration$$$$nameOf$$2.apply(Enumeration.scala:176)
at scala.Enumeration$$$$anonfun$$scala$$Enumeration$$$$nameOf$$2.apply(Enumeration.scala:171)
at scala.collection.TraversableLike$$WithFilter$$$$anonfun$$foreach$$1.apply(TraversableLike.scala:1218)
at scala.collection.IndexedSeqLike$$class.foreach(IndexedSeqLike.scala:87)
at scala.collection.mutable.ArrayOps.foreach(ArrayOps.scala:20)
at scala.collection.TraversableLike$$WithFilter.foreach(TraversableLike.scala:1217)
at scala.Enumeration.scala$$Enumeration$$$$nameOf(Enumeration.scala:171)
at scala.Enumeration$$Val.toString(Enumeration.scala:237)
at scala.runtime.ScalaRunTime$$.stringOf(ScalaRunTime.scala:145)
at RequestResult$$.<init>(<console>:9)
at RequestResult$$.<clinit>(<console>)
at RequestResult$$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1$$$$anonfun$$apply$$13.apply(Interpreter.scala:798)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1$$$$anonfun$$apply$$13.apply(Interpreter.scala:798)
at scala.util.control.Exception$$Catch.apply(Exception.scala:79)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1.apply(Interpreter.scala:797)
at scala.tools.nsc.Interpreter$$Request$$$$anonfun$$loadAndRun$$1.apply(Interpreter.scala:797)
at scala.util.control.Exception$$Catch.apply(Exception.scala:79)
at scala.tools.nsc.Interpreter$$Request.loadAndRun(Interpreter.scala:796)
at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:445)
at scala.tools.nsc.Interpreter.interpret(Interpreter.scala:435)
at scala.tools.nsc.InterpreterLoop.interpretStartingWith(InterpreterLoop.scala:345)
at scala.tools.nsc.InterpreterLoop.command(InterpreterLoop.scala:322)
at scala.tools.nsc.InterpreterLoop.processLine...
scala>Stooges.Moe
res2:Stooges.Value=Moe
The Stooge which won't crash has varied in my tests with no discernible pattern I could detect. Granted, I didn't spend much time trying to detect a pattern.
The text was updated successfully, but these errors were encountered:
@harrah said:
The problem is in Enumeration.nameOf:
privatedefnameOf(i: Int):String=
[...]
valmethods= getClass.getMethods
for (m <- methods
ifclassOf[Value].isAssignableFrom(m.getReturnType) &&!java.lang.reflect.Modifier.isFinal(m.getModifiers)) {
valname= m.getName
// invoke method to obtain actual `Value` instancevalvalue= m.invoke(this)
[...]
It iterates over all methods in the Enumeration (here, Stooges), keeping only subclasses of Value. It then invokes these methods on the Enumeration instance (again, Stooges here) without any arguments. The problem is that the crashing Stooges includes an extra method that returns a subclass of Value but accepts arguments.
Fixes should be:
add && m.getParameterTypes.isEmpty to the filter
Verify that there is a field with the same name and return type as the method to ensure it is a val. Otherwise, a user-defined method might be invoked unnecessarily.
Make nameOfsynchronized since it modifies nmap, which is mutable.
This innocent code has no problems:
This still innocent code produces the weirdest stuff:
By weirdest, I mean the following:
The
Stooge
which won't crash has varied in my tests with no discernible pattern I could detect. Granted, I didn't spend much time trying to detect a pattern.The text was updated successfully, but these errors were encountered: