File tree Expand file tree Collapse file tree
main/java/com/datastax/oss/driver/internal/core/addresstranslation
test/java/com/datastax/oss/driver/internal/core/addresstranslation Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -55,7 +55,13 @@ static Subnet parse(String subnetCIDR) throws UnknownHostException {
5555 if (isIPv4 (subnet ) && isIPv6 ) {
5656 subnet = toIPv6 (subnet );
5757 }
58- int prefixLength = Integer .parseInt (parts .get (1 ));
58+ int prefixLength ;
59+ try {
60+ prefixLength = Integer .parseInt (parts .get (1 ));
61+ } catch (NumberFormatException e ) {
62+ throw new IllegalArgumentException (
63+ String .format ("Prefix length %s must be a number" , parts .get (1 )), e );
64+ }
5965 validatePrefixLength (subnet , prefixLength );
6066
6167 byte [] networkMask = toNetworkMask (subnet , prefixLength );
Original file line number Diff line number Diff line change @@ -85,6 +85,13 @@ public void should_fail_on_invalid_prefix_length() {
8585 .withMessage ("Prefix length 33 must be within [0; 32]" );
8686 }
8787
88+ @ Test
89+ public void should_fail_on_non_numeric_prefix_length () {
90+ assertThatIllegalArgumentException ()
91+ .isThrownBy (() -> Subnet .parse ("100.64.0.0/foo" ))
92+ .withMessage ("Prefix length foo must be a number" );
93+ }
94+
8895 @ Test
8996 public void should_fail_on_not_prefix_block_subnet_ipv4 () {
9097 assertThatIllegalArgumentException ()
You can’t perform that action at this time.
0 commit comments