Closed marcello1975 closed 10 years ago
Same behaviour for BigDecimal and others...
Problem is in this method when it relies that most of Number sons are assignable from Integer, Long and others:
@Override
@SuppressWarnings("unchecked")
public
if (this.dataset != null && this.dataset.length > 0) {
result = this.dataset[random.nextInt(this.dataset.length)];
} else if (this.functions != null && this.functions.length > 0) {
result = this.functions[random.nextInt(this.functions.length)].generateValue();
} else if (this.type.isEnum()) {
result = this.type.getEnumConstants()[random.nextInt(this.type.getEnumConstants().length)];
} else if (this.type.isAssignableFrom(Integer.class)) {
result = this.range == null ? random.nextInt() : (this.range.getStart().intValue() + (int)(Math.random() * (this.range.getEnd().intValue() - this.range.getStart().intValue()) + 1));
} else if (this.type.isAssignableFrom(Long.class)) {
result = this.range == null ? random.nextLong() : (this.range.getStart().longValue() + (long)(Math.random() * (this.range.getEnd().longValue() - this.range.getStart().longValue()) + 1));
} else if (this.type.isAssignableFrom(Float.class)) {
result = this.range == null ? random.nextFloat() : (this.range.getStart().floatValue() + (float)(Math.random() * (this.range.getEnd().floatValue() - this.range.getStart().floatValue()) + 1));
} else if (this.type.isAssignableFrom(Double.class)) {
result = this.range == null ? random.nextDouble() : (this.range.getStart().doubleValue() + (double)(Math.random() * (this.range.getEnd().doubleValue() - this.range.getStart().doubleValue()) + 1));
} else if (this.type.isAssignableFrom(Boolean.class)) {
result = random.nextBoolean();
}
return (T) result;
}
@marcello1975 thank you for reporting this!
Boa tarde, Outro detalhe que não sei se interessa a vocês, é que para o caso da RandomFunction, se o cara informar um range fora dos valores MAX/MIN do tipo (Short por exemplo) ele retorna com perda de precisão, por exemplo, se o cara informar 99999 como Range máximo para um Short quando é dado "this.range.getEnd().shortValue()" ele retorna um valor negativo (-31073) por que esse número não cabe nos bits de um Short. Eu entendo que "poxa se o cara está pedindo um Short porque vai colocar um range fora do tamanho do tipo???", mas caso queiram tratar isso seria tipo uma cereja no bolo... Talvez já no momento da criação do template lançar uma exceção tipo "RangeOutBoundException"... ai o cara nem consegue criar o template errado... pode ser preciosismo de minha parte, mas sei lá vejam ai que acham da ideia..
Att, Marcello Ribeiro
I do have a simple java Object which has a property of Type Short.
What happens is that a simple "add/random" for this Short type property does not take any effect and the property is still null after gimme is called;
Does anyone have any words on this? or is it a really bug in the API?