Bridge methods

113 views
Skip to first unread message

Robert Voyer

unread,
Jan 5, 2012, 2:15:44 PM1/5/12
to scala-l...@googlegroups.com
Hi all,

My company ran into a pretty serious issue yesterday in the process of trying to migrate our stack from Scala 2.8.1 to 2.9.1. We are in the (unfortunate) situation of still being heavily reliant on Jersey for web services. We were also making heavy use of traits in our REST resources for modularizing shared behavior. Yesterday, we discovered that methods defined in traits are treated as bridge methods in concrete classes that mix them in. Jersey ignores bridge methods when collecting a resource's methods. This is a serious problem for us. What's the motivation for this new behavior in Scala 2.9.1?

Here's a snippet from a 2.9.1 REPL transcript to illustrate the behavior:

scala> trait Base { def getFoo(): String = "foo" }
defined trait Base

scala> class Sub extends Base { def getBar(): String = "bar" }
defined class Sub

scala> classOf[Sub].getDeclaredMethods
res19: Array[java.lang.reflect.Method] = Array(public java.lang.String Sub.getFoo(), public java.lang.String Sub.getBar())

scala> classOf[Sub].getDeclaredMethods()(0).isBridge
res20: Boolean = true

scala> classOf[Sub].getDeclaredMethods()(1).isBridge
res21: Boolean = false

Are there any recommended work-arounds?

Thanks,
Robert

Paul Phillips

unread,
Jan 5, 2012, 2:52:55 PM1/5/12
to scala-l...@googlegroups.com


On Thu, Jan 5, 2012 at 11:15 AM, Robert Voyer <robert...@gmail.com> wrote:
This is a serious problem for us. What's the motivation for this new behavior in Scala 2.9.1?

It emerged from the generic signature fracas, something I can't remember well involving signature conflicts which arose during mixin after we had to generate less precise signatures due to the primitives issue.  It does not seem desirable and as far as I can tell at this moment it is not necessary.  I'm running the tests to see if we at least have one in place which will give me a concrete reason.  If we don't, then unless martin chimes in I think we can reverse it for 2.10.

Paul Phillips

unread,
Jan 5, 2012, 3:09:05 PM1/5/12
to scala-l...@googlegroups.com
OK, I didn't find any contraindications so I fixed it in trunk and the 2.9.x branch.

Robert Voyer

unread,
Jan 5, 2012, 3:14:32 PM1/5/12
to scala-l...@googlegroups.com
Thanks, Paul. Two questions: can you point me to the corresponding fix? I'd be interested to see what was required. Secondly, do you have any idea when we might expect to see another 2.9.x release?

Paul Phillips

unread,
Jan 5, 2012, 3:22:57 PM1/5/12
to scala-l...@googlegroups.com
On Thu, Jan 5, 2012 at 12:14 PM, Robert Voyer <robert...@gmail.com> wrote:
Thanks, Paul. Two questions: can you point me to the corresponding fix? I'd be interested to see what was required. Secondly, do you have any idea when we might expect to see another 2.9.x release?


And, I'm afraid I don't know regarding 2.9.x.

Reply all
Reply to author
Forward
0 new messages