kungfoo / geohash-java

Implementation of GeoHashes in java. We try to be/stay compliant to the spec, as far as possible.
Other
985 stars 309 forks source link

GeoHash.fromGeohashString() throws NPE for Invalid GeoHash #40

Closed SufianBabri closed 4 years ago

SufianBabri commented 4 years ago

First of all, a big thanks to the contributors and the maintainers of this great library.

Now coming to the actual issue... The method GeoHash.fromGeohashString() throws NullPointerException if the argument is not a valid GeoHash (e.g. aaaaaa, sggfha).

Exception in thread "main" java.lang.NullPointerException
    at ch.hsr.geohash.GeoHash.fromGeohashString(GeoHash.java:103)
    at ch.hsr.geohash.Main.main(Main.java:6)

Background: Actually we faced the crash in our app because somehow an invalid geohash made into our server's DB and the app started crashing due to NPE.

Suggestion/request: Can a throws NullPointerException be added to the method signature so that the developers are aware that passing an invalid argument will throw an exception?

Since NPE is not a checked exception, the library will stay backwards compatible.

kungfoo commented 4 years ago

TBH, I think the library should throw an IllegalArgumentException in that case and that's also an unchecked exception so I would only put it in the javadoc. Thanks for reporting this though, I will take a look.

kungfoo commented 4 years ago

I will release this as 1.5.0