@@ -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
0 commit comments