diff options
Diffstat (limited to 'src/share/classes/java/lang')
-rw-r--r-- | src/share/classes/java/lang/AssertionError.java | 19 | ||||
-rw-r--r-- | src/share/classes/java/lang/Math.java | 21 | ||||
-rw-r--r-- | src/share/classes/java/lang/ProcessBuilder.java | 4 | ||||
-rw-r--r-- | src/share/classes/java/lang/StrictMath.java | 21 |
4 files changed, 46 insertions, 19 deletions
diff --git a/src/share/classes/java/lang/AssertionError.java b/src/share/classes/java/lang/AssertionError.java index 75e8cd8f0..8fb577a6e 100644 --- a/src/share/classes/java/lang/AssertionError.java +++ b/src/share/classes/java/lang/AssertionError.java @@ -66,7 +66,7 @@ public class AssertionError extends Error { * defined in <i>The Java Language Specification, Second * Edition</i>, Section 15.18.1.1. *<p> - * If the specified object is an instance of <tt>Throwable</tt>, it + * If the specified object is an instance of {@code Throwable}, it * becomes the <i>cause</i> of the newly constructed assertion error. * * @param detailMessage value to be used in constructing detail message @@ -149,4 +149,21 @@ public class AssertionError extends Error { public AssertionError(double detailMessage) { this("" + detailMessage); } + + /** + * Constructs a new {@code AssertionError} with the specified + * detail message and cause. + * + * <p>Note that the detail message associated with + * {@code cause} is <i>not</i> automatically incorporated in + * this error's detail message. + * + * @param message the detail message, may be {@code null} + * @param cause the cause, may be {@code null} + * + * @since 1.7 + */ + public AssertionError(String message, Throwable cause) { + super(message, cause); + } } diff --git a/src/share/classes/java/lang/Math.java b/src/share/classes/java/lang/Math.java index 7ce31265d..455a21f9a 100644 --- a/src/share/classes/java/lang/Math.java +++ b/src/share/classes/java/lang/Math.java @@ -681,9 +681,9 @@ public final class Math { private static Random randomNumberGenerator; - private static synchronized void initRNG() { - if (randomNumberGenerator == null) - randomNumberGenerator = new Random(); + private static synchronized Random initRNG() { + Random rnd = randomNumberGenerator; + return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd; } /** @@ -694,9 +694,11 @@ public final class Math { * * <p>When this method is first called, it creates a single new * pseudorandom-number generator, exactly as if by the expression - * <blockquote>{@code new java.util.Random}</blockquote> This - * new pseudorandom-number generator is used thereafter for all - * calls to this method and is used nowhere else. + * + * <blockquote>{@code new java.util.Random()}</blockquote> + * + * This new pseudorandom-number generator is used thereafter for + * all calls to this method and is used nowhere else. * * <p>This method is properly synchronized to allow correct use by * more than one thread. However, if many threads need to generate @@ -705,11 +707,12 @@ public final class Math { * * @return a pseudorandom {@code double} greater than or equal * to {@code 0.0} and less than {@code 1.0}. - * @see java.util.Random#nextDouble() + * @see Random#nextDouble() */ public static double random() { - if (randomNumberGenerator == null) initRNG(); - return randomNumberGenerator.nextDouble(); + Random rnd = randomNumberGenerator; + if (rnd == null) rnd = initRNG(); + return rnd.nextDouble(); } /** diff --git a/src/share/classes/java/lang/ProcessBuilder.java b/src/share/classes/java/lang/ProcessBuilder.java index 82fad4a2b..97ce45cdf 100644 --- a/src/share/classes/java/lang/ProcessBuilder.java +++ b/src/share/classes/java/lang/ProcessBuilder.java @@ -418,6 +418,8 @@ public final class ProcessBuilder * Implements a <a href="#redirect-output">null input stream</a>. */ static class NullInputStream extends InputStream { + static final NullInputStream INSTANCE = new NullInputStream(); + private NullInputStream() {} public int read() { return -1; } public int available() { return 0; } } @@ -426,6 +428,8 @@ public final class ProcessBuilder * Implements a <a href="#redirect-input">null output stream</a>. */ static class NullOutputStream extends OutputStream { + static final NullOutputStream INSTANCE = new NullOutputStream(); + private NullOutputStream() {} public void write(int b) throws IOException { throw new IOException("Stream closed"); } diff --git a/src/share/classes/java/lang/StrictMath.java b/src/share/classes/java/lang/StrictMath.java index f2f275b5c..916b82ff9 100644 --- a/src/share/classes/java/lang/StrictMath.java +++ b/src/share/classes/java/lang/StrictMath.java @@ -667,9 +667,9 @@ public final class StrictMath { private static Random randomNumberGenerator; - private static synchronized void initRNG() { - if (randomNumberGenerator == null) - randomNumberGenerator = new Random(); + private static synchronized Random initRNG() { + Random rnd = randomNumberGenerator; + return (rnd == null) ? (randomNumberGenerator = new Random()) : rnd; } /** @@ -680,9 +680,11 @@ public final class StrictMath { * * <p>When this method is first called, it creates a single new * pseudorandom-number generator, exactly as if by the expression - * <blockquote>{@code new java.util.Random}</blockquote> This - * new pseudorandom-number generator is used thereafter for all - * calls to this method and is used nowhere else. + * + * <blockquote>{@code new java.util.Random()}</blockquote> + * + * This new pseudorandom-number generator is used thereafter for + * all calls to this method and is used nowhere else. * * <p>This method is properly synchronized to allow correct use by * more than one thread. However, if many threads need to generate @@ -691,11 +693,12 @@ public final class StrictMath { * * @return a pseudorandom {@code double} greater than or equal * to {@code 0.0} and less than {@code 1.0}. - * @see java.util.Random#nextDouble() + * @see Random#nextDouble() */ public static double random() { - if (randomNumberGenerator == null) initRNG(); - return randomNumberGenerator.nextDouble(); + Random rnd = randomNumberGenerator; + if (rnd == null) rnd = initRNG(); + return rnd.nextDouble(); } /** |