Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider rename StringOps#lines. conflict jdk11 java.lang.String#lines #11125

Closed
xuwei-k opened this issue Sep 1, 2018 · 15 comments
Closed

consider rename StringOps#lines. conflict jdk11 java.lang.String#lines #11125

xuwei-k opened this issue Sep 1, 2018 · 15 comments

Comments

@xuwei-k
Copy link

xuwei-k commented Sep 1, 2018

screen shot 2018-09-01 at 10 53 02

Welcome to Scala 2.13.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181).
Type in expressions for evaluation. Or try :help.

scala> "a".lines
res0: Iterator[String] = <iterator>
Welcome to Scala 2.13.0-M5 (Java HotSpot(TM) 64-Bit Server VM, Java 11-ea).
Type in expressions for evaluation. Or try :help.

scala> "a".lines
res0: java.util.stream.Stream[String] = java.util.stream.ReferencePipeline$Head@4730e0f0
@SethTisue SethTisue added this to the 2.13.0-RC1 milestone Sep 1, 2018
@NthPortal
Copy link

what should it be replaced with? linesIterator? getLines (not in favour of this one myself)? iterateLines?

@lyricallogical
Copy link

Even if we change lines' signature, the risk still exists that the same problem will happen.
For solving it, we should add a method like ops for converting explicitly to StringOps.

@dwijnand
Copy link
Member

dwijnand commented Sep 1, 2018

Everyone wants to define lines on String - we've been here before: #5994 😄

@retronym
Copy link
Member

In scala/scala-dev#557, I suggested to restore linesIterator as an alias for lines. People using that can cross build between 2.12 and 2.13.

https://github.com/retronym/scala/tree/topic/linesIterator

WDYT?

@retronym
Copy link
Member

Marking as a blocker as it can't be done in a minor release.

@SethTisue SethTisue modified the milestones: 2.13.0-RC1, 2.12.7 Sep 10, 2018
@xuwei-k
Copy link
Author

xuwei-k commented Sep 15, 2018

@adriaanm adriaanm modified the milestones: 2.12.7, 2.13.0-RC1 Sep 18, 2018
@SethTisue
Copy link
Member

.linesIterator cross-compiles, but gives a deprecation warning. a workaround that cross-compiles but involves nothing deprecated is .linesWithSeparators.map(_.stripLineEnd). (I know: yuck.)

@retronym
Copy link
Member

A workaround, for those who don't need to use new parts of the Java standard library, is to use scalac -release 8.

$ java -version; scalac-launch 2.12.6 sandbox/test.scala; scalac-launch 2.12.6 -release 8 -Xprint:typer sandbox/test.scala
java version "11-ea" 2018-09-25
Java(TM) SE Runtime Environment 18.9 (build 11-ea+15)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11-ea+15, mixed mode)
sandbox/test.scala:2: error: value toList is not a member of java.util.stream.Stream[String]
  "".lines.toList
           ^
one error found
[[syntax trees at end of                     typer]] // test.scala
package <empty> {
  class C extends scala.AnyRef {
    def <init>(): C = {
      C.super.<init>();
      ()
    };
    scala.Predef.augmentString("").lines.toList
  }
}

I still 👍 for undeprecating linesIterator.

@SethTisue
Copy link
Member

SethTisue commented Sep 20, 2018

(in the workaround ugliness-level sweepstakes, adding Predef.augmentString(...) beats mine on fewer characters, but loses on not being insertable in the middle of a chain of method calls)

@adriaanm
Copy link
Contributor

adriaanm commented Sep 20, 2018

un-deprecating linesIterator in scala/scala#7240, which we'll include in 2.12.7

@SethTisue
Copy link
Member

SethTisue commented Sep 20, 2018

note that it isn't safe to rely on the compiler to catch bad uses of .lines, you want to search your source code and find all of them

yes, often the compiler will catch it, e.g. s.lines.toVector fails to compile because Java's Stream doesn't have toVector

but more devious is something like s.lines.filter(...) == .... Java's Stream has filter, and == isn't type-safe, so if you're lucky you'll get a "are unrelated: they will most likely never compare equal" warning ... if you're lucky... and if you're lucky enough to spot the warning in your code's big pile of warnings it already generates that you tune out now...

I guess a Scalafix rewrite could help here, and wouldn't have false positives if you are using .lines method on something other than a String

SethTisue added a commit to SethTisue/scala-java8-compat that referenced this issue Sep 20, 2018
this incurs a deprecation warning on 2.12.6, but we don't have
fatal warnings enabled in this repo. the deprecation warnings
will go away once we start building on 2.12.7.
SethTisue added a commit to scala/scala-java8-compat that referenced this issue Sep 21, 2018
SethTisue added a commit to SethTisue/utest that referenced this issue Sep 21, 2018
this incurs a deprecation warning on 2.12.6, but fatal warnings aren't
enabled in this repo. the deprecation warnings will go away once the
build moves to 2.12.7, which will undeprecate linesIterator
@SethTisue
Copy link
Member

gah, we removed .linesIterator entirely from 2.13. so .linesIterator won't become a cross-buildable alternative until we bring it back in 2.13.0-RC1 😢

it's okay though, Predef.augmentString(...).lines is fine. I'm just annoyed that I forgot about the removal in 2.13.

SethTisue added a commit to SethTisue/utest that referenced this issue Sep 21, 2018
this incurs a deprecation warning on 2.12.6, but fatal warnings aren't
enabled in this repo. the deprecation warnings will go away once the
build moves to 2.12.7, which will undeprecate linesIterator
isomarcte added a commit to isomarcte/metals that referenced this issue Dec 4, 2019
In JDK11 a method on `String` was added named `lines` which returned a `java.util.stream.Stream`. This collided with the enrichment method from Scala's `StringOps` class by the same name which returned an `Iterator`. The result, for metals, is that it was not possible to build metals using JDK11 or greater.

This commit uses the new enrichment method `linesIterator` which was added to the Scala standard library as a replacement. This now enables metals to compile on JDK11.

See: scala/bug#11125
esamson added a commit to esamson/sbt-header that referenced this issue Apr 6, 2020
hseeberger pushed a commit to sbt/sbt-header that referenced this issue Apr 7, 2020
rtyley added a commit to rtyley/bfg-repo-cleaner that referenced this issue Dec 15, 2020
basinilya added a commit to basinilya/otroslogviewer that referenced this issue Sep 13, 2021
basinilya added a commit to basinilya/otroslogviewer that referenced this issue Sep 13, 2021
basinilya added a commit to basinilya/otroslogviewer that referenced this issue Sep 13, 2021
otrebski pushed a commit to otros-systems/otroslogviewer that referenced this issue Jan 17, 2022
JoPintoPaul added a commit to hmrc/play-frontend-govuk-examples that referenced this issue Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants