refactor: support more random suffix to prevent multi-thread crash

This commit is contained in:
Connor Tumbleson 2020-04-11 06:50:09 -04:00
parent d4b2314e26
commit 44a2e87f81
No known key found for this signature in database
GPG Key ID: C3CC0A201EC7DA75

View File

@ -85,19 +85,16 @@ abstract public class Jar {
if (in == null) {
throw new FileNotFoundException(resourcePath);
}
long n = ThreadLocalRandom.current().nextLong();
if (n == Long.MIN_VALUE) {
n = 0; // corner case
} else {
n = Math.abs(n);
}
String suffix = Long.toString(n) + ".tmp";
File fileOut = File.createTempFile(tmpPrefix, suffix);
long suffix = ThreadLocalRandom.current().nextLong();
suffix = suffix == Long.MIN_VALUE ? 0 : Math.abs(suffix);
File fileOut = File.createTempFile(tmpPrefix, suffix + ".tmp");
fileOut.deleteOnExit();
OutputStream out = new FileOutputStream(fileOut);
IOUtils.copy(in, out);
in.close();
out.close();
return fileOut;
} catch (IOException ex) {
throw new BrutException("Could not extract resource: " + resourcePath, ex);