undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
109
test/jdk/java/awt/Button/ActionEventTest/ActionEventTest.java
Normal file
109
test/jdk/java/awt/Button/ActionEventTest/ActionEventTest.java
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6191390
|
||||
* @summary Verify that ActionEvent is received with correct modifiers set.
|
||||
* @run main/manual ActionEventTest
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Button;
|
||||
import java.awt.TextArea;
|
||||
import java.awt.Robot;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class ActionEventTest extends Frame {
|
||||
Button button;
|
||||
Robot robot;
|
||||
TextArea instructions;
|
||||
public static boolean isProgInterruption = false;
|
||||
static Thread mainThread = null;
|
||||
static int sleepTime = 300000;
|
||||
|
||||
public ActionEventTest() {
|
||||
try {
|
||||
robot = new Robot();
|
||||
} catch(AWTException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
button = new Button("ClickMe");
|
||||
button.setEnabled(true);
|
||||
|
||||
instructions = new TextArea(10, 50);
|
||||
instructions.setText(
|
||||
" This is a manual test\n" +
|
||||
" Keep the Alt, Shift & Ctrl Keys pressed &\n" +
|
||||
" Click 'ClickMe' button with left mouse button\n" +
|
||||
" Test exits automatically after mouse click.");
|
||||
|
||||
add(button);
|
||||
add(instructions);
|
||||
setSize(400,400);
|
||||
setLayout(new FlowLayout());
|
||||
pack();
|
||||
setVisible(true);
|
||||
robot.waitForIdle();
|
||||
|
||||
button.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent ae) {
|
||||
int md = ae.getModifiers();
|
||||
int expectedMask = ActionEvent.ALT_MASK | ActionEvent.CTRL_MASK
|
||||
| ActionEvent.SHIFT_MASK;
|
||||
|
||||
isProgInterruption = true;
|
||||
mainThread.interrupt();
|
||||
if ((md & expectedMask) != expectedMask) {
|
||||
throw new RuntimeException("Action Event modifiers"
|
||||
+ " are not set correctly.");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
mainThread = Thread.currentThread();
|
||||
ActionEventTest test = new ActionEventTest();
|
||||
try {
|
||||
mainThread.sleep(sleepTime);
|
||||
} catch (InterruptedException e) {
|
||||
if (!isProgInterruption) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
test.dispose();
|
||||
if (!isProgInterruption) {
|
||||
throw new RuntimeException("Timed out after " + sleepTime / 1000
|
||||
+ " seconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2001, 2024, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4530087
|
||||
* @summary Test if double-clicking causes ActionEvent on underlying button
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @run main/manual BadActionEventTest
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.Color;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
public class BadActionEventTest implements ActionListener {
|
||||
private static Button showBtn;
|
||||
private static Button listBtn;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
String INSTRUCTIONS = """
|
||||
1) Click on 'Show File Dialog' to bring up the FileDialog window.
|
||||
(If necessary, change to a directory with files (not just directories) in it.)
|
||||
2) Move the FileDialog so that one of the file names (again, a file, NOT a directory) in the list is
|
||||
directly over the 'ActionListener' button.
|
||||
3) Double-click on the file name over the button. The FileDialog will disappear.
|
||||
4) If the 'ActionListener' button receives an ActionEvent, the test fails and a
|
||||
message to that effect will be printed.
|
||||
Otherwise, the test passes.
|
||||
""";
|
||||
|
||||
PassFailJFrame.builder()
|
||||
.title("Test Instructions")
|
||||
.instructions(INSTRUCTIONS)
|
||||
.columns(45)
|
||||
.testUI(BadActionEventTest::createUI)
|
||||
.logArea(2)
|
||||
.build()
|
||||
.awaitAndCheck();
|
||||
}
|
||||
|
||||
private static Frame createUI() {
|
||||
Frame frame = new Frame("BadActionEventTest");
|
||||
frame.setLayout(new GridLayout(1, 2));
|
||||
frame.setSize(400, 200);
|
||||
showBtn = new Button("Show File Dialog");
|
||||
listBtn = new Button("ActionListener");
|
||||
showBtn.setSize(200, 200);
|
||||
listBtn.setSize(200, 200);
|
||||
showBtn.addActionListener(new BadActionEventTest());
|
||||
listBtn.addActionListener(new BadActionEventTest());
|
||||
frame.add(showBtn);
|
||||
frame.add(listBtn);
|
||||
return frame;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (e.getSource() == showBtn) {
|
||||
FileDialog fd = new FileDialog(new Frame());
|
||||
fd.setVisible(true);
|
||||
} else if (e.getSource() == listBtn) {
|
||||
listBtn.setBackground(Color.red);
|
||||
listBtn.setLabel("TEST FAILS!");
|
||||
PassFailJFrame.log("*TEST FAILS!* ActionListener got ActionEvent! *TEST FAILS!*");
|
||||
}
|
||||
}
|
||||
}
|
||||
94
test/jdk/java/awt/Button/ButtonNullLabelTest.java
Normal file
94
test/jdk/java/awt/Button/ButtonNullLabelTest.java
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* Copyright (c) 1999, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4245382
|
||||
@summary Tests that Button.setLabel(null) does not cause NPE in Java code or VM crash
|
||||
@key headful
|
||||
*/
|
||||
|
||||
import java.awt.Button;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
|
||||
public class ButtonNullLabelTest {
|
||||
|
||||
public static void main(String args[]) throws Exception {
|
||||
EventQueue.invokeAndWait(() -> runTest());
|
||||
}
|
||||
|
||||
static void runTest() {
|
||||
// Native code test
|
||||
Frame frame = new Frame("Test null in native");
|
||||
Button button = new Button();
|
||||
try {
|
||||
button.setLabel(null);
|
||||
System.out.println("Set to null - test native");
|
||||
frame.add(button);
|
||||
frame.pack();
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setVisible(true);
|
||||
System.out.println("Test null in native **successful**");
|
||||
} catch (NullPointerException npe) {
|
||||
System.out.println("Test failed - test native");
|
||||
throw new RuntimeException("Test failed - test native");
|
||||
} finally {
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
// Peer code test
|
||||
frame = new Frame("Test null in peer before show");
|
||||
button = new Button();
|
||||
try {
|
||||
System.out.println("Set to null - test native before show");
|
||||
frame.add(button);
|
||||
frame.pack();
|
||||
button.setLabel(null);
|
||||
frame.setVisible(true);
|
||||
System.out.println("Set null in peer before show **successful**");
|
||||
} catch (NullPointerException npe) {
|
||||
System.out.println("Test failed - test peer before show");
|
||||
throw new RuntimeException("Test failed - test peer before show");
|
||||
} finally {
|
||||
frame.dispose();
|
||||
}
|
||||
|
||||
// Peer code test
|
||||
frame = new Frame("Test null in peer after show");
|
||||
button = new Button();
|
||||
try {
|
||||
System.out.println("Set to null - test peer after show");
|
||||
frame.add(button);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
button.setLabel(null);
|
||||
System.out.println("Test null in peer after show **successful**");
|
||||
} catch (NullPointerException npe) {
|
||||
System.out.println("Test failed - peer after show");
|
||||
throw new RuntimeException("Test failed - peer after show");
|
||||
} finally {
|
||||
frame.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
117
test/jdk/java/awt/Button/DisabledButtonPress.java
Normal file
117
test/jdk/java/awt/Button/DisabledButtonPress.java
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
* Copyright (c) 2005, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 5044469
|
||||
@summary REG: Disabled component gains focus and receives keyevents on win32
|
||||
@key headful
|
||||
*/
|
||||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Button;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.FocusListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public class DisabledButtonPress implements ActionListener, FocusListener {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
DisabledButtonPress test = new DisabledButtonPress();
|
||||
EventQueue.invokeAndWait(() -> test.createUI());
|
||||
runTest();
|
||||
} finally {
|
||||
if (f != null) {
|
||||
f.dispose();
|
||||
}
|
||||
}
|
||||
if (!testPassed) {
|
||||
throw new RuntimeException("Test Failed.");
|
||||
}
|
||||
}
|
||||
|
||||
final static Object FOCUS_LOCK = new Object();
|
||||
final static Object ACTION_LOCK = new Object();
|
||||
static volatile Frame f;
|
||||
static volatile Button b2;
|
||||
static volatile boolean testPassed = true;
|
||||
|
||||
public void createUI() {
|
||||
f = new Frame("DisabledButtonPress");
|
||||
b2 = new Button("Click Me");
|
||||
b2.addActionListener(this);
|
||||
b2.addFocusListener(this);
|
||||
f.add(b2);
|
||||
f.pack();
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
static void runTest() throws Exception {
|
||||
|
||||
Robot robot = new Robot();
|
||||
robot.delay(500);
|
||||
System.out.println("Requesting focus");
|
||||
System.out.println(" b2.requestFocusInWindow()="+ b2.requestFocusInWindow());
|
||||
b2.setEnabled(false);
|
||||
synchronized(FOCUS_LOCK) {
|
||||
FOCUS_LOCK.wait(3000);
|
||||
}
|
||||
if (!b2.isFocusOwner()) {
|
||||
throw new RuntimeException("Test failed. Button doesn't have a focus.");
|
||||
}
|
||||
System.out.println("Button disabling");
|
||||
robot.delay(1000);
|
||||
robot.keyPress(KeyEvent.VK_SPACE);
|
||||
robot.delay(10);
|
||||
robot.keyRelease(KeyEvent.VK_SPACE);
|
||||
synchronized(ACTION_LOCK) {
|
||||
ACTION_LOCK.wait(2000); //give time to handle
|
||||
// ACTION_PERFORMED event from the Button if it was generated
|
||||
}
|
||||
}
|
||||
|
||||
public void focusGained(FocusEvent ae) {
|
||||
System.out.println("Button got focus");
|
||||
synchronized(FOCUS_LOCK) {
|
||||
FOCUS_LOCK.notify();
|
||||
}
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent ae) {}
|
||||
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
System.out.println("Button: " + evt.getActionCommand() + " Clicked. Event is " +evt);
|
||||
if (evt.getSource() == b2) {
|
||||
testPassed = false;
|
||||
synchronized(ACTION_LOCK) {
|
||||
ACTION_LOCK.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
112
test/jdk/java/awt/Button/DoubleActionEventTest.java
Normal file
112
test/jdk/java/awt/Button/DoubleActionEventTest.java
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/*
|
||||
* Copyright (c) 2002, 2023, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
@test
|
||||
@bug 4531849
|
||||
@summary Test that double action event no longer sent
|
||||
@key headful
|
||||
*/
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.EventQueue;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Robot;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowListener;
|
||||
|
||||
public class DoubleActionEventTest implements ActionListener, WindowListener {
|
||||
|
||||
static class Lock {
|
||||
boolean go = false;
|
||||
public synchronized boolean getGo() {return go;}
|
||||
public synchronized void setGo(boolean newGo) {go = newGo;}
|
||||
}
|
||||
|
||||
static volatile Frame f;
|
||||
static volatile int numActionEvents = 0;
|
||||
static volatile Lock lock = new Lock();
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
try {
|
||||
DoubleActionEventTest test = new DoubleActionEventTest();
|
||||
EventQueue.invokeAndWait(() -> test.createUI());
|
||||
runTest();
|
||||
} finally {
|
||||
if (f != null) {
|
||||
f.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createUI() {
|
||||
f = new Frame("DoubleActionEventTest");
|
||||
f.setLayout (new BorderLayout());
|
||||
f.addWindowListener(this);
|
||||
Button b = new Button("Action Listening Button");
|
||||
b.addActionListener(this);
|
||||
f.add(b);
|
||||
f.setBounds(100, 100, 200, 200);
|
||||
f.setVisible(true);
|
||||
}
|
||||
|
||||
static void runTest() throws Exception {
|
||||
|
||||
Robot robot = new Robot();
|
||||
robot.setAutoDelay(250);
|
||||
robot.setAutoWaitForIdle(true);
|
||||
robot.mouseMove(200, 200);
|
||||
|
||||
while (!lock.getGo()) {}
|
||||
|
||||
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
|
||||
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
||||
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
|
||||
|
||||
if (numActionEvents != 1) {
|
||||
System.out.println("Wrong number of ActionEvents. Test FAILS.");
|
||||
throw new RuntimeException("TEST FAILS");
|
||||
}
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
numActionEvents++;
|
||||
System.out.println("Number of ActionEvents: " + numActionEvents);
|
||||
}
|
||||
|
||||
public void windowActivated(WindowEvent e) {
|
||||
lock.setGo(true);
|
||||
}
|
||||
public void windowClosed(WindowEvent e) {}
|
||||
public void windowClosing(WindowEvent e) {}
|
||||
public void windowDeactivated(WindowEvent e) {}
|
||||
public void windowDeiconified(WindowEvent e) {}
|
||||
public void windowIconified(WindowEvent e) {}
|
||||
public void windowOpened(WindowEvent e) {}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue