From fd4540cd323e85396a4ba5d2bb2b8ee52f88e766 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Mon, 17 Oct 2011 13:37:55 -0400 Subject: [PATCH 1/2] Fixed extraordinarily subtle race condition with contracts invariant -- all of the methods in the class must be synchronized or the internal state can be inconsistent with the contract invariant when entering the class in a non-synchronized method, even when that method doesn't care about the object's internal state --- .../org/broadinstitute/sting/utils/SimpleTimer.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/public/java/src/org/broadinstitute/sting/utils/SimpleTimer.java b/public/java/src/org/broadinstitute/sting/utils/SimpleTimer.java index 6d228640f..a5ac10250 100644 --- a/public/java/src/org/broadinstitute/sting/utils/SimpleTimer.java +++ b/public/java/src/org/broadinstitute/sting/utils/SimpleTimer.java @@ -46,7 +46,7 @@ public class SimpleTimer { * @return the name associated with this timer */ @Ensures("result != null") - public String getName() { + public synchronized String getName() { return name; } @@ -82,14 +82,14 @@ public class SimpleTimer { /** * @return is this timer running? */ - public boolean isRunning() { + public synchronized boolean isRunning() { return running; } /** * @return A convenience function to obtain the current time in milliseconds from this timer */ - public long currentTime() { + public synchronized long currentTime() { return System.currentTimeMillis(); } @@ -119,8 +119,4 @@ public class SimpleTimer { public synchronized double getElapsedTime() { return (running ? (currentTime() - startTime + elapsed) : elapsed) / 1000.0; } - - public void printElapsedTime(PrintStream out) { - out.printf("SimpleTimer %s: %.2f%n", name, getElapsedTime()); - } } From 4108a294f76e051f9c14cc8884e49a90a46411c9 Mon Sep 17 00:00:00 2001 From: Mark DePristo Date: Mon, 17 Oct 2011 13:58:46 -0400 Subject: [PATCH 2/2] Better error message when a RodBinding file doesn't exist --- .../sting/commandline/ArgumentTypeDescriptor.java | 2 +- .../broadinstitute/sting/utils/exceptions/UserException.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java b/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java index 5fff8f609..94157963f 100644 --- a/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java +++ b/public/java/src/org/broadinstitute/sting/commandline/ArgumentTypeDescriptor.java @@ -380,7 +380,7 @@ class RodBindingArgumentTypeDescriptor extends ArgumentTypeDescriptor { if ( tribbleType == null ) if ( ! file.canRead() | ! file.isFile() ) { - throw new UserException.BadArgumentValue(name, "Couldn't read file to determine type: " + file); + throw new UserException.CouldNotReadInputFile(file, "file does exist or couldn't be read"); } else { throw new UserException.CommandLineException( String.format("No tribble type was provided on the command line and the type of the file could not be determined dynamically. " + diff --git a/public/java/src/org/broadinstitute/sting/utils/exceptions/UserException.java b/public/java/src/org/broadinstitute/sting/utils/exceptions/UserException.java index 274c64f42..9d131ae0c 100755 --- a/public/java/src/org/broadinstitute/sting/utils/exceptions/UserException.java +++ b/public/java/src/org/broadinstitute/sting/utils/exceptions/UserException.java @@ -111,6 +111,10 @@ public class UserException extends ReviewedStingException { super(String.format("Couldn't read file because %s caused by %s", message, e.getMessage())); } + public CouldNotReadInputFile(File file) { + super(String.format("Couldn't read file %s", file.getAbsolutePath())); + } + public CouldNotReadInputFile(File file, String message) { super(String.format("Couldn't read file %s because %s", file.getAbsolutePath(), message)); }