I have use cases where I need to do something if some string is not a semantic version. Currently I have to write:
// if the requested version is an exact semantic version, make no adjustments
try {
Version.valueOf(details.requested.version)
}
catch (IllegalArgumentException | ParseException ve) {
// this was not an exact semantic version
// do something
}
I would like to write
if ( ! Version.isValid(details.requested.version) ) {
// do something
}
rather than using a try/catch for this logic. At my company, we have a coding standard that states "Do not use exceptions for control flow" and while I can, I shouldn't have to.
isValid should return true only if the string matches the semver spec (i.e. it should not do any of the loose parsing I've seen suggested in some other issues like accepting a 1 or 1.0 as a valid version string and padding it out to 1.0.0)
I have use cases where I need to do something if some string is not a semantic version. Currently I have to write:
// if the requested version is an exact semantic version, make no adjustments try { Version.valueOf(details.requested.version) } catch (IllegalArgumentException | ParseException ve) { // this was not an exact semantic version // do something }
I would like to write
if ( ! Version.isValid(details.requested.version) ) { // do something }
rather than using a try/catch for this logic. At my company, we have a coding standard that states "Do not use exceptions for control flow" and while I can, I shouldn't have to.
isValid should return true only if the string matches the semver spec (i.e. it should not do any of the loose parsing I've seen suggested in some other issues like accepting a 1 or 1.0 as a valid version string and padding it out to 1.0.0)