8006085: [findbugs] a warning on javax.sound.sampled.DataLine$Info constructor
Reviewed-by: art, prr
--- a/jdk/src/share/classes/javax/sound/sampled/DataLine.java Fri Aug 16 16:52:53 2013 +0400
+++ b/jdk/src/share/classes/javax/sound/sampled/DataLine.java Fri Aug 16 20:56:46 2013 +0400
@@ -25,6 +25,8 @@
package javax.sound.sampled;
+import java.util.Arrays;
+
/**
* <code>DataLine</code> adds media-related functionality to its
* superinterface, <code>{@link Line}</code>. This functionality includes
@@ -282,9 +284,9 @@
*/
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 @@
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 @@
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 @@
* @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);
}
/**