diff --git a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m index 051588f95bf..fa534fff275 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/awt/CImage.m @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2011, 2026, 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 @@ -270,7 +270,7 @@ JNI_COCOA_ENTER(env); NSRect fromRect = NSMakeRect(0, 0, sw, sh); NSRect toRect = NSMakeRect(0, 0, dw, dh); CImage_CopyNSImageIntoArray(img, dst, fromRect, toRect); - (*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, JNI_ABORT); + (*env)->ReleasePrimitiveArrayCritical(env, buffer, dst, 0); } JNI_COCOA_EXIT(env); diff --git a/test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconPixelDataTest.java b/test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconPixelDataTest.java new file mode 100644 index 00000000000..c71c7a3e6a9 --- /dev/null +++ b/test/jdk/javax/swing/JFileChooser/FileSystemView/SystemIconPixelDataTest.java @@ -0,0 +1,93 @@ +/* + * Copyright Amazon.com Inc. 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.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.swing.Icon; +import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; +import javax.swing.UnsupportedLookAndFeelException; +import javax.swing.filechooser.FileSystemView; + +/** + * @test + * @bug 8376253 + * @summary FileSystemView may not report system icons when -Xcheck:jni enabled + * @key headful + * @run main SystemIconPixelDataTest + * @run main/othervm -Xcheck:jni SystemIconPixelDataTest + */ +public final class SystemIconPixelDataTest { + + public static void main(String[] args) throws Exception { + for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) { + AtomicBoolean ok = new AtomicBoolean(); + EventQueue.invokeAndWait(() -> ok.set(setLookAndFeel(laf))); + if (ok.get()) { + EventQueue.invokeAndWait(SystemIconPixelDataTest::test); + } + } + } + + private static boolean setLookAndFeel(LookAndFeelInfo laf) { + try { + UIManager.setLookAndFeel(laf.getClassName()); + System.out.println("LookAndFeel: " + laf.getClassName()); + return true; + } catch (UnsupportedLookAndFeelException ignored) { + return false; + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static void test() { + FileSystemView fsv = FileSystemView.getFileSystemView(); + File home = fsv.getHomeDirectory(); + Icon icon = fsv.getSystemIcon(home); + if (icon == null) { + return; + } + int w = icon.getIconWidth(); + int h = icon.getIconHeight(); + if (w <= 0 || h <= 0) { + throw new RuntimeException("Invalid icon size: " + w + "x" + h); + } + var img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB); + Graphics2D g = img.createGraphics(); + icon.paintIcon(null, g, 0, 0); + g.dispose(); + for (int y = 0; y < h; y++) { + for (int x = 0; x < w; x++) { + if (img.getRGB(x, y) != 0) { + return; + } + } + } + throw new RuntimeException("All pixels are zero"); + } +}