File tree 2 files changed +12
-4
lines changed
main/java/com/google/devtools/build/lib/bazel/bzlmod
test/java/com/google/devtools/build/lib/bazel/bzlmod
2 files changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -87,7 +87,7 @@ abstract static class Identifier implements Comparable<Identifier> {
87
87
88
88
abstract boolean isDigitsOnly ();
89
89
90
- abstract int asNumber ();
90
+ abstract long asNumber ();
91
91
92
92
abstract String asString ();
93
93
@@ -96,15 +96,19 @@ static Identifier from(String string) throws ParseException {
96
96
throw new ParseException ("identifier is empty" );
97
97
}
98
98
if (string .chars ().allMatch (Character ::isDigit )) {
99
- return new AutoValue_Version_Identifier (true , Integer .parseInt (string ), string );
99
+ try {
100
+ return new AutoValue_Version_Identifier (true , Long .parseUnsignedLong (string ), string );
101
+ } catch (NumberFormatException e ) {
102
+ throw new ParseException ("numeric version segment is too large: " + string , e );
103
+ }
100
104
} else {
101
105
return new AutoValue_Version_Identifier (false , 0 , string );
102
106
}
103
107
}
104
108
105
109
private static final Comparator <Identifier > COMPARATOR =
106
110
comparing (Identifier ::isDigitsOnly , trueFirst ())
107
- .thenComparingInt ( Identifier :: asNumber )
111
+ .thenComparing (( a , b ) -> Long . compareUnsigned ( a . asNumber (), b . asNumber ()) )
108
112
.thenComparing (Identifier ::asString );
109
113
110
114
@ Override
Original file line number Diff line number Diff line change @@ -70,14 +70,18 @@ public void testPrereleaseVersion() throws Exception {
70
70
assertThat (Version .parse ("1.0-pre.99" )).isLessThan (Version .parse ("1.0-pre.2a" ));
71
71
assertThat (Version .parse ("1.0-pre.patch.3" )).isLessThan (Version .parse ("1.0-pre.patch.4" ));
72
72
assertThat (Version .parse ("1.0--" )).isLessThan (Version .parse ("1.0----" ));
73
+ assertThat (Version .parse ("2.1.1-develop.bcr.20250113215904" ))
74
+ .isGreaterThan (Version .parse ("2.1.1-develop.bcr.20250113215903" ));
73
75
}
74
76
75
77
@ Test
76
- public void testParseException () throws Exception {
78
+ public void testParseException () {
77
79
assertThrows (ParseException .class , () -> Version .parse ("-abc" ));
78
80
assertThrows (ParseException .class , () -> Version .parse ("1_2" ));
79
81
assertThrows (ParseException .class , () -> Version .parse ("ßážëł" ));
80
82
assertThrows (ParseException .class , () -> Version .parse ("1.0-pre?" ));
83
+ assertThrows (
84
+ ParseException .class , () -> Version .parse ("1.0-11111111111111111111111111111111111111111" ));
81
85
assertThrows (ParseException .class , () -> Version .parse ("1.0-pre///" ));
82
86
assertThrows (ParseException .class , () -> Version .parse ("1..0" ));
83
87
assertThrows (ParseException .class , () -> Version .parse ("1.0-pre..erp" ));
You can’t perform that action at this time.
0 commit comments