diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java index 8b95d8adc65..52f75055cfb 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/JFIFMarkerSegment.java @@ -376,6 +376,15 @@ void write(ImageOutputStream ios, } thumbWidth = Math.min(thumbWidth, MAX_THUMB_WIDTH); thumbHeight = Math.min(thumbHeight, MAX_THUMB_HEIGHT); + + int maxArea = (0xffff - DATA_SIZE - LENGTH_SIZE) / thumb.getSampleModel().getNumBands(); + if (thumbWidth * thumbHeight > maxArea) { + writer.warningOccurred(JPEGImageWriter.WARNING_THUMB_CLIPPED); + double scale = Math.sqrt( ((double)maxArea) / (double)(thumbWidth * thumbHeight) ); + thumbWidth = (int) (scale * thumbWidth); + thumbHeight = (int) (scale * thumbHeight); + } + thumbData = thumb.getRaster().getPixels(0, 0, thumbWidth, thumbHeight, (int []) null); diff --git a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/MarkerSegment.java b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/MarkerSegment.java index a0b4b871a04..f4ba27b0fcd 100644 --- a/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/MarkerSegment.java +++ b/src/java.desktop/share/classes/com/sun/imageio/plugins/jpeg/MarkerSegment.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -190,6 +190,9 @@ void write(ImageOutputStream ios) throws IOException { static void write2bytes(ImageOutputStream ios, int value) throws IOException { + if (value < 0 || value > 0xffff) { + throw new IIOException("Invalid 2-byte value: " + value); + } ios.write((value >> 8) & 0xff); ios.write(value & 0xff); diff --git a/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java b/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java index e6b0d9233b4..0d17f872b33 100644 --- a/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java +++ b/src/java.desktop/unix/classes/sun/awt/X11/XWindowPeer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002, 2021, Oracle and/or its affiliates. All rights reserved. + * 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 @@ -805,10 +805,10 @@ public void handleConfigureNotifyEvent(XEvent xev) { if (insLog.isLoggable(PlatformLogger.Level.FINE)) { insLog.fine(xe.toString()); } - checkIfOnNewScreen(toGlobal(new Rectangle(scaleDown(xe.get_x()), + checkIfOnNewScreen(new Rectangle(scaleDown(xe.get_x()), scaleDown(xe.get_y()), scaleDown(xe.get_width()), - scaleDown(xe.get_height())))); + scaleDown(xe.get_height()))); Rectangle oldBounds = getBounds(); diff --git a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java index 81bd54484ef..3fc04bb93b9 100644 --- a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java +++ b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsIconFactory.java @@ -882,8 +882,15 @@ public void paintIcon(Component c, Graphics g, int x, int y) { } } if (icon != null) { - icon.paintIcon(c, g, x + VistaMenuItemCheckIconFactory.getIconWidth(), - y + OFFSET); + if (WindowsGraphicsUtils.isLeftToRight(c)) { + icon.paintIcon(c, g, + x + VistaMenuItemCheckIconFactory.getIconWidth(), + y + OFFSET); + } else { + icon.paintIcon(c, g, + x - VistaMenuItemCheckIconFactory.getIconWidth() + 2 * OFFSET, + y + OFFSET); + } } } private static WindowsMenuItemUIAccessor getAccessor( diff --git a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsMenuItemUI.java b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsMenuItemUI.java index 7aa52eadfb8..0fa284294e2 100644 --- a/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsMenuItemUI.java +++ b/src/java.desktop/windows/classes/com/sun/java/swing/plaf/windows/WindowsMenuItemUI.java @@ -43,6 +43,7 @@ import javax.swing.JComponent; import javax.swing.JMenu; import javax.swing.JMenuItem; +import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.plaf.ComponentUI; import javax.swing.plaf.UIResource; @@ -215,8 +216,17 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g, if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) { Rectangle rect = lr.getTextRect(); - - rect.x += lh.getAfterCheckIconGap(); + if (menuItem.getComponentOrientation().isLeftToRight()) { + if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING + && menuItem.getHorizontalTextPosition() != SwingConstants.LEFT) { + rect.x += lh.getAfterCheckIconGap(); + } + } else { + if (menuItem.getHorizontalTextPosition() != SwingConstants.LEADING + && menuItem.getHorizontalTextPosition() != SwingConstants.RIGHT) { + rect.x -= lh.getAfterCheckIconGap(); + } + } lr.setTextRect(rect); } @@ -232,7 +242,11 @@ static void paintMenuItem(WindowsMenuItemUIAccessor accessor, Graphics g, } if (lh.getCheckIcon() != null && lh.useCheckAndArrow()) { Rectangle rect = lr.getAccRect(); - rect.x += lh.getAfterCheckIconGap(); + if (menuItem.getComponentOrientation().isLeftToRight()) { + rect.x += lh.getAfterCheckIconGap(); + } else { + rect.x -= lh.getAfterCheckIconGap(); + } lr.setAccRect(rect); } SwingUtilities3.paintAccText(g, lh, lr, disabledForeground, diff --git a/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/AllocateWithoutOomTest.java b/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/AllocateWithoutOomTest.java index 51307bb996c..a1bd7acedeb 100644 --- a/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/AllocateWithoutOomTest.java +++ b/test/hotspot/jtreg/vmTestbase/gc/gctests/AllocateWithoutOomTest/AllocateWithoutOomTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 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 @@ -37,7 +37,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * gc.gctests.AllocateWithoutOomTest.AllocateWithoutOomTest */ diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_InternedStrings_Strings/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_InternedStrings_Strings/TestDescription.java index 4e11e51a894..ad7db17e412 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_InternedStrings_Strings/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_InternedStrings_Strings/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp interned(randomString) diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree/TestDescription.java index b058bb2c84d..be4f9f673b7 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp nonbranchyTree(high) diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_ArrayOf/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_ArrayOf/TestDescription.java index 3beeaa76a84..2ca21ae2ee6 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_ArrayOf/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_ArrayOf/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp nonbranchyTree(high) diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_TwoFields/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_TwoFields/TestDescription.java index c1421263a48..01dc687251b 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_TwoFields/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_NonbranchyTree_TwoFields/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp nonbranchyTree(high) diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings/TestDescription.java index 207822c666b..9ba96b7e493 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp randomString diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_InternedStrings/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_InternedStrings/TestDescription.java index 705e47ea68b..30dcfc7502e 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_InternedStrings/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_InternedStrings/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp randomString diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_TwoFields/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_TwoFields/TestDescription.java index 7d5ddc36fcb..8a62d4b07eb 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_TwoFields/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Compact_Strings_TwoFields/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp randomString diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_NonbranchyTree/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_NonbranchyTree/TestDescription.java index 38c5b1e6bab..c9c117f0b0e 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_NonbranchyTree/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_NonbranchyTree/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp nonbranchyTree(high) diff --git a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_Strings/TestDescription.java b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_Strings/TestDescription.java index 88d11739141..7d4b6ae3a21 100644 --- a/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_Strings/TestDescription.java +++ b/test/hotspot/jtreg/vmTestbase/vm/gc/compact/Humongous_Strings/TestDescription.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -36,7 +36,7 @@ * * @library /vmTestbase * /test/lib - * @run main/othervm + * @run main/othervm/timeout=480 * -XX:-UseGCOverheadLimit * vm.gc.compact.Compact * -gp randomString diff --git a/test/jdk/java/awt/Multiscreen/MultiScreenCheckScreenIDTest.java b/test/jdk/java/awt/Multiscreen/MultiScreenCheckScreenIDTest.java new file mode 100644 index 00000000000..14717da5790 --- /dev/null +++ b/test/jdk/java/awt/Multiscreen/MultiScreenCheckScreenIDTest.java @@ -0,0 +1,148 @@ +/* + * Copyright (c) 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. + */ + +import java.awt.AWTException; +import java.awt.Color; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Rectangle; +import java.awt.Robot; +import java.awt.Window; + +import javax.swing.JWindow; +import javax.swing.SwingUtilities; + +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +/* + * @test + * @bug 8280482 + * @key headful + * @summary Test to check if window GC doesn't change within same screen. + * @run main MultiScreenCheckScreenIDTest + */ + +public class MultiScreenCheckScreenIDTest extends MouseAdapter { + private static final int COLS = 12; + private static final int ROWS = 8; + private static final Color BACKGROUND = new Color(0, 0, 255, 64); + private static GraphicsDevice[] screens; + static List windowList = new ArrayList<>(); + static Robot robot; + static JWindow window; + + + public static void main(final String[] args) throws Exception { + try { + createGUI(); + } finally { + for (Window win : windowList) { + win.dispose(); + } + if (window != null) { + window.dispose(); + } + } + System.out.println("Test Pass"); + } + + private static void createGUI() throws AWTException { + new MultiScreenCheckScreenIDTest().createWindowGrid(); + } + + private void createWindowGrid() throws AWTException { + screens = GraphicsEnvironment + .getLocalGraphicsEnvironment() + .getScreenDevices(); + + if (screens.length < 2) { + System.out.println("Testing aborted. Required min of 2 screens. " + + "Available : " + screens.length); + return; + } + robot = new Robot(); + + int screenNumber = 1; + for (GraphicsDevice screen : screens) { + Rectangle screenBounds = screen.getDefaultConfiguration().getBounds(); + + for (Rectangle r : gridOfRectangles(screenBounds, COLS, ROWS)) { + try { + SwingUtilities.invokeAndWait(() -> { + try { + window = createWindow(r); + } catch (Exception e) { + throw new RuntimeException(e); + } + }); + } catch (InterruptedException | InvocationTargetException e) { + e.printStackTrace(); + } + robot.delay(50); + robot.waitForIdle(); + if (window.getBounds().intersects(screenBounds)) { + if (!(window.getGraphicsConfiguration().getBounds(). + intersects(screenBounds))) { + throw new RuntimeException("Graphics configuration " + + "changed for screen :" + screenNumber); + } + } + windowList.add(window); + } + screenNumber++; + } + } + + private JWindow createWindow(Rectangle bounds) { + JWindow window = new JWindow(); + window.setBounds(bounds); + window.setBackground(BACKGROUND); + window.setAlwaysOnTop(true); + window.addMouseListener(this); + window.setVisible(true); + return window; + } + + @Override + public void mouseClicked(MouseEvent e) { + ((Window) e.getSource()).dispose(); + } + + private static List gridOfRectangles(Rectangle r, int cols, int rows) { + List l = new ArrayList<>(); + for (int row = 0; row < rows; row++) { + int y1 = r.y + (int) Math.round(r.height * (double) row / rows); + int y2 = r.y + (int) Math.round(r.height * (double) (row + 1) / rows); + for (int col = 0; col < cols; col++) { + int x1 = r.x + (int) Math.round(r.width * (double) col / cols); + int x2 = r.x + (int) Math.round(r.width * (double) (col + 1) / cols); + l.add(new Rectangle(x1, y1, x2 - x1, y2 - y1)); + } + } + return l; + } +} diff --git a/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java b/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java index b081d261529..b526af0c7f5 100644 --- a/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java +++ b/test/jdk/java/lang/Thread/virtual/stress/GetStackTraceALotWhenPinned.java @@ -56,8 +56,8 @@ public static void main(String[] args) throws Exception { int iterations; int value = Integer.parseInt(args[0]); - if (Platform.isOSX() && Platform.isX64()) { - // reduced iterations on macosx-x64 + if (Platform.isOSX()) { + // reduced iterations on macosx iterations = Math.max(value / 4, 1); } else { iterations = value; diff --git a/test/jdk/java/lang/Thread/virtual/stress/ParkALot.java b/test/jdk/java/lang/Thread/virtual/stress/ParkALot.java index 882e0b881bc..a9dd16e2586 100644 --- a/test/jdk/java/lang/Thread/virtual/stress/ParkALot.java +++ b/test/jdk/java/lang/Thread/virtual/stress/ParkALot.java @@ -49,8 +49,8 @@ public class ParkALot { public static void main(String[] args) throws Exception { int iterations; int value = Integer.parseInt(args[0]); - if (Platform.isOSX() && Platform.isX64()) { - // reduced iterations on macosx-x64 + if (Platform.isOSX()) { + // reduced iterations on macosx iterations = Math.max(value / 4, 1); } else { iterations = value; diff --git a/test/jdk/javax/imageio/plugins/jpeg/WriteJPEGThumbnailTest.java b/test/jdk/javax/imageio/plugins/jpeg/WriteJPEGThumbnailTest.java new file mode 100644 index 00000000000..94ad1fd6e8d --- /dev/null +++ b/test/jdk/javax/imageio/plugins/jpeg/WriteJPEGThumbnailTest.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 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. + */ + +/* + * @test + * @bug 8351110 + * @summary Test verifies that when a JFIF thumbnail may exceed 65535 bytes + * we still write a valid JPEG file by clipping the thumbnail. + * @run main WriteJPEGThumbnailTest + */ + +import javax.imageio.IIOImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.ImageWriter; +import javax.imageio.stream.ImageInputStream; +import javax.imageio.stream.ImageOutputStream; +import java.awt.geom.AffineTransform; +import java.awt.image.BufferedImage; +import java.awt.Color; +import java.awt.Graphics2D; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; +import java.util.List; + +public class WriteJPEGThumbnailTest { + + private static void assertEquals(int expected, int observed) { + if (expected != observed) { + throw new Error("expected " + expected + ", but observed " + observed); + } + } + + public static void main(String[] args) throws Exception { + // this always passed. 21800 * 3 = 65400, which fits in a 65535-byte segment. + boolean b1 = new WriteJPEGThumbnailTest(100, 218).run(); + + // this failed prior to resolving 8351110. 21900 * 3 = 65700, which is too large + // for a JPEG segment. Now we clip the thumbnail to make it fit. (Previously + // we wrote a corrupt JPEG file.) + boolean b2 = new WriteJPEGThumbnailTest(100, 219).run(); + + if (!(b1 && b2)) { + System.err.println("Test failed"); + throw new Error("Test failed"); + } + } + + final int thumbWidth; + final int thumbHeight; + + public WriteJPEGThumbnailTest(int thumbWidth, int thumbHeight) { + this.thumbWidth = thumbWidth; + this.thumbHeight = thumbHeight; + } + + public boolean run() throws Exception { + System.out.println("Testing thumbnail " + thumbWidth + "x" + thumbHeight + "..."); + try { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + BufferedImage thumbnail = writeImage(byteOut); + byte[] jpegData = byteOut.toByteArray(); + ImageReader reader = getJPEGImageReader(); + ImageInputStream stream = ImageIO.createImageInputStream(new ByteArrayInputStream(jpegData)); + reader.setInput(stream); + assertEquals(1, reader.getNumThumbnails(0)); + + // we may have a subset of our original thumbnail, that's OK + BufferedImage readThumbnail = reader.readThumbnail(0, 0); + for (int y = 0; y < readThumbnail.getHeight(); y++) { + for (int x = 0; x < readThumbnail.getWidth(); x++) { + int rgb1 = thumbnail.getRGB(x, y); + int rgb2 = readThumbnail.getRGB(x, y); + assertEquals(rgb1, rgb2); + } + } + System.out.println("\tTest passed"); + } catch (Throwable e) { + e.printStackTrace(); + return false; + } + return true; + } + + private BufferedImage writeImage(OutputStream out) throws IOException { + BufferedImage thumbnail = createImage(thumbWidth, thumbHeight); + BufferedImage bi = createImage(thumbnail.getWidth() * 10, thumbnail.getHeight() * 10); + + ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next(); + + try (ImageOutputStream outputStream = ImageIO.createImageOutputStream(out)) { + writer.setOutput(outputStream); + + // Write the main image + IIOImage img = new IIOImage(bi, List.of(thumbnail), null); + writer.write(null, img, null); + } finally { + writer.dispose(); + } + return thumbnail; + } + + private static BufferedImage createImage(int width, int height) { + BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + Graphics2D g = bi.createGraphics(); + double sx = ((double)width) / 1000.0; + double sy = ((double)height) / 1000.0; + g.transform(AffineTransform.getScaleInstance(sx, sy)); + g.setColor(Color.RED); + g.fillRect(0, 0, 100, 100); + g.setColor(Color.GREEN); + g.fillRect(900, 0, 900, 100); + g.setColor(Color.ORANGE); + g.fillRect(0, 900, 100, 100); + g.setColor(Color.MAGENTA); + g.fillRect(900, 900, 100, 100); + g.dispose(); + return bi; + } + + private static ImageReader getJPEGImageReader() { + Iterator readers = ImageIO.getImageReadersByFormatName("jpeg"); + ImageReader reader; + while (readers.hasNext()) { + reader = readers.next(); + if (reader.canReadRaster()) { + return reader; + } + } + return null; + } +} diff --git a/test/jdk/javax/swing/JComponent/bug4235215.java b/test/jdk/javax/swing/JComponent/bug4235215.java new file mode 100644 index 00000000000..471f713ee46 --- /dev/null +++ b/test/jdk/javax/swing/JComponent/bug4235215.java @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1999, 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. + */ + +/* + * @test + * @bug 4235215 + * @summary Tests that Toolkit.getPrintJob() do not throw NPE + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual bug4235215 + */ + +import java.awt.Toolkit; +import javax.swing.JButton; +import javax.swing.JFrame; + +public class bug4235215 { + + private static final String INSTRUCTIONS = """ + Press "Print Dialog" button. + If you see a print dialog, test passes. + Click "Cancel" button to close it."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("bug4235215 Instructions") + .instructions(INSTRUCTIONS) + .columns(35) + .testUI(bug4235215::createTestUI) + .build() + .awaitAndCheck(); + } + + private static JFrame createTestUI() { + JFrame frame = new JFrame("bug4235215"); + JButton button = new JButton("Print Dialog"); + button.addActionListener(ev -> { + Toolkit.getDefaultToolkit().getPrintJob(frame, "Test Printing", null); + }); + frame.add(button); + frame.pack(); + return frame; + } +} diff --git a/test/jdk/javax/swing/JComponent/bug4247610.java b/test/jdk/javax/swing/JComponent/bug4247610.java new file mode 100644 index 00000000000..e5470606f6e --- /dev/null +++ b/test/jdk/javax/swing/JComponent/bug4247610.java @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2000, 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. + */ + +/* + * @test + * @bug 4247610 + * @summary Tests an unnecessary repaint issue + * @key headful + * @run main bug4247610 + */ + +import java.awt.Dimension; +import java.awt.FlowLayout; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.Robot; +import java.awt.event.InputEvent; +import javax.swing.JButton; +import javax.swing.JDesktopPane; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingUtilities; + +import java.util.concurrent.atomic.AtomicInteger; +import java.util.Random; + +public class bug4247610 { + + private static JFrame frame; + private static JButton damager; + private static volatile Point loc; + private static volatile Dimension size; + private static volatile boolean traced; + private static volatile boolean failed; + + public static void main(String[] args) throws Exception { + Robot robot = new Robot(); + SwingUtilities.invokeAndWait(() -> { + frame = new JFrame("bug4247610"); + JDesktopPane pane = new JDesktopPane(); + + JInternalFrame jif = new JInternalFrame( + "Damager", true, true, true, true); + InternalFramePanel ifp = new InternalFramePanel(); + damager = new JButton("Damage!"); + ifp.add(damager); + jif.setContentPane(ifp); + jif.setBounds(0, 0, 300, 300); + jif.setVisible(true); + pane.add(jif); + + jif = new JInternalFrame("Damagee", true, true, true, true); + JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); + final JLabel damagee = new JLabel(""); + panel.add(damagee); + jif.setContentPane(panel); + jif.setBounds(60, 220, 300, 100); + jif.setVisible(true); + pane.add(jif); + + final Random random = new Random(); + + damager.addActionListener((e) -> { + System.out.println("trace paints enabled"); + traced = true; + damagee.setText(Integer.toString(random.nextInt())); + }); + frame.setContentPane(pane); + frame.setSize(500, 500); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + }); + robot.waitForIdle(); + robot.delay(1000); + SwingUtilities.invokeAndWait(() -> { + loc = damager.getLocationOnScreen(); + size = damager.getSize(); + }); + robot.mouseMove(loc.x + size.width / 2, loc.y + size.height / 2); + robot.waitForIdle(); + robot.delay(200); + robot.mousePress(InputEvent.BUTTON1_DOWN_MASK); + robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK); + if (failed) { + throw new RuntimeException("Failed: unnecessary repaint occured"); + } + } + + + static class InternalFramePanel extends JPanel { + final AtomicInteger repaintCounter = new AtomicInteger(0); + InternalFramePanel() { + super(new FlowLayout()); + setOpaque(true); + } + + public synchronized void paintComponent(Graphics g) { + super.paintComponent(g); + repaintCounter.incrementAndGet(); + System.out.println("repaintCounter " + repaintCounter.intValue()); + if (traced) { + failed = true; + } + } + } +} diff --git a/test/jdk/javax/swing/JComponent/bug4254995.java b/test/jdk/javax/swing/JComponent/bug4254995.java new file mode 100644 index 00000000000..8947558f128 --- /dev/null +++ b/test/jdk/javax/swing/JComponent/bug4254995.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1999, 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. + */ + +/* + * @test + * @bug 4254995 + * @summary Tests that html in renderer works correctly + * @library /java/awt/regtesthelpers + * @build PassFailJFrame + * @run main/manual bug4254995 + */ + +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JScrollPane; + +public class bug4254995 { + + private static final String INSTRUCTIONS = """ + If you see a list containing digits from one to seven, test passes. + Otherwise it fails."""; + + public static void main(String[] args) throws Exception { + PassFailJFrame.builder() + .title("bug4254995 Instructions") + .instructions(INSTRUCTIONS) + .columns(35) + .testUI(bug4254995::createTestUI) + .build() + .awaitAndCheck(); + } + + private static JFrame createTestUI() { + JFrame frame = new JFrame("bug4254995"); + String[] data = { "1", "2", "3", "4", "5", "6", "7" }; + frame.add(new JScrollPane(new JList(data))); + frame.pack(); + return frame; + } +} diff --git a/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java b/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java index 7080f03ad2a..247d8b52541 100644 --- a/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java +++ b/test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java @@ -45,7 +45,7 @@ /* * @test id=windows - * @bug 4211052 + * @bug 4211052 8370465 * @requires (os.family == "windows") * @summary Verifies if menu items lay out correctly when their * ComponentOrientation property is set to RIGHT_TO_LEFT. @@ -155,6 +155,16 @@ static void addMenuItems(JMenu menu, ComponentOrientation o) { menuItem.setHorizontalTextPosition(SwingConstants.LEADING); menu.add(menuItem); + menuItem = new JMenuItem("Text to the left", new MyMenuItemIcon()); + menuItem.setComponentOrientation(o); + menuItem.setHorizontalTextPosition(SwingConstants.LEFT); + menu.add(menuItem); + + menuItem = new JMenuItem("Text to the right", new MyMenuItemIcon()); + menuItem.setComponentOrientation(o); + menuItem.setHorizontalTextPosition(SwingConstants.RIGHT); + menu.add(menuItem); + menuItem = new JRadioButtonMenuItem("Radio Button Menu Item"); menuItem.setComponentOrientation(o); menuItem.setSelected(true);