Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

A few additional comments to complement the other review:

Avoid spelling errors, especially in user-visible strings

The first error message has "octect" but what was meant was undoubtedly "octet". Spelling errors in code are unfortunately relatively common, but we should all make special effort to avoid such errors in user-visible strings. It could lead a user of the code to wonder how many less visible errors are also in the code.

Convert variables only when required

The ip variable is already a String, so ip.getText().toString()) seems to be doubly redundant.

Consider other error conditions

Some addresses will pass this validation but may, depending on context, not be appropriate. Two such addresses are 0.0.0.0 and 255.255.255.255 (Broadcast address). Other special addresses might also be inappropriate, depending on context. It may be useful to augment the existing code with additional functions which check for usability within a given context.

Be aware of exceptions that may be thrown

The StringUtils.isNumeric(octet) call will return true with an empty string return true with an empty string, but Integer.parseInt(octet) will throw a NumberFormatException. You may want to handle that in case the passed string is something like "0.0..0".

A few additional comments to complement the other review:

Avoid spelling errors, especially in user-visible strings

The first error message has "octect" but what was meant was undoubtedly "octet". Spelling errors in code are unfortunately relatively common, but we should all make special effort to avoid such errors in user-visible strings. It could lead a user of the code to wonder how many less visible errors are also in the code.

Convert variables only when required

The ip variable is already a String, so ip.getText().toString()) seems to be doubly redundant.

Consider other error conditions

Some addresses will pass this validation but may, depending on context, not be appropriate. Two such addresses are 0.0.0.0 and 255.255.255.255 (Broadcast address). Other special addresses might also be inappropriate, depending on context. It may be useful to augment the existing code with additional functions which check for usability within a given context.

Be aware of exceptions that may be thrown

The StringUtils.isNumeric(octet) call will return true with an empty string, but Integer.parseInt(octet) will throw a NumberFormatException. You may want to handle that in case the passed string is something like "0.0..0".

A few additional comments to complement the other review:

Avoid spelling errors, especially in user-visible strings

The first error message has "octect" but what was meant was undoubtedly "octet". Spelling errors in code are unfortunately relatively common, but we should all make special effort to avoid such errors in user-visible strings. It could lead a user of the code to wonder how many less visible errors are also in the code.

Convert variables only when required

The ip variable is already a String, so ip.getText().toString()) seems to be doubly redundant.

Consider other error conditions

Some addresses will pass this validation but may, depending on context, not be appropriate. Two such addresses are 0.0.0.0 and 255.255.255.255 (Broadcast address). Other special addresses might also be inappropriate, depending on context. It may be useful to augment the existing code with additional functions which check for usability within a given context.

Be aware of exceptions that may be thrown

The StringUtils.isNumeric(octet) call will return true with an empty string, but Integer.parseInt(octet) will throw a NumberFormatException. You may want to handle that in case the passed string is something like "0.0..0".

Source Link
Edward
  • 67.2k
  • 4
  • 120
  • 284

A few additional comments to complement the other review:

Avoid spelling errors, especially in user-visible strings

The first error message has "octect" but what was meant was undoubtedly "octet". Spelling errors in code are unfortunately relatively common, but we should all make special effort to avoid such errors in user-visible strings. It could lead a user of the code to wonder how many less visible errors are also in the code.

Convert variables only when required

The ip variable is already a String, so ip.getText().toString()) seems to be doubly redundant.

Consider other error conditions

Some addresses will pass this validation but may, depending on context, not be appropriate. Two such addresses are 0.0.0.0 and 255.255.255.255 (Broadcast address). Other special addresses might also be inappropriate, depending on context. It may be useful to augment the existing code with additional functions which check for usability within a given context.

Be aware of exceptions that may be thrown

The StringUtils.isNumeric(octet) call will return true with an empty string, but Integer.parseInt(octet) will throw a NumberFormatException. You may want to handle that in case the passed string is something like "0.0..0".

lang-java

AltStyle によって変換されたページ (->オリジナル) /