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

fix buggy Java version check in Scaladoc tool #8904

Merged
merged 1 commit into from Apr 22, 2020

Conversation

SethTisue
Copy link
Member

@SethTisue SethTisue commented Apr 21, 2020

this is a post-2.13.1 regression, due to #8663

the bug was that the Java version might be e.g. "14", with
no . character at all, causing StringIndexOutOfBoundsException

this was caught by the Scala community build

@scala-jenkins scala-jenkins added this to the 2.13.3 milestone Apr 21, 2020
@SethTisue SethTisue modified the milestones: 2.13.3, 2.13.2 Apr 21, 2020
@SethTisue SethTisue added the prio:blocker release blocker (used only by core team, only near release time) label Apr 21, 2020
@som-snytt
Copy link
Contributor

We have the hardened ScalaVersion which is also used for Java versions.

@SethTisue SethTisue marked this pull request as draft April 21, 2020 18:48
@SethTisue
Copy link
Member Author

SethTisue commented Apr 21, 2020

We have the hardened ScalaVersion which is also used for Java versions

Interesting, thank you, I was not aware.

It chokes on the underscores in some java.version strings, but (come to think of it) it's actually more appropriate to use java.specification.version, and ScalaVersion indeed handled the ones I tested it on.

The reuse is tempting, but in this context I think I'm a bit more comfortable going with the following (IMO) maximally robust code:

  lazy val javaVersion: Int =
    System.getProperty("java.specification.version").split('.').take(2).map(_.toIntOption) match {
      case Array(Some(1), Some(n)) => n   // example: 1.8.0_242
      case Array(Some(n))          => n   // example: 14
      case Array(Some(n), _)       => n   // example: 11.0.7
      case _                       => 8   // shrug!
    }

I want to get this merged so I can re-run the CB and get 2.13.2 out, but I'd be fine with further revisions.

this is a post-2.13.1 regression, due to scala#8663

the bug was that the Java version might be e.g. "14", with
no . characters at all, causing StringIndexOutOfBoundsException

this was caught by the Scala community build
@som-snytt
Copy link
Contributor

Jason said somewhere once he reused it for Java versions. I guess I can grep for it. I had touched ScalaVersion, and I also remember a laborious thing about soc wanting version checking to have no dependencies (in particular, no regex).

@SethTisue SethTisue marked this pull request as ready for review April 21, 2020 23:54
@som-snytt
Copy link
Contributor

Oh, it was "just a test":

./src/partest/scala/tools/partest/DirectTest.scala:  // the "ScalaVersion" class parses Java specification versions just fine
./src/partest/scala/tools/partest/DirectTest.scala:  val requiredJavaVersion = ScalaVersion(version)
./src/partest/scala/tools/partest/DirectTest.scala:  val executingJavaVersion = ScalaVersion(javaVersion)

@SethTisue
Copy link
Member Author

god forbid that System.getProperty("java.specification.version") returns null when running in some weird JVM embedded in your Dustbuster or something like that

System.getProperty("java.specification.version").split('.').take(2).map(_.toIntOption) match {
case Array(Some(1), Some(n)) => n // example: 1.8.0_242
case Array(Some(n)) => n // example: 14
case Array(Some(n), _) => n // example: 11.0.7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

case Array(Some(v), _*) => v for both cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 cleverness, -1 readability

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*_*)

(if (version.startsWith("1.")) {
version.substring(2, 3)
lazy val javaVersion: Int =
System.getProperty("java.specification.version").split('.').take(2).map(_.toIntOption) match {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.split('.') is augmentString, split("\\.") is java which notices it's a split on literal char, not a pattern. Just to footnote, as I always have to look it up.

Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL 8 is the new shrug emoji.

@som-snytt
Copy link
Contributor

Oh, soc was about util.Properties. You could count from 8 [shrug] until isJavaAtLeast(version: Int) is falsified! That tests javaSpecVersion.

@SethTisue
Copy link
Member Author

de-duplicating this with isJavaAtLeast would be a great cleanup for..... somebody

@som-snytt
Copy link
Contributor

The big S on my chest stands for ... Somebody.

@SethTisue
Copy link
Member Author

SethTisue commented Apr 22, 2020

somebody sombody <-- geez, how'd I miss this pun opportunity. I must be slipping

@som-snytt
Copy link
Contributor

I was literally in the middle of editing my strike-thru.

@SethTisue
Copy link
Member Author

we're here all night or until CI is green, whichever comes first

@som-snytt
Copy link
Contributor

re-run the CB

Ten-four, looks like we got us a convoy.

@SethTisue SethTisue merged commit d69a1ef into scala:2.13.x Apr 22, 2020
@SethTisue SethTisue deleted the scaladoc-regression branch April 22, 2020 00:46
@SethTisue SethTisue removed the prio:blocker release blocker (used only by core team, only near release time) label Apr 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants