8194879: Runtime.Version parses string which does not conform to spec without throwing IAE
Reviewed-by: alanb, iris, rriggs
This commit is contained in:
parent
869f9e2ed0
commit
f61a078bd2
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1995, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1995, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -1099,16 +1099,23 @@ public class Runtime {
|
|||||||
m.group(VersionPattern.OPT_GROUP));
|
m.group(VersionPattern.OPT_GROUP));
|
||||||
|
|
||||||
// empty '+'
|
// empty '+'
|
||||||
if ((m.group(VersionPattern.PLUS_GROUP) != null)
|
if (!build.isPresent()) {
|
||||||
&& !build.isPresent()) {
|
if (m.group(VersionPattern.PLUS_GROUP) != null) {
|
||||||
if (optional.isPresent()) {
|
if (optional.isPresent()) {
|
||||||
if (pre.isPresent())
|
if (pre.isPresent())
|
||||||
throw new IllegalArgumentException("'+' found with"
|
throw new IllegalArgumentException("'+' found with"
|
||||||
+ " pre-release and optional components:'" + s
|
+ " pre-release and optional components:'" + s
|
||||||
+ "'");
|
+ "'");
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("'+' found with neither"
|
||||||
|
+ " build or optional components: '" + s + "'");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("'+' found with neither"
|
if (optional.isPresent() && !pre.isPresent()) {
|
||||||
+ " build or optional components: '" + s + "'");
|
throw new IllegalArgumentException("optional component"
|
||||||
|
+ " must be preceeded by a pre-release component"
|
||||||
|
+ " or '+': '" + s + "'");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new Version(List.of(version), pre, build, optional);
|
return new Version(List.of(version), pre, build, optional);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -24,7 +24,7 @@
|
|||||||
/*
|
/*
|
||||||
* @test
|
* @test
|
||||||
* @summary Unit test for java.lang.Runtime.Version
|
* @summary Unit test for java.lang.Runtime.Version
|
||||||
* @bug 8072379 8144062 8161236 8160956
|
* @bug 8072379 8144062 8161236 8160956 8194879
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.lang.Runtime.Version;
|
import java.lang.Runtime.Version;
|
||||||
@ -115,6 +115,7 @@ public class Basic {
|
|||||||
tryCatch("9-pre+-opt", IAE);
|
tryCatch("9-pre+-opt", IAE);
|
||||||
tryCatch("1.4142+-", IAE);
|
tryCatch("1.4142+-", IAE);
|
||||||
tryCatch("2.9979+-%", IAE);
|
tryCatch("2.9979+-%", IAE);
|
||||||
|
tryCatch("10--ea", IAE);
|
||||||
|
|
||||||
//// Test for Runtime.version()
|
//// Test for Runtime.version()
|
||||||
testVersion();
|
testVersion();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user