Skip to content

Conversation

@som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Jul 13, 2016

The utility method compares javaSpecVersion, which has the
form "1.8" previously and "9" going forward.

The method accepts "1.n" for n < 9. More correctly, the string
argument should be a single number.

Supports JEP-223.

Supersedes #5270

Review by @golem131

This supposes golem was annoyed by our preciousness.

The utility method compares javaSpecVersion, which has the
form "1.8" previously and "9" going forward.

The method accepts "1.n" for n < 9. More correctly, the string
argument should be a single number.

Supports JEP-223.
def versionOf(s: String): Int = s.indexOf('.') match {
case 1 if s.charAt(0) == '1' =>
val v = versionOf(s.substring(2))
if (v < 9) v else -1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably didn't intend to accept 1.1.8.

Leaves the error string as is, but adds test to show how it looks.
Java calls it a version number. `Not a version: 1.9`.

Don't strip `1.` prefix recursively. (That was Snytt's fault.)
A good opportunity to simplify the API. Versions are strings,
but a spec version is just a number.
val i = x.indexOf('.')
if (i < 0) throw new NumberFormatException("Not a version: " + x)
(x.substring(0, i), x.substring(i+1, x.length))
def versionOf(s: String): Int = s.indexOf('.') match {
Copy link
Contributor

Choose a reason for hiding this comment

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

JEP223 specify that the system property java.specification.version is a $VNUM and $VNUMs satisfy the regular expression: ^[1-9][0-9]*(((\.0)*\.[1-9][0-9]*)*)*$. This code doesn't look ready to pick the major version from all strings satisfying that regular expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@varming You're right, it does say $VNUM. I was fooled by the table of examples where the spec is $MAJOR? Is the spec $MAJOR in practice? I think it can't hurt to accept leading "1." and then ignore suffix of ".anything". The doc should say the arg must be the $MAJOR, if that is the desired behavior. Certainly previous usage has been just to distinguish major versions of the platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, re-reading what they intend by $MINOR, which includes revision of API, it's possible this API should support $MAJOR.$MINOR. I know I care if we're on java 8 or 9, but will I care if it is 9.1 or 9.2? assuming the spec string is 9.1. Alternatively, maybe supply isJavaMajorSpec for platforms that don't want to use regex for this test; otherwise just use regex like normal people.

Copy link
Contributor

Choose a reason for hiding this comment

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

Dear @som-snytt,

I don't know if there will be a time where $minor, $security, and later parts of the $VNUM will be important, but I would expect the code to work with all $VNUMs. In most settings you probably want to support $major, $minor, and $security. Having special functions to check that the major is at least greater than some integer seems like a good idea.

Right now the code handles backwards compatibility with <= JDK8, but it cannot handle JDK10. It would be nice if it handled backwards compatibility separately from general $VNUMs and let backwards compatibility take precedence. It doesn't look like you need full regular expressions to parse a $VNUM, simply take all characters up to the next dot (or the end of the string if there is no more dots) and parse them as an integer, and repeat this until you can decide the version question.

Don't assume spec is just major, but allow arbitrary version
number for both spec value and user value to check.

Only the first three dot-separated fields are considered,
after skipping optional leading value "1" in legacy format.

Minimal validity checks of user arg are applied. Leading three
fields, if present, must be number values, but subsequent
fields are ignored.

Note that a version number is not a version string, which
optionally includes pre and build info, `9-ea+109`.
@som-snytt
Copy link
Contributor Author

By coincidence, there's a performance regression on start-up in JDK-9 that has to do with loading regex classes, fixed by checking if the version is just a major number. The call for review.

After the nuclear apocalypse, the only things left will be cockroaches and programs that do s.indexOf('.').

@adriaanm adriaanm modified the milestone: 2.12.1 Jul 26, 2016
@retronym
Copy link
Member

Looks like we can actually remove the only use of this method from our own code. Would you mind doing that too? We know statically that isJavaAtLeast("1.7") is true.

val suppressable = isJavaAtLeast("1.7")
...
      if (suppressable) {
        import scala.language.reflectiveCalls
        type Suppressing = { def getSuppressed(): Array[Throwable] }
        for (s <- e.asInstanceOf[Suppressing].getSuppressed) print(s, Suppressed, frames, indents + 1)
      }

Formatting suppressed exceptions required reflection for platform
compatibility. No longer, since Java 8 is assumed. Minor tidying.
@som-snytt
Copy link
Contributor Author

Sure thing, it gave me something to do while babysitting my second Windows 10 upgrade this week, with a few hours to spare.

I only wish that guy would comment his code. Frankly, I never want to touch his code ever again. I don't see how anyone puts up with it.

Technically, isJavaAtLeast(Int) still calls isJavaAtLeast(String).

@SethTisue
Copy link
Member

shouldn't this target 2.11.x?

@som-snytt
Copy link
Contributor Author

@SethTisue Too risky!

@SethTisue SethTisue self-assigned this Aug 9, 2016
@retronym
Copy link
Member

retronym commented Sep 8, 2016

LGTM. I think we can get target Java 9 support to the 2.12.1+, and then backport to 2.11.x once some problems are shaken out.

@SethTisue SethTisue merged commit 92db1dc into scala:2.12.x Oct 26, 2016
@som-snytt som-snytt deleted the issue/9750 branch October 26, 2016 18:54
smarter added a commit to dotty-staging/dotty that referenced this pull request Sep 17, 2017
The dotty implementation of Properties.isJavaAtLeast is broken for Java
9 (Fixed in Scalac at scala/scala#5276, but
maybe we just shouldn't have a copy of Properties.scala in Dotty). The
test is useless now anyway since we only compile with 2.12 which
requires Java 8, so this code is never going to run on an older version
of the JVM.
smarter added a commit to dotty-staging/dotty that referenced this pull request Oct 12, 2017
The dotty implementation of Properties.isJavaAtLeast is broken for Java
9 (Fixed in Scalac at scala/scala#5276, but
maybe we just shouldn't have a copy of Properties.scala in Dotty). The
test is useless now anyway since we only compile with 2.12 which
requires Java 8, so this code is never going to run on an older version
of the JVM.
smarter added a commit to dotty-staging/dotty that referenced this pull request Aug 23, 2018
The dotty implementation of Properties.isJavaAtLeast is broken for Java
9 (Fixed in Scalac at scala/scala#5276, but
maybe we just shouldn't have a copy of Properties.scala in Dotty). The
test is useless now anyway since we only compile with 2.12 which
requires Java 8, so this code is never going to run on an older version
of the JVM.
smarter added a commit to dotty-staging/dotty that referenced this pull request Aug 25, 2018
The dotty implementation of Properties.isJavaAtLeast is broken for Java
9 (Fixed in Scalac at scala/scala#5276, but
maybe we just shouldn't have a copy of Properties.scala in Dotty). The
test is useless now anyway since we only compile with 2.12 which
requires Java 8, so this code is never going to run on an older version
of the JVM.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants