8005980: [findbugs] More com.sun.media.sound.* warnings
authorserb
Fri, 16 Aug 2013 21:18:21 +0400
changeset 19369 1b53b14758ee
parent 19368 5d7565f5978c
child 19370 02abaf6251be
child 20094 462e588b8284
8005980: [findbugs] More com.sun.media.sound.* warnings Reviewed-by: art, prr
jdk/src/share/classes/com/sun/media/sound/DataPusher.java
jdk/src/share/classes/com/sun/media/sound/ModelStandardDirector.java
jdk/src/share/classes/com/sun/media/sound/ModelStandardIndexedDirector.java
jdk/src/share/classes/com/sun/media/sound/SoftMixingClip.java
jdk/src/share/classes/sun/audio/AudioData.java
--- a/jdk/src/share/classes/com/sun/media/sound/DataPusher.java	Fri Aug 16 20:56:46 2013 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/DataPusher.java	Fri Aug 16 21:18:21 2013 +0400
@@ -25,6 +25,8 @@
 
 package com.sun.media.sound;
 
+import java.util.Arrays;
+
 import javax.sound.sampled.*;
 
 /**
@@ -46,11 +48,11 @@
     private final AudioFormat format;
 
     // stream as source data
-    private AudioInputStream ais = null;
+    private final AudioInputStream ais;
 
     // byte array as source data
-    private byte[] audioData = null;
-    private int audioDataByteLength = 0;
+    private final byte[] audioData;
+    private final int audioDataByteLength;
     private int pos;
     private int newPos = -1;
     private boolean looping;
@@ -67,16 +69,22 @@
     private final int BUFFER_SIZE = 16384;
 
     public DataPusher(SourceDataLine sourceLine, AudioFormat format, byte[] audioData, int byteLength) {
-        this.audioData = audioData;
-        this.audioDataByteLength = byteLength;
-        this.format = format;
-        this.source = sourceLine;
+        this(sourceLine, format, null, audioData, byteLength);
     }
 
     public DataPusher(SourceDataLine sourceLine, AudioInputStream ais) {
+        this(sourceLine, ais.getFormat(), ais, null, 0);
+    }
+
+    private DataPusher(final SourceDataLine source, final AudioFormat format,
+                       final AudioInputStream ais, final byte[] audioData,
+                       final int audioDataByteLength) {
+        this.source = source;
+        this.format = format;
         this.ais = ais;
-        this.format = ais.getFormat();
-        this.source = sourceLine;
+        this.audioDataByteLength = audioDataByteLength;
+        this.audioData = audioData == null ? null : Arrays.copyOf(audioData,
+                                                                  audioData.length);
     }
 
     public synchronized void start() {
--- a/jdk/src/share/classes/com/sun/media/sound/ModelStandardDirector.java	Fri Aug 16 20:56:46 2013 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/ModelStandardDirector.java	Fri Aug 16 21:18:21 2013 +0400
@@ -24,6 +24,8 @@
  */
 package com.sun.media.sound;
 
+import java.util.Arrays;
+
 /**
  * A standard director who chooses performers
  * by there keyfrom,keyto,velfrom,velto properties.
@@ -32,17 +34,16 @@
  */
 public final class ModelStandardDirector implements ModelDirector {
 
-    ModelPerformer[] performers;
-    ModelDirectedPlayer player;
-    boolean noteOnUsed = false;
-    boolean noteOffUsed = false;
+    private final ModelPerformer[] performers;
+    private final ModelDirectedPlayer player;
+    private boolean noteOnUsed = false;
+    private boolean noteOffUsed = false;
 
-    public ModelStandardDirector(ModelPerformer[] performers,
-            ModelDirectedPlayer player) {
-        this.performers = performers;
+    public ModelStandardDirector(final ModelPerformer[] performers,
+                                 final ModelDirectedPlayer player) {
+        this.performers = Arrays.copyOf(performers, performers.length);
         this.player = player;
-        for (int i = 0; i < performers.length; i++) {
-            ModelPerformer p = performers[i];
+        for (final ModelPerformer p : this.performers) {
             if (p.isReleaseTriggered()) {
                 noteOffUsed = true;
             } else {
--- a/jdk/src/share/classes/com/sun/media/sound/ModelStandardIndexedDirector.java	Fri Aug 16 20:56:46 2013 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/ModelStandardIndexedDirector.java	Fri Aug 16 21:18:21 2013 +0400
@@ -24,6 +24,8 @@
  */
 package com.sun.media.sound;
 
+import java.util.Arrays;
+
 /**
  * A standard indexed director who chooses performers
  * by there keyfrom,keyto,velfrom,velto properties.
@@ -32,22 +34,21 @@
  */
 public final class ModelStandardIndexedDirector implements ModelDirector {
 
-    ModelPerformer[] performers;
-    ModelDirectedPlayer player;
-    boolean noteOnUsed = false;
-    boolean noteOffUsed = false;
+    private final ModelPerformer[] performers;
+    private final ModelDirectedPlayer player;
+    private boolean noteOnUsed = false;
+    private boolean noteOffUsed = false;
 
     // Variables needed for index
-    byte[][] trantables;
-    int[] counters;
-    int[][] mat;
+    private byte[][] trantables;
+    private int[] counters;
+    private int[][] mat;
 
-    public ModelStandardIndexedDirector(ModelPerformer[] performers,
-            ModelDirectedPlayer player) {
-        this.performers = performers;
+    public ModelStandardIndexedDirector(final ModelPerformer[] performers,
+                                        final ModelDirectedPlayer player) {
+        this.performers = Arrays.copyOf(performers, performers.length);
         this.player = player;
-        for (int i = 0; i < performers.length; i++) {
-            ModelPerformer p = performers[i];
+        for (final ModelPerformer p : this.performers) {
             if (p.isReleaseTriggered()) {
                 noteOffUsed = true;
             } else {
--- a/jdk/src/share/classes/com/sun/media/sound/SoftMixingClip.java	Fri Aug 16 20:56:46 2013 +0400
+++ b/jdk/src/share/classes/com/sun/media/sound/SoftMixingClip.java	Fri Aug 16 21:18:21 2013 +0400
@@ -38,7 +38,7 @@
 import javax.sound.sampled.LineUnavailableException;
 
 /**
- * Clip implemention for the SoftMixingMixer.
+ * Clip implementation for the SoftMixingMixer.
  *
  * @author Karl Helgason
  */
@@ -357,7 +357,9 @@
                 throw new IllegalArgumentException(
                         "Buffer size does not represent an integral number of sample frames!");
 
-            this.data = data;
+            if (data != null) {
+                this.data = Arrays.copyOf(data, data.length);
+            }
             this.offset = offset;
             this.bufferSize = bufferSize;
             this.format = format;
--- a/jdk/src/share/classes/sun/audio/AudioData.java	Fri Aug 16 20:56:46 2013 +0400
+++ b/jdk/src/share/classes/sun/audio/AudioData.java	Fri Aug 16 21:18:21 2013 +0400
@@ -26,6 +26,8 @@
 package sun.audio;
 
 import java.io.*;
+import java.util.Arrays;
+
 import javax.sound.sampled.*;
 
 
@@ -65,12 +67,11 @@
     /**
      * Constructor
      */
-    public AudioData(byte buffer[]) {
-
-        this.buffer = buffer;
-        // if we cannot extract valid format information, we resort to assuming the data will be 8k mono u-law
-        // in order to provide maximal backwards compatibility....
-        this.format = DEFAULT_FORMAT;
+    public AudioData(final byte[] buffer) {
+        // if we cannot extract valid format information, we resort to assuming
+        // the data will be 8k mono u-law in order to provide maximal backwards
+        // compatibility....
+        this(DEFAULT_FORMAT, buffer);
 
         // okay, we need to extract the format and the byte buffer of data
         try {
@@ -90,9 +91,10 @@
      * Non-public constructor; this is the one we use in ADS and CADS
      * constructors.
      */
-    AudioData(AudioFormat format, byte[] buffer) {
-
+    AudioData(final AudioFormat format, final byte[] buffer) {
         this.format = format;
-        this.buffer = buffer;
+        if (buffer != null) {
+            this.buffer = Arrays.copyOf(buffer, buffer.length);
+        }
     }
 }