From 27d3451a4638f49827da49cc255fa7d0a2d86df1 Mon Sep 17 00:00:00 2001 From: serb Date: Fri, 16 Aug 2013 21:18:21 +0400 Subject: [PATCH] 8005980: [findbugs] More com.sun.media.sound.* warnings Reviewed-by: art, prr --- .../com/sun/media/sound/DataPusher.java | 26 ++++++++++++------- .../media/sound/ModelStandardDirector.java | 19 +++++++------- .../sound/ModelStandardIndexedDirector.java | 25 +++++++++--------- .../com/sun/media/sound/SoftMixingClip.java | 6 +++-- src/share/classes/sun/audio/AudioData.java | 20 +++++++------- 5 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/share/classes/com/sun/media/sound/DataPusher.java b/src/share/classes/com/sun/media/sound/DataPusher.java index 814a0150b..95c0ff9f0 100644 --- a/src/share/classes/com/sun/media/sound/DataPusher.java +++ b/src/share/classes/com/sun/media/sound/DataPusher.java @@ -25,6 +25,8 @@ package com.sun.media.sound; +import java.util.Arrays; + import javax.sound.sampled.*; /** @@ -46,11 +48,11 @@ public final class DataPusher implements Runnable { 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 @@ public final class DataPusher implements Runnable { 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() { diff --git a/src/share/classes/com/sun/media/sound/ModelStandardDirector.java b/src/share/classes/com/sun/media/sound/ModelStandardDirector.java index e64d94cd4..115f28a6f 100644 --- a/src/share/classes/com/sun/media/sound/ModelStandardDirector.java +++ b/src/share/classes/com/sun/media/sound/ModelStandardDirector.java @@ -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 @@ package com.sun.media.sound; */ 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 { diff --git a/src/share/classes/com/sun/media/sound/ModelStandardIndexedDirector.java b/src/share/classes/com/sun/media/sound/ModelStandardIndexedDirector.java index a5171eb1f..a0c2aff39 100644 --- a/src/share/classes/com/sun/media/sound/ModelStandardIndexedDirector.java +++ b/src/share/classes/com/sun/media/sound/ModelStandardIndexedDirector.java @@ -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 @@ package com.sun.media.sound; */ 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 { diff --git a/src/share/classes/com/sun/media/sound/SoftMixingClip.java b/src/share/classes/com/sun/media/sound/SoftMixingClip.java index bcf67f3b5..748b0eb3e 100644 --- a/src/share/classes/com/sun/media/sound/SoftMixingClip.java +++ b/src/share/classes/com/sun/media/sound/SoftMixingClip.java @@ -38,7 +38,7 @@ import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineUnavailableException; /** - * Clip implemention for the SoftMixingMixer. + * Clip implementation for the SoftMixingMixer. * * @author Karl Helgason */ @@ -357,7 +357,9 @@ public final class SoftMixingClip extends SoftMixingDataLine implements Clip { 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; diff --git a/src/share/classes/sun/audio/AudioData.java b/src/share/classes/sun/audio/AudioData.java index 023fd3a93..670387694 100644 --- a/src/share/classes/sun/audio/AudioData.java +++ b/src/share/classes/sun/audio/AudioData.java @@ -26,6 +26,8 @@ package sun.audio; import java.io.*; +import java.util.Arrays; + import javax.sound.sampled.*; @@ -65,12 +67,11 @@ public final class AudioData { /** * 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 @@ public final class AudioData { * 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); + } } } -- GitLab