You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
If the list of longs passed to the method public String encode(long... numbers) contains a negative value, it may result in a java.lang.ArrayIndexOutOfBoundsException being thrown. Here is the offending code snippet (see added inline comments.
private String _encode(long... numbers){
int numberHashInt = 0;
for(int i = 0; i < numbers.length; i++){
numberHashInt += (numbers[i] % (i+100)); // If numbers contains a negative long value then numberHashInt could be negative
}
String alphabet = this.alphabet;
char ret = alphabet.toCharArray()[numberHashInt % alphabet.length()]; // if numberHashInt is negative, an ArrayIndexOutOfBoundsException will be thrown
Possible Solutions:
In the method public String encode(long... numbers) replace the following line
if (number > 9007199254740992L) {
with
if (number > 9007199254740992L || number < 0) {
In the method private String _encode(long... numbers) use the absolute value of the long values in numbers when computing the hash:
int numberHashInt = 0;
for(int i = 0; i < numbers.length; i++){
numberHashInt += (Math.abs(numbers[i]) % (i+100));
}
The text was updated successfully, but these errors were encountered:
Problem:
If the list of longs passed to the method
public String encode(long... numbers)
contains a negative value, it may result in ajava.lang.ArrayIndexOutOfBoundsException
being thrown. Here is the offending code snippet (see added inline comments.Possible Solutions:
public String encode(long... numbers)
replace the following lineif (number > 9007199254740992L) {
with
if (number > 9007199254740992L || number < 0) {
private String _encode(long... numbers)
use the absolute value of the long values in numbers when computing the hash:The text was updated successfully, but these errors were encountered: