Skip to content

Commit 0b30e21

Browse files
committed
Fixed exception comparing versions
1 parent 4edcf99 commit 0b30e21

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

src/main/java/com/imsweb/naaccrxml/SpecificationVersion.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*/
44
package com.imsweb.naaccrxml;
55

6+
import java.util.Objects;
7+
68
import org.apache.commons.lang3.StringUtils;
79

810
public final class SpecificationVersion {
@@ -46,6 +48,9 @@ public static boolean isSpecificationSupported(String spec) {
4648
* @return negative integer if first version is smaller, 0 if they are the same, positive integer otherwise
4749
*/
4850
public static int compareSpecifications(String spec1, String spec2) {
51+
if (StringUtils.isBlank(spec1) || !isSpecificationSupported(spec1) || StringUtils.isBlank(spec2) || !isSpecificationSupported(spec2))
52+
return Objects.compare(spec1, spec2, String::compareTo);
53+
4954
String[] parts1 = StringUtils.split(spec1, '.');
5055
Integer major1 = Integer.valueOf(parts1[0]);
5156
Integer minor1 = Integer.valueOf(parts1[1]);

src/test/java/com/imsweb/naaccrxml/SpecificationVersionTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public void testCompareVersions() {
4444
Assert.assertEquals(1, SpecificationVersion.compareSpecifications("2.1", "1.0"));
4545
Assert.assertEquals(-1, SpecificationVersion.compareSpecifications("1.2", "2.1"));
4646
Assert.assertEquals(1, SpecificationVersion.compareSpecifications("2.1", "1.2"));
47+
48+
Assert.assertEquals(2, SpecificationVersion.compareSpecifications("1.0", "1"));
49+
Assert.assertEquals(-2, SpecificationVersion.compareSpecifications("1", "1.0"));
50+
Assert.assertEquals(0, SpecificationVersion.compareSpecifications("1", "1"));
4751
}
4852

4953
@Test

0 commit comments

Comments
 (0)