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
|
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
* Copyright (c) 2022, 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.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JFileChooser;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.WindowConstants;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8296198
|
||||
* @key headful
|
||||
* @requires (os.family == "windows")
|
||||
* @library /java/awt/regtesthelpers
|
||||
* @build PassFailJFrame
|
||||
* @summary Test to check if the Link to a folder is traversable with custom
|
||||
* FileSystemView is valid on ValueChanged property listener.
|
||||
* @run main/manual CustomFSVLinkTest
|
||||
*/
|
||||
public class CustomFSVLinkTest {
|
||||
static JFrame frame;
|
||||
static JFileChooser jfc;
|
||||
|
||||
static PassFailJFrame passFailJFrame;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
initialize();
|
||||
} catch (InterruptedException | InvocationTargetException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
passFailJFrame.awaitAndCheck();
|
||||
}
|
||||
|
||||
static void initialize() throws InterruptedException, InvocationTargetException {
|
||||
//Initialize the components
|
||||
final String INSTRUCTIONS = """
|
||||
Instructions to Test:
|
||||
1. Create a link to a any valid folder.
|
||||
2. Navigate to the linked folder through the link created
|
||||
(From FileChooser).
|
||||
3. If "link" can't be traversed or if its absolute path is null
|
||||
click FAIL. If "link" can be traversed then click PASS.
|
||||
""";
|
||||
frame = new JFrame("JFileChooser Link test");
|
||||
jfc = new JFileChooser(new MyFileSystemView());
|
||||
passFailJFrame = new PassFailJFrame("Test Instructions", INSTRUCTIONS, 5L, 8, 40);
|
||||
|
||||
PassFailJFrame.addTestWindow(frame);
|
||||
PassFailJFrame.positionTestWindow(frame, PassFailJFrame.Position.HORIZONTAL);
|
||||
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||
jfc.setControlButtonsAreShown(false);
|
||||
jfc.setDialogType(JFileChooser.CUSTOM_DIALOG);
|
||||
|
||||
frame.add(jfc, BorderLayout.CENTER);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private static class MyFileSystemView extends FileSystemView {
|
||||
FileSystemView delegate;
|
||||
|
||||
MyFileSystemView() {
|
||||
delegate = FileSystemView.getFileSystemView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File createNewFolder(File containingDir) throws IOException {
|
||||
return delegate.createNewFolder(containingDir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRoot(File f) {
|
||||
return delegate.isRoot(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean isTraversable(File f) {
|
||||
return delegate.isTraversable(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSystemDisplayName(File f) {
|
||||
return delegate.getSystemDisplayName(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSystemTypeDescription(File f) {
|
||||
return delegate.getSystemTypeDescription(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Icon getSystemIcon(File f) {
|
||||
return delegate.getSystemIcon(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isParent(File folder, File file) {
|
||||
return delegate.isParent(folder, file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getChild(File parent, String fileName) {
|
||||
return delegate.getChild(parent, fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFileSystem(File f) {
|
||||
return delegate.isFileSystem(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isHiddenFile(File f) {
|
||||
return delegate.isHiddenFile(f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFileSystemRoot(File dir) {
|
||||
return delegate.isFileSystemRoot(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDrive(File dir) {
|
||||
return delegate.isDrive(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFloppyDrive(File dir) {
|
||||
return delegate.isFloppyDrive(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isComputerNode(File dir) {
|
||||
return delegate.isComputerNode(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getRoots() {
|
||||
return delegate.getRoots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getHomeDirectory() {
|
||||
return delegate.getHomeDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getDefaultDirectory() {
|
||||
return delegate.getDefaultDirectory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public File createFileObject(File dir, String filename) {
|
||||
return delegate.createFileObject(dir, filename);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File createFileObject(String path) {
|
||||
return delegate.createFileObject(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getFiles(File dir, boolean useFileHiding) {
|
||||
return delegate.getFiles(dir, useFileHiding);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getParentDirectory(File dir) {
|
||||
return delegate.getParentDirectory(dir);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File[] getChooserComboBoxFiles() {
|
||||
return delegate.getChooserComboBoxFiles();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLink(File file) {
|
||||
return delegate.isLink(file);
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getLinkLocation(File file) throws FileNotFoundException {
|
||||
return delegate.getLinkLocation(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2017, 2018, 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.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @bug 8175968 8198342
|
||||
* @summary FileSystemView should clean listeners in UIManager before removal
|
||||
* @library /javax/swing/regtesthelpers
|
||||
* @build Util
|
||||
* @run main/othervm -Xmx8m -Djava.awt.headless=true FileSystemViewListenerLeak
|
||||
*/
|
||||
public final class FileSystemViewListenerLeak {
|
||||
|
||||
public static void main(final String[] args) {
|
||||
checkListenersCount();
|
||||
new CustomFileSystemView();
|
||||
Util.generateOOME();
|
||||
checkListenersCount();
|
||||
}
|
||||
|
||||
private static void checkListenersCount() {
|
||||
int length = UIManager.getPropertyChangeListeners().length;
|
||||
if (length != 0) {
|
||||
throw new RuntimeException("The count of listeners is: " + length);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class CustomFileSystemView extends FileSystemView {
|
||||
|
||||
public File createNewFolder(File containingDir) throws IOException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* 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.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8227257
|
||||
* @requires (os.family == "windows")
|
||||
* @summary existing but inaccessible target for a link should be ignored
|
||||
* @run main/othervm InaccessibleLink
|
||||
* @run main/othervm -ea -esa InaccessibleLink
|
||||
*/
|
||||
public final class InaccessibleLink {
|
||||
|
||||
/**
|
||||
* The link to the windows-update settings.
|
||||
*/
|
||||
private static final byte[] bytes = {
|
||||
76, 0, 0, 0, 1, 20, 2, 0, 0, 0, 0, 0, -64, 0, 0, 0, 0, 0, 0, 70,
|
||||
-127, 0, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 84, 0, 20, 0, 31, 104, -128, 83,
|
||||
28, -121, -96, 66, 105, 16, -94, -22, 8, 0, 43, 48, 48, -99, 62, 0,
|
||||
97, -128, 0, 0, 0, 0, 109, 0, 115, 0, 45, 0, 115, 0, 101, 0, 116, 0,
|
||||
116, 0, 105, 0, 110, 0, 103, 0, 115, 0, 58, 0, 119, 0, 105, 0, 110,
|
||||
0, 100, 0, 111, 0, 119, 0, 115, 0, 117, 0, 112, 0, 100, 0, 97, 0,
|
||||
116, 0, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
File file = new File("inaccessible.lnk");
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream(file);
|
||||
fos.write(bytes);
|
||||
fos.close();
|
||||
|
||||
FileSystemView fsv = FileSystemView.getFileSystemView();
|
||||
if (!fsv.isLink(file)) {
|
||||
throw new RuntimeException("not a link");
|
||||
}
|
||||
File linkLocation = fsv.getLinkLocation(file);
|
||||
if (linkLocation != null) {
|
||||
throw new RuntimeException(
|
||||
"location is not null: " + linkLocation);
|
||||
}
|
||||
} finally {
|
||||
Files.deleteIfExists(file.toPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,274 @@
|
|||
/*
|
||||
* Copyright (c) 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.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.UIManager;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8320692
|
||||
* @requires (os.family == "windows")
|
||||
* @summary NullPointerException is thrown for .exe file without icon
|
||||
* @run main/othervm NoIconExeNPE
|
||||
*/
|
||||
public class NoIconExeNPE {
|
||||
|
||||
/**
|
||||
* Bytes of a short {@code Hello.exe} which has no icon.
|
||||
*/
|
||||
private static final byte[] bytes = {
|
||||
(byte) 0x4d, (byte) 0x5a, (byte) 0x80, (byte) 0x00, (byte) 0x01,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x04, (byte) 0x00,
|
||||
(byte) 0x10, (byte) 0x00, (byte) 0xff, (byte) 0xff, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x40, (byte) 0x01, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x40,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0e,
|
||||
(byte) 0x1f, (byte) 0xba, (byte) 0x0e, (byte) 0x00, (byte) 0xb4,
|
||||
(byte) 0x09, (byte) 0xcd, (byte) 0x21, (byte) 0xb8, (byte) 0x01,
|
||||
(byte) 0x4c, (byte) 0xcd, (byte) 0x21, (byte) 0x54, (byte) 0x68,
|
||||
(byte) 0x69, (byte) 0x73, (byte) 0x20, (byte) 0x70, (byte) 0x72,
|
||||
(byte) 0x6f, (byte) 0x67, (byte) 0x72, (byte) 0x61, (byte) 0x6d,
|
||||
(byte) 0x20, (byte) 0x63, (byte) 0x61, (byte) 0x6e, (byte) 0x6e,
|
||||
(byte) 0x6f, (byte) 0x74, (byte) 0x20, (byte) 0x62, (byte) 0x65,
|
||||
(byte) 0x20, (byte) 0x72, (byte) 0x75, (byte) 0x6e, (byte) 0x20,
|
||||
(byte) 0x69, (byte) 0x6e, (byte) 0x20, (byte) 0x44, (byte) 0x4f,
|
||||
(byte) 0x53, (byte) 0x20, (byte) 0x6d, (byte) 0x6f, (byte) 0x64,
|
||||
(byte) 0x65, (byte) 0x2e, (byte) 0x0d, (byte) 0x0a, (byte) 0x24,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x50, (byte) 0x45,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x4c, (byte) 0x01, (byte) 0x01,
|
||||
(byte) 0x00, (byte) 0x55, (byte) 0x96, (byte) 0x96, (byte) 0x65,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xe0, (byte) 0x00,
|
||||
(byte) 0x0f, (byte) 0x01, (byte) 0x0b, (byte) 0x01, (byte) 0x01,
|
||||
(byte) 0x49, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x40, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x04, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x20,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0xac, (byte) 0xa3, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x02, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x00,
|
||||
(byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x40, (byte) 0x10, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x86, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x2e, (byte) 0x74, (byte) 0x65, (byte) 0x78,
|
||||
(byte) 0x74, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xc6,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x10,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x20, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x60, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x6a, (byte) 0x00, (byte) 0x68,
|
||||
(byte) 0x29, (byte) 0x10, (byte) 0x40, (byte) 0x00, (byte) 0x68,
|
||||
(byte) 0x1c, (byte) 0x10, (byte) 0x40, (byte) 0x00, (byte) 0x6a,
|
||||
(byte) 0x00, (byte) 0xff, (byte) 0x15, (byte) 0x88, (byte) 0x10,
|
||||
(byte) 0x40, (byte) 0x00, (byte) 0x6a, (byte) 0x00, (byte) 0xff,
|
||||
(byte) 0x15, (byte) 0x80, (byte) 0x10, (byte) 0x40, (byte) 0x00,
|
||||
(byte) 0x48, (byte) 0x65, (byte) 0x6c, (byte) 0x6c, (byte) 0x6f,
|
||||
(byte) 0x20, (byte) 0x57, (byte) 0x6f, (byte) 0x72, (byte) 0x6c,
|
||||
(byte) 0x64, (byte) 0x21, (byte) 0x00, (byte) 0x48, (byte) 0x65,
|
||||
(byte) 0x6c, (byte) 0x6c, (byte) 0x6f, (byte) 0x20, (byte) 0x66,
|
||||
(byte) 0x61, (byte) 0x73, (byte) 0x6d, (byte) 0x00, (byte) 0x90,
|
||||
(byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90,
|
||||
(byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90,
|
||||
(byte) 0x90, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x90, (byte) 0x10,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x80, (byte) 0x10, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x9d, (byte) 0x10,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x88, (byte) 0x10, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x90, (byte) 0x90, (byte) 0x90, (byte) 0x90,
|
||||
(byte) 0xa8, (byte) 0x10, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xb8, (byte) 0x10,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x6b, (byte) 0x65, (byte) 0x72, (byte) 0x6e,
|
||||
(byte) 0x65, (byte) 0x6c, (byte) 0x33, (byte) 0x32, (byte) 0x2e,
|
||||
(byte) 0x64, (byte) 0x6c, (byte) 0x6c, (byte) 0x00, (byte) 0x75,
|
||||
(byte) 0x73, (byte) 0x65, (byte) 0x72, (byte) 0x33, (byte) 0x32,
|
||||
(byte) 0x2e, (byte) 0x64, (byte) 0x6c, (byte) 0x6c, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x45, (byte) 0x78, (byte) 0x69,
|
||||
(byte) 0x74, (byte) 0x50, (byte) 0x72, (byte) 0x6f, (byte) 0x63,
|
||||
(byte) 0x65, (byte) 0x73, (byte) 0x73, (byte) 0x00, (byte) 0x90,
|
||||
(byte) 0x90, (byte) 0x00, (byte) 0x00, (byte) 0x4d, (byte) 0x65,
|
||||
(byte) 0x73, (byte) 0x73, (byte) 0x61, (byte) 0x67, (byte) 0x65,
|
||||
(byte) 0x42, (byte) 0x6f, (byte) 0x78, (byte) 0x41, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
|
||||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
final Path temp = Files.createTempDirectory("no-icon");
|
||||
final Path hello = temp.resolve("Hello.exe");
|
||||
|
||||
try {
|
||||
try (OutputStream out = Files.newOutputStream(hello)) {
|
||||
out.write(bytes);
|
||||
}
|
||||
|
||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
||||
|
||||
FileSystemView fsv = FileSystemView.getFileSystemView();
|
||||
// No NullPointerException is expected
|
||||
Icon icon = fsv.getSystemIcon(hello.toFile());
|
||||
if (icon == null) {
|
||||
throw new RuntimeException("Null icon returned by FileSystemView.getSystemIcon()");
|
||||
}
|
||||
} finally {
|
||||
Files.deleteIfExists(hello);
|
||||
Files.delete(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 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 8277299
|
||||
* @requires (os.family == "windows")
|
||||
* @summary STACK_OVERFLOW in Java_sun_awt_shell_Win32ShellFolder2_getIconBits
|
||||
* @run main/othervm -Xss320k ShellFolderStackOverflow
|
||||
*/
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class ShellFolderStackOverflow {
|
||||
public static void main(final String... args) throws Exception {
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
|
||||
// With default stack size for 32-bit VM next call will cause VM crash
|
||||
UIManager.getIcon("Tree.openIcon");
|
||||
}
|
||||
}
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2021, 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 8182043
|
||||
* @summary Access to Windows Large Icons
|
||||
* @run main SystemIconTest
|
||||
*/
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
import java.awt.image.MultiResolutionImage;
|
||||
import java.io.File;
|
||||
|
||||
public class SystemIconTest {
|
||||
static final FileSystemView fsv = FileSystemView.getFileSystemView();
|
||||
|
||||
public static void main(String[] args) {
|
||||
testSystemIcon();
|
||||
negativeTests();
|
||||
}
|
||||
|
||||
static void testSystemIcon() {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os.startsWith("Windows")) {
|
||||
String windir = System.getenv("windir");
|
||||
testSystemIcon(new File(windir), true);
|
||||
testSystemIcon(new File(windir + "/explorer.exe"),
|
||||
true);
|
||||
} else {
|
||||
String homedir = System.getProperty("user.home");
|
||||
testSystemIcon(new File(homedir), false);
|
||||
}
|
||||
}
|
||||
|
||||
static void negativeTests() {
|
||||
Icon icon;
|
||||
try {
|
||||
icon = fsv.getSystemIcon(new File("."), -1, 16);
|
||||
throw new RuntimeException("Negative size icon should throw invalid argument exception");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
icon = fsv.getSystemIcon(new File("thereisdefinitelynosuchfile.why"),
|
||||
16, 16);
|
||||
if (icon != null) {
|
||||
throw new RuntimeException("Icons for files with invalid names should be null");
|
||||
}
|
||||
}
|
||||
|
||||
static void testSystemIcon(File file, boolean implComplete) {
|
||||
int[] sizes = new int[] {16, 32, 48, 64, 128};
|
||||
for (int size : sizes) {
|
||||
Icon i = fsv.getSystemIcon(file, size, size);
|
||||
|
||||
if (i == null) {
|
||||
throw new RuntimeException(file.getAbsolutePath() + " icon is null");
|
||||
}
|
||||
|
||||
if (!(i instanceof ImageIcon)) {
|
||||
// Default UI resource icon returned - it is not covered
|
||||
// by new implementation so we can not test it
|
||||
continue;
|
||||
}
|
||||
|
||||
ImageIcon icon = (ImageIcon) i;
|
||||
//Enable below to see the icon
|
||||
//JLabel label = new JLabel(icon);
|
||||
//JOptionPane.showMessageDialog(null, label);
|
||||
|
||||
if (implComplete && icon.getIconWidth() != size) {
|
||||
throw new RuntimeException("Wrong icon size " +
|
||||
icon.getIconWidth() + " when requested " + size +
|
||||
" for file " + file.getAbsolutePath());
|
||||
}
|
||||
|
||||
if (icon.getImage() instanceof MultiResolutionImage) {
|
||||
MultiResolutionImage mri = (MultiResolutionImage) icon.getImage();
|
||||
if (mri.getResolutionVariant(size, size) == null) {
|
||||
throw new RuntimeException("There is no suitable variant for the size "
|
||||
+ size + " in the multi resolution icon " + file.getAbsolutePath());
|
||||
}
|
||||
} else {
|
||||
if (implComplete) {
|
||||
throw new RuntimeException("icon is supposed to be" +
|
||||
" multi-resolution but it is not for " + file.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,158 @@
|
|||
/*
|
||||
* Copyright (c) 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.io.File;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8305072
|
||||
* @requires (os.family == "windows")
|
||||
* @modules java.desktop/sun.awt.shell
|
||||
* @summary Verifies consistency of Win32ShellFolder2.compareTo
|
||||
* @run main/othervm --add-opens java.desktop/sun.awt.shell=ALL-UNNAMED Win32FolderSort
|
||||
*/
|
||||
public class Win32FolderSort {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Class<?> folderManager = Class.forName("sun.awt.shell.Win32ShellFolderManager2");
|
||||
Class<?> folder = Class.forName("sun.awt.shell.Win32ShellFolder2");
|
||||
|
||||
Method getDesktop = folderManager.getDeclaredMethod("getDesktop");
|
||||
getDesktop.setAccessible(true);
|
||||
Method getPersonal = folderManager.getDeclaredMethod("getPersonal");
|
||||
getPersonal.setAccessible(true);
|
||||
|
||||
Method createShellFolder = folderManager.getDeclaredMethod("createShellFolder", folder, File.class);
|
||||
createShellFolder.setAccessible(true);
|
||||
|
||||
Method isFileSystem = folder.getMethod("isFileSystem");
|
||||
isFileSystem.setAccessible(true);
|
||||
Method isSpecial = folder.getMethod("isSpecial");
|
||||
isSpecial.setAccessible(true);
|
||||
Method getChildByPath = folder.getDeclaredMethod("getChildByPath", String.class);
|
||||
getChildByPath.setAccessible(true);
|
||||
|
||||
File desktop = (File) getDesktop.invoke(null);
|
||||
File personal = (File) getPersonal.invoke(null);
|
||||
if (!((Boolean) isSpecial.invoke(personal))) {
|
||||
throw new RuntimeException("personal is not special");
|
||||
}
|
||||
File fakePersonal = (File) getChildByPath.invoke(desktop, personal.getPath());
|
||||
if (fakePersonal == null) {
|
||||
fakePersonal = (File) createShellFolder.invoke(null, desktop,
|
||||
new File(personal.getPath()));
|
||||
}
|
||||
if ((Boolean) isSpecial.invoke(fakePersonal)) {
|
||||
throw new RuntimeException("fakePersonal is special");
|
||||
}
|
||||
File homeDir = (File) createShellFolder.invoke(null, desktop,
|
||||
new File(System.getProperty("user.home")));
|
||||
|
||||
File[] files = {fakePersonal, personal, homeDir};
|
||||
for (File f : files) {
|
||||
if (!((Boolean) isFileSystem.invoke(f))) {
|
||||
throw new RuntimeException(f + " is not on file system");
|
||||
}
|
||||
}
|
||||
|
||||
List<String> errors = new ArrayList<>(2);
|
||||
for (File f1 : files) {
|
||||
for (File f2 : files) {
|
||||
for (File f3 : files) {
|
||||
String result = verifyCompareTo(f1, f2, f3);
|
||||
if (result != null) {
|
||||
String error = result + "\nwhere"
|
||||
+ "\n a = " + formatFile(f1, isSpecial)
|
||||
+ "\n b = " + formatFile(f2, isSpecial)
|
||||
+ "\n c = " + formatFile(f3, isSpecial);
|
||||
errors.add(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
System.out.println("Unsorted:");
|
||||
for (File f : files) {
|
||||
System.out.println(formatFile(f, isSpecial));
|
||||
}
|
||||
System.out.println();
|
||||
|
||||
Arrays.sort(files);
|
||||
System.out.println("Sorted:");
|
||||
for (File f : files) {
|
||||
System.out.println(formatFile(f, isSpecial));
|
||||
}
|
||||
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
System.err.println("Implementation of Win32ShellFolder2.compareTo is inconsistent:");
|
||||
errors.forEach(System.err::println);
|
||||
throw new RuntimeException("Inconsistencies found: " + errors.size()
|
||||
+ " - " + errors.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies consistency of {@code Comparable} implementation.
|
||||
*
|
||||
* @param a the first object
|
||||
* @param b the second object
|
||||
* @param c the third object
|
||||
* @return error message if inconsistency is found,
|
||||
* or {@code null } otherwise
|
||||
*/
|
||||
private static String verifyCompareTo(File a, File b, File c) {
|
||||
// a < b & b < c => a < c
|
||||
if (a.compareTo(b) < 0 && b.compareTo(c) < 0) {
|
||||
if (a.compareTo(c) >= 0) {
|
||||
return "a < b & b < c but a >= c";
|
||||
}
|
||||
}
|
||||
|
||||
// a > b & b > c => a > c
|
||||
if (a.compareTo(b) > 0 && b.compareTo(c) > 0) {
|
||||
if (a.compareTo(c) <= 0) {
|
||||
return "a > b & b > c but a <= c";
|
||||
}
|
||||
}
|
||||
|
||||
// a = b & b = c => a = c
|
||||
if (a.compareTo(b) == 0 && b.compareTo(c) == 0) {
|
||||
if (a.compareTo(c) != 0) {
|
||||
return "a = b & b = c but a != c";
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static String formatFile(File f, Method isSpecial)
|
||||
throws InvocationTargetException, IllegalAccessException {
|
||||
return f + "(" + isSpecial.invoke(f) + ")";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2022, 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 javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.filechooser.FileSystemView;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.MultiResolutionImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8282526
|
||||
* @summary Default icon is not painted properly
|
||||
* @requires (os.family == "windows")
|
||||
* @run main WindowsDefaultIconSizeTest
|
||||
*/
|
||||
|
||||
public class WindowsDefaultIconSizeTest {
|
||||
public static void main(String[] args) {
|
||||
WindowsDefaultIconSizeTest test = new WindowsDefaultIconSizeTest();
|
||||
test.test();
|
||||
}
|
||||
|
||||
public void test() {
|
||||
String filename = "test.not";
|
||||
|
||||
File testFile = new File(filename);
|
||||
try {
|
||||
if (!testFile.exists()) {
|
||||
testFile.createNewFile();
|
||||
testFile.deleteOnExit();
|
||||
}
|
||||
FileSystemView fsv = FileSystemView.getFileSystemView();
|
||||
Icon icon = fsv.getSystemIcon(new File(filename));
|
||||
if (icon instanceof ImageIcon) {
|
||||
Image image = ((ImageIcon) icon).getImage();
|
||||
if (image instanceof MultiResolutionImage) {
|
||||
Image variant = ((MultiResolutionImage) image).getResolutionVariant(16, 16);
|
||||
if (variant.getWidth(null) != 16) {
|
||||
throw new RuntimeException("Default file icon has size of " +
|
||||
variant.getWidth(null) + " instead of 16");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException("Unexpected error while creating the test file: " + ioe.getLocalizedMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue