Committed by
Brian O'Connor
ONOS-2124 Added a few more validity checks.
Change-Id: Icbb784bd0caa124b6bfac03619702b6f2250ffff
Showing
1 changed file
with
4 additions
and
2 deletions
| ... | @@ -31,6 +31,7 @@ public final class Version { | ... | @@ -31,6 +31,7 @@ public final class Version { |
| 31 | public static final String FORMAT_LONG = "%d.%d.%s.%s"; | 31 | public static final String FORMAT_LONG = "%d.%d.%s.%s"; |
| 32 | 32 | ||
| 33 | private static final String NEGATIVE = "Version segment cannot be negative"; | 33 | private static final String NEGATIVE = "Version segment cannot be negative"; |
| 34 | + public static final String TOO_SHORT = "Version must have at least major and minor numbers"; | ||
| 34 | 35 | ||
| 35 | private final int major; | 36 | private final int major; |
| 36 | private final int minor; | 37 | private final int minor; |
| ... | @@ -64,8 +65,8 @@ public final class Version { | ... | @@ -64,8 +65,8 @@ public final class Version { |
| 64 | * @return version descriptor | 65 | * @return version descriptor |
| 65 | */ | 66 | */ |
| 66 | public static Version version(int major, int minor, String patch, String build) { | 67 | public static Version version(int major, int minor, String patch, String build) { |
| 67 | - checkArgument(major > 0, NEGATIVE); | 68 | + checkArgument(major >= 0, NEGATIVE); |
| 68 | - checkArgument(minor > 0, NEGATIVE); | 69 | + checkArgument(minor >= 0, NEGATIVE); |
| 69 | return new Version(major, minor, patch, build); | 70 | return new Version(major, minor, patch, build); |
| 70 | } | 71 | } |
| 71 | 72 | ||
| ... | @@ -77,6 +78,7 @@ public final class Version { | ... | @@ -77,6 +78,7 @@ public final class Version { |
| 77 | */ | 78 | */ |
| 78 | public static Version version(String string) { | 79 | public static Version version(String string) { |
| 79 | String[] fields = string.split("[.-]"); | 80 | String[] fields = string.split("[.-]"); |
| 81 | + checkArgument(fields.length >= 2, TOO_SHORT); | ||
| 80 | return new Version(parseInt(fields[0]), parseInt(fields[1]), | 82 | return new Version(parseInt(fields[0]), parseInt(fields[1]), |
| 81 | fields.length >= 3 ? fields[2] : null, | 83 | fields.length >= 3 ? fields[2] : null, |
| 82 | fields.length >= 4 ? fields[3] : null); | 84 | fields.length >= 4 ? fields[3] : null); | ... | ... |
-
Please register or login to post a comment