Hi awt-dev,
I found a behavior difference when open file dialog from an
applet, bug
7160238 has been created for this issue.
Here's the tiny test case to helping reproduce the problem,
/*
* Copyright (c) 2012 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.
*/
/*
* Portions Copyright (c) 2012 IBM Corporation
*/
import java.applet.Applet;
import java.awt.Button;
import java.awt.FileDialog;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class FileDialogTest extends Applet {
@Override
public void init() {
Button button = new Button("Open FileDialog");
add(button);
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
Frame f = new Frame();
FileDialog dialog = new FileDialog(f, "FileDialog");
dialog.show();
}
});
}
}
Embeded it into an HTML document, test.html, then run
appletviewer with
following two commands,
appletviewer -J-Dsun.awt.disableGtkFileDialogs=true test.html
appletviewer -J-Dsun.awt.disableGtkFileDialogs=false test.html
The result will be different, -J-Dsun.awt.disableGtkFileDialogs=true
will throw AccessControlException, but
-J-Dsun.awt.disableGtkFileDialogs=false will continue to open a file
dialog.
According to the specification:
The basic applet security model is an all or nothing proposition.
If you
get a security certificate, you can give the applet full access
to the
user's system. Without it, the applet has virtually no access at
all.
Since file dialog displays the content of user's file system, so it
absolutely needs file system read permmission, right? but for Gtk
File
Dialog, it just works fine without exceptions. I don't think this
behavior is following the spec here, right? In OpenJDK's source
code,
GtkFileDialogPeer will create a native GTK file chooser widget
and keep
a native pointer, does this leave a breach to Java applet's security
model?
Cheers!
- Jonathan