# HG changeset patch # User igerasim # Date 1478101514 -10800 # Node ID b26ea3cb64c5a5272bf00537497b312cf3dd8cd1 # Parent 90450650fe743b035d453c3a3d6696aae886a556 8168923: Use unsigned random long in a temp directory name Reviewed-by: bpb, alanb diff -r 90450650fe74 -r b26ea3cb64c5 jdk/src/java.base/share/classes/java/io/File.java --- a/jdk/src/java.base/share/classes/java/io/File.java Wed Nov 02 14:46:40 2016 +0000 +++ b/jdk/src/java.base/share/classes/java/io/File.java Wed Nov 02 18:45:14 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1907,16 +1907,10 @@ throws IOException { long n = random.nextLong(); - if (n == Long.MIN_VALUE) { - n = 0; // corner case - } else { - n = Math.abs(n); - } // Use only the file name from the supplied prefix prefix = (new File(prefix)).getName(); - - String name = prefix + Long.toString(n) + suffix; + String name = prefix + Long.toUnsignedString(n) + suffix; File f = new File(dir, name); if (!name.equals(f.getName()) || f.isInvalid()) { if (System.getSecurityManager() != null) diff -r 90450650fe74 -r b26ea3cb64c5 jdk/src/java.base/share/classes/java/nio/file/TempFileHelper.java --- a/jdk/src/java.base/share/classes/java/nio/file/TempFileHelper.java Wed Nov 02 14:46:40 2016 +0000 +++ b/jdk/src/java.base/share/classes/java/nio/file/TempFileHelper.java Wed Nov 02 18:45:14 2016 +0300 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2009, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -55,8 +55,8 @@ private static final SecureRandom random = new SecureRandom(); private static Path generatePath(String prefix, String suffix, Path dir) { long n = random.nextLong(); - n = (n == Long.MIN_VALUE) ? 0 : Math.abs(n); - Path name = dir.getFileSystem().getPath(prefix + Long.toString(n) + suffix); + String s = prefix + Long.toUnsignedString(n) + suffix; + Path name = dir.getFileSystem().getPath(s); // the generated name should be a simple file name if (name.getParent() != null) throw new IllegalArgumentException("Invalid prefix or suffix");