-
Notifications
You must be signed in to change notification settings - Fork 3.1k
SI-9750 scala.util.Properties.isJavaAtLeast will not work with JDK9 #5270
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
Conversation
golem131
commented
Jul 8, 2016
- Support JEP-223
- Tests update
* Support JEP-223 * Tests update
|
I have signed the Scala CLA, but check not changed ( |
|
/synch |
|
That's a lot of infrastructure just to compare a number. Also, it leaks details. Last time, @soc objected to regex, with the idea that this check should be absolutely minimal (and not require dependencies). I'd suggest keeping the current code and just strip the optional "1." prefix, perhaps complaining if the suffix is not in "0-8". |
|
|
||
|
|
||
| object JavaSpecVersionBefore9 { | ||
| val pattern = "1.([5-8])"r |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
postfix is warnable.
|
Can't this whole thing just be def javaVersion(s: String) = s.split("\\.")(if (s.startsWith("1.")) 1 else 0).toIntThere admittedly isn't much error checking here, but do we need any more logic than that? |
|
I was going to say |
|
Are we playing the no-regex but yes-StringOps-extensions game? Okay. def javaVersion(s: String) = s.stripPrefix("1.").takeWhile(_ != '.').toIntCan use |
|
I noticed a second ago that in fact, last time, we said no extensions either, so, jinx. I think @soc plays with other platforms where he has to boot in 16KB of ram. |
|
@Ichoran the problem of your recommended decision is not in Java System API, but in user input. |
|
@golem131 - |
|
@Ichoran - Ok, ok. So, what decision? We try to create fastest version, simplest version, correct version (more secure checks, more custom exceptions etc.), or we say, that "version string" is not just sequence of numbers, and may be more complex ("9-ea+73" or "9.1.2+62" for example)? Forgot to say, that we have sbt-nsa sbt plugin (https://github.com/mentat-labs/sbt-nsa) with type safe versions and compiler options. Do you think this plugin have wrong basic idea? |
|
For libraries that want to extract all the information available in a version string you have different requirements than a routine that merely needs to tell "is this 9 or is this 8". Realistically, it should handle all the examples in http://openjdk.java.net/jeps/223 which means it can't stop on For instance, getting the major version number with this code would, I think, be enough, though it could be rewritten with while loops and such if we wanted to make it easier for Proguard and the like to chop out as much as possible: // Java version string old format is 1.x.stuff
// Java version string new format is x[.-+u]stuff
// This handles both (and admits mixtures of the two)
def javaVersion(s: String): Int =
try { s.stripPrefix("1.").takeWhile(c => !(".-+u" contains c.toString)).toInt }
catch { case nfe: NumberFormatException =>
throw new NumberFormatException("Could not locate major Java version number in " + s)
}Then all the rest of the logic can be done with just an |
|
@Ichoran ok, no problem, i'll fix my PR after weekend. |
|
For reference, a while loop version would look something like this: def javaVersion(s: String): Int =
try {
val i = if (s startsWith "1.") 2 else 0
var j = i
while (j < s.length && !(".-+u" contains s.substring(j, j+1))) j += 1
s.substring(i, j).toInt
}
catch { case nfe: NumberFormatException =>
throw new NumberFormatException("Could not locate major Java version number in " + s)
} |
|
@som-snytt then what's your choice? |
|
I would stick with spec version tests. Fix the Scaladoc if it says different. That's all it used to do: It ought to have been, Moral equivalent, Also, I just re-remembered that |
|
superseded by #5276 |