-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@Size without max attribute causes a java.lang.OutOfMemoryError: Java heap space #289
Comments
Yeah, with random beans, we have random bugs 😄 Sorry, I couldn't resist on this.. Anyway, thank you for pointing this out! |
Hi, The issue does not happen when both Thank you for pointing this out! Let me try to fix that for v3.8.0. Kr |
Hi, When the When I first analysed this issue, I thought that the cause of the OOM is the string concatenation in @Override
public String getRandomValue() {
StringBuilder stringBuilder = new StringBuilder();
int length = minLength + random.nextInt(maxLength - minLength + 1);
for (int i = 0; i < length; i++) {
stringBuilder.append(characterRandomizer.getRandomValue());
}
return stringBuilder.toString();
} I changed the above code to: @Override
public String getRandomValue() {
int length = minLength + random.nextInt(maxLength - minLength + 1);
char[] chars = new char[length];
for (int i = 0; i < length; i++) {
chars[i] = characterRandomizer.getRandomValue();
}
return new String(chars);
} which is better but the OOM still happens for a large length. Random Beans can do nothing in this case. We need to:
BTW, here is the exact same code outside of Random Beans which also causes an OOM with a high length value: import java.util.Random;
class Scratch {
public static void main(String[] args) {
Random random = new Random();
int length = 374668018;
char[] chars = new char[length];
for (int i = 0; i < length; i++) {
chars[i] = (char) random.nextInt(127);
}
String value = new String(chars); // java.lang.OutOfMemoryError: Java heap space at java.util.Arrays.copyOf(Arrays.java:3332)
System.out.println("value = " + value);
}
} That said, I'm closing this issue. Kr, |
Hi random-beans Team,
@Size
onString
is causingjava.lang.OutOfMemoryError: Java heap space
.This bug is not always happening, but during debugging there are always problems.
Example:
Also it is not working at all with validation-api pre 2.0, even if
Java heap space
doesn't appear@Size
is just ignored.Best regards,
Redid
The text was updated successfully, but these errors were encountered: