question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding method to value class breaks binary compatibility but is not reported

See original GitHub issue

I made the following change. From

  implicit class Ops(private val s: String) extends scala.AnyVal {
    def `\\` (index: Int  ): String = s.substring(index, index + 1)
  }

to

  implicit class Ops(private val s: String) extends scala.AnyVal {
    def `\\` (index: Int  ): String = s.substring(index, index + 1)
    def `\\` (range: Range): String = range.map(s.charAt).mkString
  }

Now here are multiple things that could be involved:

  • it’s a value class (my guess)
  • it’s an overloaded method
  • it’s an implicit class

I have created a project that demonstrates the bug: https://github.com/Sciss/mima-bug-135 To reproduce:

  • git clone https://github.com/Sciss/mima-bug-135.git
  • cd mima-bug-135
  • git checkout foo-0.1.0
  • cd foo && sbt publish-local
  • cd ../bar && sbt publish-local
  • cd ../baz && sbt run

This should run without crash. Now we publish the updated version:

  • git checkout foo-0.1.1
  • cd ../foo && sbt mimaReportBinaryIssues && sbt publish-local
  • cd ../baz && sbt run

(note that Bar was compiled against foo-0.1.0; MiMa does not report any issue).

This crashes with:

error] (run-main-0) java.lang.NoSuchMethodError: de.sciss.mima.package$Ops$.$bslash$extension(Ljava/lang/String;I)Ljava/lang/String;
java.lang.NoSuchMethodError: de.sciss.mima.package$Ops$.$bslash$extension(Ljava/lang/String;I)Ljava/lang/String;
	at de.sciss.mima.Bar$.apply(Bar.scala:4)
	at de.sciss.mima.Baz$.main(Baz.scala:4)
	at de.sciss.mima.Baz.main(Baz.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dwijnandcommented, May 19, 2019

It’s not clear to me why such a change should not be binary compatible.

Fixed in 2.13.0-RC1 with https://github.com/scala/scala/pull/7896

cc also @kailuowang

0reactions
szeigercommented, Nov 21, 2016

The problem here is that any member whose decoded name contains a $ is considered non-accessible. I think the most straight-forward fix would be to exclude names that end in $extensions or that contain $extension$. It feels a bit dirty but so does excluding every name with a $ in the first place.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issue about "binary compatibility" - java - Stack Overflow
Changing methods or constructors to return values on inputs for which they previously either threw exceptions that normally should not occur.
Read more >
Types of breaking changes - .NET - Microsoft Learn
This article outlines changes that affect compatibility and the way in which the .NET team evaluates each type of change.
Read more >
Chapter 13. Binary Compatibility - Oracle Help Center
13.4.​​ Adding new methods or constructors that overload existing methods or constructors does not break compatibility with pre-existing binaries.
Read more >
Evolving Java-based APIs 2 - Eclipsepedia
(1) Adding and deleting checked exceptions declared as thrown by an API method does not break binary compatibility; however, it breaks contract ...
Read more >
clirr - Check source and binary compatibility of Java libraries
Clirr is a tool that checks Java libraries for binary and source compatibility with older releases. Basically you give it two sets of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found