Skip to content

Commit 3c29591

Browse files
committed
Fixed isValidMapcodeFormat to trim string and check for null
1 parent d842f8e commit 3c29591

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,14 @@ Normally, one of our developers should be able to comment on them and fix.
477477

478478

479479
# Release Notes <a name="releasenotes"></a>
480-
480+
mat
481481
These are the release notes for the Java library for mapcodes.
482482

483+
### 2.4.10
484+
485+
* Changed `Mapcode.isValidMapcodeFormat()` to return `false` if the string is `null`. Trimming the string is also
486+
no longer needed.
487+
483488
### 2.4.9
484489

485490
* Updated dependencies for security patches.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<artifactId>mapcode</artifactId>
99

1010
<packaging>jar</packaging>
11-
<version>2.4.9</version>
11+
<version>2.4.10</version>
1212

1313
<name>Mapcode Java Library</name>
1414
<description>

src/main/java/com/mapcode/Mapcode.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.regex.Pattern;
2424

2525
import static com.mapcode.CheckArgs.checkMapcodeCode;
26-
import static com.mapcode.CheckArgs.checkNonnull;
2726

2827
/**
2928
* This class defines a single mapcode encoding result, including the alphanumeric code and the
@@ -313,11 +312,13 @@ public static int getPrecisionFormat(@Nonnull final String mapcode) throws Unkno
313312
* actually a valid mapcode representing a location on Earth.
314313
* @throws IllegalArgumentException If mapcode is null.
315314
*/
316-
public static boolean isValidMapcodeFormat(@Nonnull final String mapcode) throws IllegalArgumentException {
317-
checkNonnull("mapcode", mapcode);
315+
public static boolean isValidMapcodeFormat(@Nullable final String mapcode) throws IllegalArgumentException {
316+
if (mapcode == null) {
317+
return false;
318+
}
318319
try {
319320
// Throws an exception if the format is incorrect.
320-
getPrecisionFormat(mapcode.toUpperCase());
321+
getPrecisionFormat(mapcode.trim().toUpperCase());
321322
return true;
322323
} catch (final UnknownPrecisionFormatException ignored) {
323324
return false;
@@ -333,7 +334,7 @@ public static boolean isValidMapcodeFormat(@Nonnull final String mapcode) throws
333334
*/
334335
public static boolean containsTerritory(@Nonnull final String mapcode) throws IllegalArgumentException {
335336
checkMapcodeCode("mapcode", mapcode);
336-
return PATTERN_TERRITORY.matcher(mapcode.toUpperCase().trim()).find();
337+
return PATTERN_TERRITORY.matcher(mapcode.trim().toUpperCase()).find();
337338
}
338339

339340
/**

src/test/java/com/mapcode/MapcodeTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public void checkInvalidPrecisionFormats() {
8686
LOG.info("checkInvalidPrecisionFormats");
8787

8888
// Territory code must be correct syntax.
89+
assertFalse(Mapcode.isValidMapcodeFormat(null));
8990
assertFalse(Mapcode.isValidMapcodeFormat(""));
9091
assertFalse(Mapcode.isValidMapcodeFormat("NL- XX.XX"));
9192
assertFalse(Mapcode.isValidMapcodeFormat("US IN XX.XX"));

0 commit comments

Comments
 (0)