Compare commits
2 Commits
27c6eebde8
...
0e921237d2
Author | SHA1 | Date | |
---|---|---|---|
|
0e921237d2 | ||
|
af967ded87 |
@ -431,7 +431,6 @@ public class AquaInternalFrameUI extends BasicInternalFrameUI implements SwingCo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public void mouseReleased(final MouseEvent e) {
|
public void mouseReleased(final MouseEvent e) {
|
||||||
if (didForwardEvent(e)) return;
|
if (didForwardEvent(e)) return;
|
||||||
|
|
||||||
|
@ -91,7 +91,6 @@ public class SwingUtilities3 {
|
|||||||
* @param rootContainer topmost container. Should be {@code Window}
|
* @param rootContainer topmost container. Should be {@code Window}
|
||||||
* @param isRequested the value to set vsyncRequested state to
|
* @param isRequested the value to set vsyncRequested state to
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static void setVsyncRequested(Container rootContainer,
|
public static void setVsyncRequested(Container rootContainer,
|
||||||
boolean isRequested) {
|
boolean isRequested) {
|
||||||
assert (rootContainer instanceof Window);
|
assert (rootContainer instanceof Window);
|
||||||
@ -108,7 +107,6 @@ public class SwingUtilities3 {
|
|||||||
* @param rootContainer topmost container. Should be Window
|
* @param rootContainer topmost container. Should be Window
|
||||||
* @return {@code true} if vsync painting is requested for {@code rootContainer}
|
* @return {@code true} if vsync painting is requested for {@code rootContainer}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static boolean isVsyncRequested(Container rootContainer) {
|
public static boolean isVsyncRequested(Container rootContainer) {
|
||||||
assert (rootContainer instanceof Window);
|
assert (rootContainer instanceof Window);
|
||||||
return Boolean.TRUE == vsyncedMap.get(rootContainer);
|
return Boolean.TRUE == vsyncedMap.get(rootContainer);
|
||||||
|
@ -58,7 +58,6 @@ import javax.sound.sampled.UnsupportedAudioFileException;
|
|||||||
* @author Arthur van Hoff, Kara Kytle, Jan Borgersen
|
* @author Arthur van Hoff, Kara Kytle, Jan Borgersen
|
||||||
* @author Florian Bomers
|
* @author Florian Bomers
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public final class JavaSoundAudioClip implements MetaEventListener, LineListener {
|
public final class JavaSoundAudioClip implements MetaEventListener, LineListener {
|
||||||
|
|
||||||
private long lastPlayCall = 0;
|
private long lastPlayCall = 0;
|
||||||
|
@ -607,7 +607,6 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
* @see #setComponentPopupMenu
|
* @see #setComponentPopupMenu
|
||||||
* @since 1.5
|
* @since 1.5
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public JPopupMenu getComponentPopupMenu() {
|
public JPopupMenu getComponentPopupMenu() {
|
||||||
|
|
||||||
if(!getInheritsPopupMenu()) {
|
if(!getInheritsPopupMenu()) {
|
||||||
@ -2966,7 +2965,7 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
* @param pressed true if the key is pressed
|
* @param pressed true if the key is pressed
|
||||||
* @return true if there is a key binding for <code>e</code>
|
* @return true if there is a key binding for <code>e</code>
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({"deprecation", "removal"})
|
@SuppressWarnings("deprecation")
|
||||||
boolean processKeyBindings(KeyEvent e, boolean pressed) {
|
boolean processKeyBindings(KeyEvent e, boolean pressed) {
|
||||||
if (!SwingUtilities.isValidKeyEventForKeyBindings(e)) {
|
if (!SwingUtilities.isValidKeyEventForKeyBindings(e)) {
|
||||||
return false;
|
return false;
|
||||||
@ -4521,7 +4520,6 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
* return value for this method
|
* return value for this method
|
||||||
* @see #getVisibleRect
|
* @see #getVisibleRect
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
static final void computeVisibleRect(Component c, Rectangle visibleRect) {
|
static final void computeVisibleRect(Component c, Rectangle visibleRect) {
|
||||||
Container p = c.getParent();
|
Container p = c.getParent();
|
||||||
Rectangle bounds = c.getBounds();
|
Rectangle bounds = c.getBounds();
|
||||||
@ -4681,7 +4679,7 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the top-level ancestor of this component (either the
|
* Returns the top-level ancestor of this component (the
|
||||||
* containing <code>Window</code>)
|
* containing <code>Window</code>)
|
||||||
* or <code>null</code> if this component has not
|
* or <code>null</code> if this component has not
|
||||||
* been added to any container.
|
* been added to any container.
|
||||||
@ -4690,7 +4688,6 @@ public abstract class JComponent extends Container implements Serializable,
|
|||||||
* or <code>null</code> if not in any container
|
* or <code>null</code> if not in any container
|
||||||
*/
|
*/
|
||||||
@BeanProperty(bound = false)
|
@BeanProperty(bound = false)
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public Container getTopLevelAncestor() {
|
public Container getTopLevelAncestor() {
|
||||||
for(Container p = this; p != null; p = p.getParent()) {
|
for(Container p = this; p != null; p = p.getParent()) {
|
||||||
if(p instanceof Window) {
|
if(p instanceof Window) {
|
||||||
|
@ -6121,7 +6121,6 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
|
|||||||
this.focusManager = fm;
|
this.focusManager = fm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public void propertyChange(PropertyChangeEvent ev) {
|
public void propertyChange(PropertyChangeEvent ev) {
|
||||||
if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) {
|
if (!isEditing() || getClientProperty("terminateEditOnFocusLost") != Boolean.TRUE) {
|
||||||
return;
|
return;
|
||||||
|
@ -134,7 +134,6 @@ class KeyboardManager {
|
|||||||
/**
|
/**
|
||||||
* Find the top focusable Window, or InternalFrame
|
* Find the top focusable Window, or InternalFrame
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private static Container getTopAncestor(JComponent c) {
|
private static Container getTopAncestor(JComponent c) {
|
||||||
for(Container p = c.getParent(); p != null; p = p.getParent()) {
|
for(Container p = c.getParent(); p != null; p = p.getParent()) {
|
||||||
if (p instanceof Window && ((Window)p).isFocusableWindow() ||
|
if (p instanceof Window && ((Window)p).isFocusableWindow() ||
|
||||||
|
@ -273,7 +273,6 @@ public class PopupFactory {
|
|||||||
* Obtains the appropriate <code>Popup</code> based on
|
* Obtains the appropriate <code>Popup</code> based on
|
||||||
* <code>popupType</code>.
|
* <code>popupType</code>.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private Popup getPopup(Component owner, Component contents,
|
private Popup getPopup(Component owner, Component contents,
|
||||||
int ownerX, int ownerY, int popupType) {
|
int ownerX, int ownerY, int popupType) {
|
||||||
if (GraphicsEnvironment.isHeadless()) {
|
if (GraphicsEnvironment.isHeadless()) {
|
||||||
@ -621,7 +620,6 @@ public class PopupFactory {
|
|||||||
* Returns true if popup can fit the screen and the owner's top parent.
|
* Returns true if popup can fit the screen and the owner's top parent.
|
||||||
* It determines can popup be lightweight or mediumweight.
|
* It determines can popup be lightweight or mediumweight.
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
boolean fitsOnScreen() {
|
boolean fitsOnScreen() {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
Component component = getComponent();
|
Component component = getComponent();
|
||||||
@ -784,7 +782,6 @@ public class PopupFactory {
|
|||||||
recycleLightWeightPopup(this);
|
recycleLightWeightPopup(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public void show() {
|
public void show() {
|
||||||
Container parent = null;
|
Container parent = null;
|
||||||
|
|
||||||
@ -932,7 +929,6 @@ public class PopupFactory {
|
|||||||
recycleMediumWeightPopup(this);
|
recycleMediumWeightPopup(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public void show() {
|
public void show() {
|
||||||
Component component = getComponent();
|
Component component = getComponent();
|
||||||
Container parent = null;
|
Container parent = null;
|
||||||
|
@ -405,7 +405,6 @@ public class RepaintManager
|
|||||||
*
|
*
|
||||||
* @see JComponent#repaint
|
* @see JComponent#repaint
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private void addDirtyRegion0(Container c, int x, int y, int w, int h) {
|
private void addDirtyRegion0(Container c, int x, int y, int w, int h) {
|
||||||
/* Special cases we don't have to bother with.
|
/* Special cases we don't have to bother with.
|
||||||
*/
|
*/
|
||||||
@ -507,7 +506,6 @@ public class RepaintManager
|
|||||||
addDirtyRegion0(window, x, y, w, h);
|
addDirtyRegion0(window, x, y, w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
void scheduleHeavyWeightPaints() {
|
void scheduleHeavyWeightPaints() {
|
||||||
Map<Container,Rectangle> hws;
|
Map<Container,Rectangle> hws;
|
||||||
|
|
||||||
|
@ -414,7 +414,6 @@ public class SwingUtilities implements SwingConstants
|
|||||||
* @param p a Point object (converted to the new coordinate system)
|
* @param p a Point object (converted to the new coordinate system)
|
||||||
* @param c a Component object
|
* @param c a Component object
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static void convertPointToScreen(Point p,Component c) {
|
public static void convertPointToScreen(Point p,Component c) {
|
||||||
Rectangle b;
|
Rectangle b;
|
||||||
int x,y;
|
int x,y;
|
||||||
@ -453,7 +452,6 @@ public class SwingUtilities implements SwingConstants
|
|||||||
* @param p a Point object (converted to the new coordinate system)
|
* @param p a Point object (converted to the new coordinate system)
|
||||||
* @param c a Component object
|
* @param c a Component object
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static void convertPointFromScreen(Point p,Component c) {
|
public static void convertPointFromScreen(Point p,Component c) {
|
||||||
Rectangle b;
|
Rectangle b;
|
||||||
int x,y;
|
int x,y;
|
||||||
@ -1653,7 +1651,6 @@ public class SwingUtilities implements SwingConstants
|
|||||||
* @param c the component
|
* @param c the component
|
||||||
* @return the first ancestor of c that's a Window
|
* @return the first ancestor of c that's a Window
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static Component getRoot(Component c) {
|
public static Component getRoot(Component c) {
|
||||||
for(Component p = c; p != null; p = p.getParent()) {
|
for(Component p = c; p != null; p = p.getParent()) {
|
||||||
if (p instanceof Window) {
|
if (p instanceof Window) {
|
||||||
@ -1690,7 +1687,6 @@ public class SwingUtilities implements SwingConstants
|
|||||||
* @return true if a binding has found and processed
|
* @return true if a binding has found and processed
|
||||||
* @since 1.4
|
* @since 1.4
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public static boolean processKeyBindings(KeyEvent event) {
|
public static boolean processKeyBindings(KeyEvent event) {
|
||||||
if (event != null) {
|
if (event != null) {
|
||||||
if (event.isConsumed()) {
|
if (event.isConsumed()) {
|
||||||
@ -2204,7 +2200,6 @@ public class SwingUtilities implements SwingConstants
|
|||||||
* @see java.awt.Component#isVisible()
|
* @see java.awt.Component#isVisible()
|
||||||
* @since 1.7
|
* @since 1.7
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("removal")
|
|
||||||
static Container getValidateRoot(Container c, boolean visibleOnly) {
|
static Container getValidateRoot(Container c, boolean visibleOnly) {
|
||||||
Container root = null;
|
Container root = null;
|
||||||
|
|
||||||
|
@ -794,7 +794,6 @@ public final class ToolTipManager extends MouseAdapter implements MouseMotionLis
|
|||||||
// Returns: 0 no adjust
|
// Returns: 0 no adjust
|
||||||
// -1 can't fit
|
// -1 can't fit
|
||||||
// >0 adjust value by amount returned
|
// >0 adjust value by amount returned
|
||||||
@SuppressWarnings("removal")
|
|
||||||
private int getPopupFitWidth(Rectangle popupRectInScreen, Component invoker){
|
private int getPopupFitWidth(Rectangle popupRectInScreen, Component invoker){
|
||||||
if (invoker != null){
|
if (invoker != null){
|
||||||
Container parent;
|
Container parent;
|
||||||
|
@ -914,7 +914,6 @@ public class BasicPopupMenuUI extends PopupMenuUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
boolean isInPopup(Component src) {
|
boolean isInPopup(Component src) {
|
||||||
for (Component c=src; c!=null; c=c.getParent()) {
|
for (Component c=src; c!=null; c=c.getParent()) {
|
||||||
if (c instanceof Window) {
|
if (c instanceof Window) {
|
||||||
@ -1129,7 +1128,6 @@ public class BasicPopupMenuUI extends PopupMenuUI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("removal")
|
|
||||||
public void stateChanged(ChangeEvent ev) {
|
public void stateChanged(ChangeEvent ev) {
|
||||||
if (!(UIManager.getLookAndFeel() instanceof BasicLookAndFeel)) {
|
if (!(UIManager.getLookAndFeel() instanceof BasicLookAndFeel)) {
|
||||||
uninstall();
|
uninstall();
|
||||||
|
128
test/jdk/javax/sound/sampled/Clip/AutoCloseTimeCheck.java
Normal file
128
test/jdk/javax/sound/sampled/Clip/AutoCloseTimeCheck.java
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import javax.sound.SoundClip;
|
||||||
|
import javax.sound.sampled.AudioFileFormat.Type;
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
|
||||||
|
import static javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED;
|
||||||
|
import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
* @bug 8202264
|
||||||
|
*/
|
||||||
|
public final class AutoCloseTimeCheck {
|
||||||
|
|
||||||
|
public static void main(final String[] args) throws Exception {
|
||||||
|
// Prepare the audio file
|
||||||
|
File file = new File("audio.wav");
|
||||||
|
try {
|
||||||
|
AudioFormat format =
|
||||||
|
new AudioFormat(PCM_SIGNED, 44100, 8, 1, 1, 44100, false);
|
||||||
|
AudioSystem.write(getStream(format), Type.WAVE, file);
|
||||||
|
} catch (final Exception ignored) {
|
||||||
|
return; // the test is not applicable
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
testSmallDelay(file);
|
||||||
|
testBigDelay(file);
|
||||||
|
} finally {
|
||||||
|
Files.delete(file.toPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that after a big period of non-activity the clip will be closed
|
||||||
|
* and the "Direct Clip" thread will stop.
|
||||||
|
*/
|
||||||
|
private static void testBigDelay(final File file) throws Exception {
|
||||||
|
SoundClip clip = SoundClip.createSoundClip(file);
|
||||||
|
clip.loop();
|
||||||
|
clip.stop();
|
||||||
|
sleep(20000); // 20 sec for slow systems
|
||||||
|
if (count() != 0) {
|
||||||
|
throw new RuntimeException("Thread was found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks that after small period of non-activity the clip will not be
|
||||||
|
* closed and the "Direct Clip" thread will alive.
|
||||||
|
*/
|
||||||
|
private static void testSmallDelay(final File file) throws IOException {
|
||||||
|
SoundClip clip = SoundClip.createSoundClip(file);
|
||||||
|
long threadID = 0;
|
||||||
|
// Will run the test no more than 15 seconds
|
||||||
|
long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(15);
|
||||||
|
while (endtime - System.nanoTime() > 0) {
|
||||||
|
clip.loop();
|
||||||
|
sleep(500);
|
||||||
|
|
||||||
|
long data = count();
|
||||||
|
if (data != threadID) {
|
||||||
|
System.out.println("Playing on new thread: " + data + " at "
|
||||||
|
+ new java.util.Date());
|
||||||
|
if (threadID == 0) {
|
||||||
|
threadID = data;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("Thread was changed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
clip.stop();
|
||||||
|
sleep(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void sleep(int millis) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(millis);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static long count() {
|
||||||
|
for (final Thread t : Thread.getAllStackTraces().keySet()) {
|
||||||
|
if (t.getName().equals("Direct Clip")) {
|
||||||
|
return t.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AudioInputStream getStream(final AudioFormat format) {
|
||||||
|
final int dataSize = 5000 * format.getFrameSize();
|
||||||
|
final InputStream in = new ByteArrayInputStream(new byte[dataSize]);
|
||||||
|
return new AudioInputStream(in, format, NOT_SPECIFIED);
|
||||||
|
}
|
||||||
|
}
|
95
test/jdk/javax/sound/sampled/Clip/DataPusherThreadCheck.java
Normal file
95
test/jdk/javax/sound/sampled/Clip/DataPusherThreadCheck.java
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
|
||||||
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
|
*
|
||||||
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU General Public License version 2 only, as
|
||||||
|
* published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||||
|
* version 2 for more details (a copy is included in the LICENSE file that
|
||||||
|
* accompanied this code).
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License version
|
||||||
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||||
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
*
|
||||||
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||||
|
* or visit www.oracle.com if you need additional information or have any
|
||||||
|
* questions.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import static javax.sound.sampled.AudioFormat.Encoding.PCM_SIGNED;
|
||||||
|
import static javax.sound.sampled.AudioSystem.NOT_SPECIFIED;
|
||||||
|
|
||||||
|
import javax.sound.sampled.AudioFileFormat;
|
||||||
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
import javax.sound.sampled.AudioInputStream;
|
||||||
|
import javax.sound.sampled.AudioSystem;
|
||||||
|
import javax.sound.sampled.Clip;
|
||||||
|
import javax.sound.sampled.DataLine;
|
||||||
|
import javax.sound.SoundClip;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @test
|
||||||
|
* @key headful
|
||||||
|
* @bug 8279673
|
||||||
|
* @summary Verify no NPE creating threads
|
||||||
|
* @run main/othervm DataPusherThreadCheck
|
||||||
|
*/
|
||||||
|
public class DataPusherThreadCheck {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
// Prepare the audio file
|
||||||
|
File file = new File("audio.wav");
|
||||||
|
try {
|
||||||
|
AudioFormat format =
|
||||||
|
new AudioFormat(PCM_SIGNED, 44100, 8, 1, 1, 44100, false);
|
||||||
|
DataLine.Info info = new DataLine.Info(Clip.class, format);
|
||||||
|
if (!(AudioSystem.isLineSupported(info)) ) {
|
||||||
|
return; // the test is not applicable
|
||||||
|
}
|
||||||
|
int dataSize = 6000*1000 * format.getFrameSize();
|
||||||
|
InputStream in = new ByteArrayInputStream(new byte[dataSize]);
|
||||||
|
AudioInputStream audioStream = new AudioInputStream(in, format, NOT_SPECIFIED);
|
||||||
|
AudioSystem.write(audioStream, AudioFileFormat.Type.WAVE, file);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return; // the test is not applicable
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
checkThread(file);
|
||||||
|
} finally {
|
||||||
|
Files.delete(file.toPath());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void checkThread(File file) throws Exception {
|
||||||
|
SoundClip clip = SoundClip.createSoundClip(file);
|
||||||
|
clip.loop();
|
||||||
|
try {
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException ignored) {
|
||||||
|
}
|
||||||
|
boolean found = isDataPushedThreadExist();
|
||||||
|
clip.stop();
|
||||||
|
if (!found) {
|
||||||
|
throw new RuntimeException("Thread 'DataPusher' isn't found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean isDataPushedThreadExist() {
|
||||||
|
for (Thread t : Thread.getAllStackTraces().keySet()) {
|
||||||
|
if (t.getName().equals("DataPusher")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user