Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit a623530

Browse files
committed
3.1.1
1 parent 04f2eed commit a623530

File tree

4 files changed

+31
-27
lines changed

4 files changed

+31
-27
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.1.1
2+
3+
* Fix `SemVer.parse(String)` throw `IllegalStateException` when importing this dependency.
4+
15
## 3.1.0
26

37
* Assign `provide` scope to dependencies which doesn't need outside this package

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
<groupId>xyz.rk0cc.josev</groupId>
3333
<artifactId>josev-core</artifactId>
34-
<version>3.1.0</version>
34+
<version>3.1.1</version>
3535

3636
<licenses>
3737
<license>

src/main/java/xyz/rk0cc/josev/SemVer.java

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -428,37 +428,36 @@ public String toString() {
428428
*
429429
* @see #tryParse(String)
430430
*/
431-
@SuppressWarnings("AssertWithSideEffects")
432431
@Nonnull
433432
public static SemVer parse(@Nonnull String version) throws NonStandardSemVerException {
434433
final String v = version.charAt(0) == 'v' ? version.substring(1) : version;
435-
try {
436-
final Matcher vm = compiledSemverRegex().matcher(v);
437-
assert vm.matches();
438-
439-
// Extract string from group
440-
ArrayList<String> matchedGroup = new ArrayList<>();
441-
int g = 1; // Must be started from 1, 0 is entire version string
442-
while (true) {
443-
try {
444-
matchedGroup.add(vm.group(g++));
445-
} catch (IndexOutOfBoundsException ioobe) {
446-
// Stop append if reached maximum
447-
break;
448-
}
449-
}
434+
final Matcher vm = compiledSemverRegex().matcher(v);
435+
if (!vm.matches()) throw new NonStandardSemVerException(version, new AssertionError());
450436

451-
// 3 mandatory part
452-
final long major, minor, patch;
437+
// Extract string from group
438+
ArrayList<String> matchedGroup = new ArrayList<>();
439+
int g = 1; // Must be started from 1, 0 is entire version string
440+
while (true) {
453441
try {
454-
// It should be decimal, otherwise it has been thrown already.
455-
major = Long.parseLong(matchedGroup.get(0), 10);
456-
minor = Long.parseLong(matchedGroup.get(1), 10);
457-
patch = Long.parseLong(matchedGroup.get(2), 10);
458-
} catch (IndexOutOfBoundsException isvd) {
459-
throw new AssertionError(isvd);
442+
matchedGroup.add(vm.group(g++));
443+
} catch (IndexOutOfBoundsException ioobe) {
444+
// Stop append if reached maximum
445+
break;
460446
}
447+
}
448+
449+
// 3 mandatory part
450+
final long major, minor, patch;
451+
try {
452+
// It should be decimal, otherwise it has been thrown already.
453+
major = Long.parseLong(matchedGroup.get(0), 10);
454+
minor = Long.parseLong(matchedGroup.get(1), 10);
455+
patch = Long.parseLong(matchedGroup.get(2), 10);
456+
} catch (IndexOutOfBoundsException | NumberFormatException e) {
457+
throw new NonStandardSemVerException(version, e);
458+
}
461459

460+
try {
462461
switch (matchedGroup.size()) {
463462
case 3:
464463
return new SemVer(major, minor, patch);
@@ -472,8 +471,8 @@ public static SemVer parse(@Nonnull String version) throws NonStandardSemVerExce
472471
default:
473472
throw new AssertionError("Unexpected number of semver pattern group found");
474473
}
475-
} catch (Throwable t) {
476-
throw (t instanceof NonStandardSemVerException nt) ? nt : new NonStandardSemVerException(version, t);
474+
} catch (AssertionError e) {
475+
throw new NonStandardSemVerException(version, e);
477476
}
478477
}
479478

src/test/resources/xyz/rk0cc/josev/semver_sample.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ semver,valid
77
1.1.2+meta-valid,true
88
1.0.0-alpha,true
99
1.0.0-beta,true
10+
1.0.0-pre-1,true
1011
1.0.0-alpha.beta,true
1112
1.0.0-alpha.beta.1,true
1213
1.0.0-alpha.1,true

0 commit comments

Comments
 (0)