From a3ba31ae89f7561ae43f37442f32ea312757d72f Mon Sep 17 00:00:00 2001 From: serb Date: Fri, 16 Aug 2013 20:56:46 +0400 Subject: [PATCH] 8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor Reviewed-by: art, prr --- .../classes/javax/sound/sampled/DataLine.java | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/share/classes/javax/sound/sampled/DataLine.java b/src/share/classes/javax/sound/sampled/DataLine.java index f74953b19..8b3b1809a 100644 --- a/src/share/classes/javax/sound/sampled/DataLine.java +++ b/src/share/classes/javax/sound/sampled/DataLine.java @@ -25,6 +25,8 @@ package javax.sound.sampled; +import java.util.Arrays; + /** * DataLine adds media-related functionality to its * superinterface, {@link Line}. This functionality includes @@ -282,9 +284,9 @@ public interface DataLine extends Line { */ public static class Info extends Line.Info { - private AudioFormat[] formats; - private int minBufferSize; - private int maxBufferSize; + private final AudioFormat[] formats; + private final int minBufferSize; + private final int maxBufferSize; /** * Constructs a data line's info object from the specified information, @@ -304,7 +306,7 @@ public interface DataLine extends Line { if (formats == null) { this.formats = new AudioFormat[0]; } else { - this.formats = formats; + this.formats = Arrays.copyOf(formats, formats.length); } this.minBufferSize = minBufferSize; @@ -329,8 +331,7 @@ public interface DataLine extends Line { if (format == null) { this.formats = new AudioFormat[0]; } else { - AudioFormat[] formats = { format }; - this.formats = formats; + this.formats = new AudioFormat[]{format}; } this.minBufferSize = bufferSize; @@ -373,10 +374,7 @@ public interface DataLine extends Line { * @see #isFormatSupported(AudioFormat) */ public AudioFormat[] getFormats() { - - AudioFormat[] returnedArray = new AudioFormat[formats.length]; - System.arraycopy(formats, 0, returnedArray, 0, formats.length); - return returnedArray; + return Arrays.copyOf(formats, formats.length); } /** -- GitLab