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:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -0,0 +1,74 @@
/*
* 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 4257944
@summary PopupMenu.setEnabled fails on Win32
@key headful
@run main EnableTest
*/
import java.awt.AWTEvent;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.MenuItem;
import java.awt.PopupMenu;
public class EnableTest {
PopupMenu popup = null;
Frame frame;
public static void main(String[] args) throws Exception {
EnableTest test = new EnableTest();
test.start();
}
public void start() throws Exception {
try {
EventQueue.invokeAndWait(() -> {
frame = new Frame("EnableTest");
popup = new PopupMenu("Popup Menu Title");
MenuItem mi1 = new MenuItem("Menu Item");
MenuItem mi2 = new MenuItem("Menu Item");
popup.add(mi1);
popup.addSeparator();
popup.add(mi2);
popup.setEnabled(false);
popup.setLabel("New Label");
mi2.setEnabled(false);
frame.add(popup);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
} finally {
EventQueue.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}

View file

@ -0,0 +1,83 @@
/*
* Copyright (c) 2002, 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.
*/
import java.awt.Font;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
/*
* @test
* @bug 4700350
* @requires os.family != "mac"
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary Tests menu item font is big
* @run main/manual GiantFontTest
*/
public class GiantFontTest {
public static void main(String[] args) throws Exception {
String INSTRUCTIONS = """
A frame with one menu will appear.
On Linux, the menu's (present on menu bar) font should
be quite large (48 point).
If not, test fails.
On Windows, the menu's (present on menu bar) font
should be normal size.
If the menu text is clipped by the title bar, or is painted over
the title bar or client area, the test fails.
On both Windows and Linux, the menu items in the popup
menu should be large.
If so, test passes.""";
PassFailJFrame.builder()
.title("GiantFontTest")
.instructions(INSTRUCTIONS)
.rows((int) INSTRUCTIONS.lines().count() + 2)
.columns(40)
.testUI(GiantFontTest::createAndShowUI)
.build()
.awaitAndCheck();
}
private static Frame createAndShowUI() {
Font giantFont = new Font("Dialog", Font.PLAIN, 48);
Frame f = new Frame("GiantFontTest");
MenuBar mb = new MenuBar();
Menu m = new Menu("My font is too big!");
m.setFont(giantFont);
for (int i = 0; i < 5; i++) {
m.add(new MenuItem("Some MenuItems"));
}
mb.add(m);
f.setMenuBar(mb);
f.setSize(450, 400);
return f;
}
}

View file

@ -0,0 +1,117 @@
/*
* Copyright (c) 1998, 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.
*/
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
/*
* @test
* @bug 4175790
* @requires os.family == "windows"
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary Win32: Running out of command ids for menu items
* @run main/manual LotsOfMenuItemsTest
*/
public class LotsOfMenuItemsTest extends ComponentAdapter {
private static final int NUM_WINDOWS = 400;
private static TestFrame firstFrame;
public static void main(String[] args) throws Exception {
LotsOfMenuItemsTest obj = new LotsOfMenuItemsTest();
String INSTRUCTIONS = """
This test creates lots of frames with menu bars.
When it's done you will see two frames.
Try to select menu items from each of them.
If everything seems to work - test passed.
Click "Pass" button in the test harness window.
If test crashes on you - test failed.""";
PassFailJFrame.builder()
.title("LotsOfMenuItemsTest")
.instructions(INSTRUCTIONS)
.rows((int) INSTRUCTIONS.lines().count() + 2)
.columns(40)
.testUI(obj::createAndShowUI)
.build()
.awaitAndCheck();
}
private Frame createAndShowUI() {
firstFrame = new TestFrame("First frame");
firstFrame.addComponentListener(this);
return firstFrame;
}
@Override
public void componentShown(ComponentEvent e) {
final int x = firstFrame.getX();
final int y = firstFrame.getY() + firstFrame.getHeight() + 8;
TestFrame testFrame;
for (int i = 1; i < NUM_WINDOWS - 1; ++i) {
testFrame = new TestFrame("Running(" + i + ")...", x, y);
testFrame.setVisible(false);
testFrame.dispose();
}
testFrame = new TestFrame("Last Frame", x, y);
PassFailJFrame.addTestWindow(testFrame);
}
private static class TestFrame extends Frame {
static int n = 0;
public TestFrame(String title) {
this(title, 0, 0, false);
}
public TestFrame(String s, int x, int y) {
this(s, x, y, true);
}
private TestFrame(String title, int x, int y, boolean visible) {
super(title);
MenuBar mb = new MenuBar();
for (int i = 0; i < 10; ++i) {
Menu m = new Menu("Menu_" + (i + 1));
for (int j = 0; j < 20; ++j) {
MenuItem mi = new MenuItem("Menu item " + ++n);
m.add(mi);
}
mb.add(m);
}
setMenuBar(mb);
setLocation(x, y);
setSize(450, 150);
if (visible) {
setVisible(true);
}
}
}
}

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2000, 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.
*/
import java.awt.Font;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
/*
* @test
* @bug 4066657 8009454
* @requires os.family != "mac"
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary Tests that setting a font on the Menu with MenuItem takes effect.
* @run main/manual MenuSetFontTest
*/
public class MenuSetFontTest {
public static void main(String[] args) throws Exception {
String INSTRUCTIONS = """
Look at the menu in the upper left corner of the 'SetFont Test' frame.
Click on the "File" menu. You will see "menu item" item.
Press Pass if menu item is displayed using bold and large font,
otherwise press Fail.
If you do not see menu at all, press Fail.""";
PassFailJFrame.builder()
.title("MenuSetFontTest")
.instructions(INSTRUCTIONS)
.rows((int) INSTRUCTIONS.lines().count() + 2)
.columns(40)
.testUI(MenuSetFontTest::createAndShowUI)
.build()
.awaitAndCheck();
}
private static Frame createAndShowUI() {
Frame frame = new Frame("SetFont Test");
MenuBar menuBar = new MenuBar();
Menu menu = new Menu("File");
MenuItem item = new MenuItem("menu item");
menu.add(item);
menuBar.add(menu);
menuBar.setFont(new Font(Font.MONOSPACED, Font.BOLD, 24));
frame.setMenuBar(menuBar);
frame.setSize(300, 200);
return frame;
}
}

View file

@ -0,0 +1,112 @@
/*
* 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 4261935
@summary Menu display problem when changing the text of the menu(window 98)
@key headful
@run main MenuSetLabelTest
*/
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Robot;
public class MenuSetLabelTest {
Menu1 f;
public static void main(String[] args) throws Exception {
MenuSetLabelTest test = new MenuSetLabelTest();
test.start();
}
public void start() throws Exception {
try {
EventQueue.invokeAndWait(() -> {
f = new Menu1();
f.setTitle("MenuSetLabelTest");
f.setSize(300, 200);
f.setLocationRelativeTo(null);
f.setVisible(true);
});
Robot robot = new Robot();
robot.delay(1000);
robot.waitForIdle();
EventQueue.invokeAndWait(() -> {
f.changeMenuLabel();
});
} finally {
EventQueue.invokeAndWait(() -> {
if (f != null) {
f.dispose();
}
});
}
}
}
class Menu1 extends Frame {
String s1 = new String("short");
String s2 = new String("This is a long string");
String s3 = new String("Menu Item string");
MenuBar mb1 = new MenuBar();
Menu f = new Menu(s1);
Menu m = new Menu(s1);
boolean flag = true;
public Menu1()
{
for (int i = 0; i < 5; i++) {
m.add(new MenuItem(s3));
}
for (int i = 0; i < 10; i++) {
f.add(new MenuItem(s3));
}
mb1.add(f);
mb1.add(m);
setMenuBar(mb1);
}
public void changeMenuLabel() {
MenuBar mb = getMenuBar();
Menu m0 = mb.getMenu(0);
Menu m1 = mb.getMenu(1);
if (flag) {
m0.setLabel(s2);
m1.setLabel(s2);
} else {
m0.setLabel(s1);
m1.setLabel(s1);
}
flag = !flag;
}
}

View file

@ -0,0 +1,105 @@
/*
* Copyright (c) 1999, 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.
*/
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
* @test
* @bug 4251036
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary MenuItem setLabel(null/"") behaves differently under Win32 and Solaris
* @run main/manual NullOrEmptyStringLabelTest
*/
public class NullOrEmptyStringLabelTest {
public static void main(String[] args) throws Exception {
String INSTRUCTIONS = """
The bug is reproducible under Win32 and Solaris.
Setting 'null' and "" as a label of menu item
should set blank label on all platforms according to the specification.
But under Solaris setting "" as a label of menu item used to
cause some garbage to be set as label.
Under Win32 setting 'null' as a label used to result in
throwing NullPointerException.
If you see any of these things happen test fails otherwise
it passes.""";
PassFailJFrame.builder()
.title("NullOrEmptyStringLabelTest")
.instructions(INSTRUCTIONS)
.rows((int) INSTRUCTIONS.lines().count() + 2)
.columns(40)
.testUI(NullOrEmptyStringLabelTest::createAndShowUI)
.build()
.awaitAndCheck();
}
private static Frame createAndShowUI() {
Frame frame = new Frame("Null Or Empty String Label Test");
Menu menu = new Menu("Menu");
MenuItem mi = new MenuItem("Item");
MenuBar mb = new MenuBar();
Button button1 = new Button("Set MenuItem label to 'null'");
Button button2 = new Button("Set MenuItem label to \"\"");
Button button3 = new Button("Set MenuItem label to 'text'");
button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
System.out.println("Setting MenuItem label to null");
mi.setLabel(null);
}
});
button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
System.out.println("Setting MenuItem label to \"\"");
mi.setLabel("");
}
});
button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ev) {
System.out.println("Setting MenuItem label to 'text'");
mi.setLabel("text");
}
});
menu.add(mi);
mb.add(menu);
frame.add(button1, BorderLayout.NORTH);
frame.add(button2, BorderLayout.CENTER);
frame.add(button3, BorderLayout.SOUTH);
frame.setMenuBar(mb);
frame.setSize(200, 135);
return frame;
}
}

View file

@ -0,0 +1,186 @@
/*
* Copyright (c) 2023, 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.awt.EventQueue;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/*
* @test
* @key headful
* @bug 4234266
* @summary To test setLabel functionality on Windows.
* @requires (os.family == "windows")
*/
public class SetLabelTest {
private static Robot robot;
private static Frame frame;
private static MenuBar mb;
private static PopupMenu pm;
private static Point frameLoc;
private static final StringBuffer errorLog = new StringBuffer();
public static void main(String[] args) throws Exception {
try {
robot = new Robot();
EventQueue.invokeAndWait(() -> createTestUI());
robot.delay(1000);
EventQueue.invokeAndWait(() -> frameLoc = frame.getLocationOnScreen());
checkMenu();
checkPopupMenu();
robot.delay(200);
if (!errorLog.isEmpty()) {
throw new RuntimeException("Before & After screenshots are same." +
" Test fails for the following case(s):\n" + errorLog);
}
} finally {
EventQueue.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
private static void createTestUI() {
frame = new Frame("Menu SetLabel Test");
frame.setUndecorated(true);
mb = new MenuBar();
//Menu 1
Menu menu1 = new Menu("Menu");
MenuItem mi1 = new MenuItem("Item-1");
menu1.add(mi1);
menu1.addSeparator();
MenuItem mi2 = new MenuItem("Item-2");
menu1.add(mi2);
mb.add(menu1);
//Popup menu
pm = new PopupMenu("Popup");
MenuItem pm1 = new MenuItem("Item-1");
pm.add(pm1);
pm.addSeparator();
MenuItem pm2 = new MenuItem("Item-2");
pm.add(pm2);
frame.add(pm);
frame.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
showPopup(e);
}
@Override
public void mouseReleased(MouseEvent e) {
showPopup(e);
}
private void showPopup(MouseEvent e) {
if (e.isPopupTrigger()) {
pm.show(e.getComponent(),
e.getX(), e.getY());
}
}
});
frame.setMenuBar(mb);
frame.setSize(300, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void checkMenu() throws IOException {
robot.mouseMove(frameLoc.x + 8, frameLoc.y + 8);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.delay(200);
BufferedImage beforeImgMenu = robot.createScreenCapture(frame.getBounds());
//Change Menu & MenuItem label
Menu m1 = mb.getMenu(0);
m1.setLabel("New Menu");
m1.getItem(0).setLabel("New Item-1");
m1.getItem(2).setLabel("New Item-2");
robot.delay(200);
BufferedImage afterImgMenu = robot.createScreenCapture(frame.getBounds());
if (compareImages(beforeImgMenu, afterImgMenu)) {
errorLog.append("Menu case\n");
ImageIO.write(beforeImgMenu, "png", new File("MenuBefore.png"));
ImageIO.write(afterImgMenu, "png", new File("MenuAfter.png"));
}
}
private static void checkPopupMenu() throws IOException {
robot.mouseMove(frameLoc.x + (frame.getWidth() / 2),
frameLoc.y + (frame.getHeight() /2));
robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
robot.delay(200);
BufferedImage beforeImgPopup = robot.createScreenCapture(frame.getBounds());
//Change popup menu label
pm.setLabel("Changed Popup");
pm.getItem(0).setLabel("New Item-1");
pm.getItem(2).setLabel("New Item-2");
robot.delay(200);
BufferedImage afterImgPopup = robot.createScreenCapture(frame.getBounds());
robot.mouseMove(frameLoc.x + (frame.getWidth() - 10),
frameLoc.y + (frame.getHeight() - 10));
robot.delay(100);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
if (compareImages(beforeImgPopup, afterImgPopup)) {
errorLog.append("Popup case\n");
ImageIO.write(beforeImgPopup, "png", new File("PopupBefore.png"));
ImageIO.write(afterImgPopup, "png", new File("PopupAfter.png"));
}
}
private static boolean compareImages(BufferedImage beforeImg, BufferedImage afterImg) {
for (int x = 0; x < beforeImg.getWidth(); x++) {
for (int y = 0; y < beforeImg.getHeight(); y++) {
if (beforeImg.getRGB(x, y) != afterImg.getRGB(x, y)) {
return false;
}
}
}
return true;
}
}

View file

@ -0,0 +1,70 @@
/*
* 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 4234266
@summary MenuItem throws NullPointer exception when setting the label with created peer.
@key headful
@run main SetLabelWithPeerCreatedTest
*/
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
public class SetLabelWithPeerCreatedTest {
Frame frame;
public static void main(String[] args) throws Exception {
SetLabelWithPeerCreatedTest test = new SetLabelWithPeerCreatedTest();
test.start();
}
public void start() throws Exception {
try {
EventQueue.invokeAndWait(() -> {
frame = new Frame("SetLabel with Peer Created Test");
Menu menu = new Menu("Menu");
MenuItem mi = new MenuItem("Item");
MenuBar mb = new MenuBar();
menu.add(mi);
mb.add(menu);
frame.setMenuBar(mb);
frame.setSize(300, 200);
frame.setLocationRelativeTo(null);
mi.setLabel("new label");
frame.setVisible(true);
System.out.println("Test PASSED!");
});
} finally {
EventQueue.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}

View file

@ -0,0 +1,70 @@
/*
* 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 5106833
@summary NullPointerException in XMenuPeer.repaintMenuItem
@key headful
@run main SetStateTest
*/
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.CheckboxMenuItem;
public class SetStateTest {
Frame frame;
public static void main(String[] args) throws Exception {
SetStateTest test = new SetStateTest();
test.start();
}
public void start () throws Exception {
try {
EventQueue.invokeAndWait(() -> {
frame = new Frame("SetStateTest");
MenuBar bar = new MenuBar();
Menu menu = new Menu("Menu");
CheckboxMenuItem checkboxMenuItem = new CheckboxMenuItem("Item");
bar.add(menu);
frame.setMenuBar(bar);
menu.add(checkboxMenuItem);
checkboxMenuItem.setState(true);
frame.setSize(300, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
System.out.println("Test PASSED!");
});
} finally {
EventQueue.invokeAndWait(() -> {
if (frame != null) {
frame.dispose();
}
});
}
}
}

View file

@ -0,0 +1,91 @@
/*
* Copyright (c) 1999, 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.
*/
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
/*
* @test
* @bug 4099695
* @library /java/awt/regtesthelpers
* @build PassFailJFrame
* @summary menu items with Unicode labels treated as separators
* @run main/manual UnicodeMenuItemTest
*/
public class UnicodeMenuItemTest {
public static void main(String[] args) throws Exception {
String INSTRUCTIONS = """
Click on the "Menu" on the top-left corner of frame.
The menu should have four entries:
1) a row of five unicode characters: \u00c4\u00cb\u00cf\u00d6\u00dc
2) a menu separator
3) a unicode character: \u012d
4) a unicode character: \u022d
If the menu items look like the list above, the test passes.
It is okay if the unicode characters look like empty boxes
or something - as long as they are not separators.
If either of the last two menu items show up as separators,
the test FAILS.
Press 'Pass' if above instructions hold good else press 'Fail'.""";
PassFailJFrame.builder()
.title("UnicodeMenuItemTest")
.instructions(INSTRUCTIONS)
.rows((int) INSTRUCTIONS.lines().count() + 2)
.columns(40)
.testUI(UnicodeMenuItemTest::createAndShowUI)
.build()
.awaitAndCheck();
}
private static Frame createAndShowUI() {
Frame frame = new Frame("Unicode MenuItem Test");
MenuBar mb = new MenuBar();
Menu m = new Menu("Menu");
MenuItem mi1 = new MenuItem("\u00c4\u00cb\u00cf\u00d6\u00dc");
m.add(mi1);
MenuItem separator = new MenuItem("-");
m.add(separator);
MenuItem mi2 = new MenuItem("\u012d");
m.add(mi2);
MenuItem mi3 = new MenuItem("\u022d");
m.add(mi3);
mb.add(m);
frame.setMenuBar(mb);
frame.setSize(450, 150);
return frame;
}
}