This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Bridge methods

4 replies
rlvoyer
Joined: 2011-09-15,
User offline. Last seen 1 year 4 weeks ago.

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

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Bridge methods


On Thu, Jan 5, 2012 at 11:15 AM, Robert Voyer <robert [dot] voyer [at] gmail [dot] 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.
extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Bridge methods

OK, I didn't find any contraindications so I fixed it in trunk and the 2.9.x branch.

rlvoyer
Joined: 2011-09-15,
User offline. Last seen 1 year 4 weeks ago.
Re: Bridge methods

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?

On Jan 5, 2012, at 12:09 PM, Paul Phillips wrote:

> OK, I didn't find any contraindications so I fixed it in trunk and the 2.9.x branch.

extempore
Joined: 2008-12-17,
User offline. Last seen 35 weeks 3 days ago.
Re: Bridge methods


On Thu, Jan 5, 2012 at 12:14 PM, Robert Voyer <robert [dot] voyer [at] gmail [dot] 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?

https://github.com/scala/scala/commit/fe94bc7a14
And, I'm afraid I don't know regarding 2.9.x.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland