Closed ethauvin closed 7 years ago
I also ran into this today for the first time.
I definitely think that ArrayIndexOutOfBoundsException
isn't the appropriate exception to throw. An IllegalArgumentException
with an error message would be consistent with other exceptions thrown by the library.
I'll check on these today. I'll keep you posted on that.
I fixed it.
Instead throwing an exception, I return an empty array []
. This is the same behavior of the original library(Javascript).
I have found two other occurrences where I get ArrayIndexOutOfBoundsException from deep in the HashIds code.
Hashids hashids = new Hashids("this is my salt"); long[] numbers = hashids.decode("[]");
and
Hashids hashids = new Hashids("this is my salt"); long[] numbers = hashids.decode("()");
Like the original submitter above, these aren't valid hashes, but I'm running into these errors in my web app because someone COULD put these characters in as an ID in a URL accidentally or on purpose. My app is just passing in these characters directly into HashIds. I would expect something other than ArrayIndexOutOfBoundsExceptions.
Please let me know if I should open a new bug. I figured this is directly related to this issue so I'd comment here.
Hi @kmandeville , I'll look at this issue, but for the sake of organization, could you file another issue? Just to relate it in the commit. I'll get to work on it right away Thanks.
@kmandeville , never mind, I just created it(Issue #45) and fixed in master.
Thanks!
Thank you!
Both:
and:
are causing exceptions in various places.
I realize that they are not valid hashes, but the exception should either be declared or handled.
Hope this helps.