Github user ahgittin commented on a diff in the pull request:
https://github.com/apache/incubator-brooklyn/pull/61#discussion_r14806385
--- Diff: utils/common/src/main/java/brooklyn/util/os/Os.java ---
@@ -523,17 +525,16 @@ public static boolean isMicrosoftWindows() {
* either prefix or ext may be null;
* if ext is non-empty and not > 4 chars and not starting with a .,
then a dot will be inserted */
public static File newTempFile(String prefix, String ext) {
- String baseName = (prefix!=null ? prefix + "-" : "") +
Identifiers.makeRandomId(4) +
- (ext!=null ? ext.startsWith(".") || ext.length()>4 ? ext :
"."+ext : "");
- File tempFile = new File(tmp(), baseName);
+ String sanitizedPrefix = (prefix!=null ? prefix + "-" : "");
+ String sanitizedExt = (ext!=null ? ext.startsWith(".") ||
ext.length()>4 ? ext : "."+ext : "");
try {
- if (tempFile.createNewFile()) {
- tempFile.deleteOnExit();
- return tempFile;
- }
- throw new IllegalStateException("cannot create temp file
"+tempFile+", call returned false");
+ File tempFile = File.createTempFile(sanitizedPrefix,
sanitizedExt, new File(tmp()));
+ tempFile.deleteOnExit();
+ return tempFile;
} catch (IOException e) {
- throw new IllegalStateException("cannot create temp file
"+tempFile+", error: "+e, e);
+ Exceptions.propagate(e);
--- End diff --
most of us use `throw Exceptions.propagate(e)` to skip needing to include a
non-reachable `return null`; the `throw` never gets run of course but it is
misleading in a good way :)
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---