JDK-7038890 : CookieHandler.getDefault().get() with "javascript:" URI hangs or otherwise works incorrectly
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 6u24
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-04-22
  • Updated: 2013-11-28
  • Resolved: 2012-01-26
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u4Fixed 8 b23Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Description
In the applet mode, every call to CookieHandler.getDefault().get() with a URI starting with "javascript:" hangs in IE8 or returns an empty map in Firefox 3.6.16.

Here is my test applet:

public class CookieHandlerGetTest extends JApplet {

    private JLabel label;

    @Override
    public void init() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    setLayout(new BorderLayout());

                    JButton button = new JButton("Test");
                    button.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            test();
                        }
                    });
                    add(button, BorderLayout.NORTH);

                    label = new JLabel();
                    add(label, BorderLayout.CENTER);
                }
            });
        } catch (Exception e) {
            System.err.println("createGUI didn't complete successfully");
        }
    }

    private void test() {
        try {
            CookieHandler handler = CookieHandler.getDefault();
            Map<String, List<String>> headers = new HashMap<String, List<String>>();
            URI uri = new URI("javascript://www.oracle.com");
            Map<String, List<String>> result = handler.get(uri, headers);
            label.setText("Result: " + result);
        } catch (Exception ex) {
            label.setText("Error, consult Java Plug-in console for more info");
            ex.printStackTrace(System.err);
        }
    }
}

If I start the applet in IE8 and click the "Test" button, the applet and the Java Console hang, and then jvisualvm finds the event dispatching thread blocked in the following state:

"AWT-EventQueue-2" prio=4 tid=0x03280c00 nid=0x860 in Object.wait() [0x03abe000]
   java.lang.Thread.State: WAITING (on object monitor)
	at java.lang.Object.wait(Native Method)
	- waiting on <0x22c14fe0> (a sun.plugin2.message.Queue)
	at sun.plugin2.message.Queue.waitForMessage(Unknown Source)
	- locked <0x22c14fe0> (a sun.plugin2.message.Queue)
	at sun.plugin2.message.Pipe.receive(Unknown Source)
	at sun.plugin2.main.client.MessagePassingExecutionContext.doCookieOp(Unknown Source)
	at sun.plugin2.main.client.MessagePassingExecutionContext.getCookie(Unknown Source)
	at sun.plugin2.main.client.PluginCookieSelector.getCookieFromBrowser(Unknown Source)
	at com.sun.deploy.net.cookie.DeployCookieSelector.getCookieInfo(Unknown Source)
	at com.sun.deploy.net.cookie.DeployCookieSelector.get(Unknown Source)
	- locked <0x27f5ba98> (a sun.plugin2.main.client.PluginCookieSelector)
	at cookiehandlergettest.CookieHandlerGetTest.test(CookieHandlerGetTest.java:49)
	at cookiehandlergettest.CookieHandlerGetTest.access$000(CookieHandlerGetTest.java:16)
	at cookiehandlergettest.CookieHandlerGetTest$1$1.actionPerformed(CookieHandlerGetTest.java:30)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.awt.EventQueue$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.awt.EventQueue$2.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

In Firefox 3.6.16, instead of hanging, the same call generates a long exception stack trace in the Java Console and returns an empty map, although I am sure I have cookies for oracle.com in there.

To reproduce the problem, compile the attached source code, sign the jar, and run the applet e.g. using the cookiehandlergettest.html and cookiehandlergettest.jnlp files included in the attached project.

Do not know what happens if the same is attempted by an application deployed via WebStart.
FYI, this problem is the only reason why JavaFX WebView does not honor HTTPOnly cookie attribute: http://javafx-jira.kenai.com/browse/RT-12200 . According to 7048628, in order to filter out HTTPOnly cookies, the client needs to call CookieHandler.getDefault().get() with a "javascript:" URI, but, as this problem report indicates, that causes applets to hang.

Comments
Verified on win7-x86/IE9/FF/GC with 8b117. No hangs, all got an empty map.
28-11-2013

SUGGESTED FIX It's better to use URI to avoid the implication of a protocol handler need to be exist.
24-01-2012

EVALUATION javascript is not a valid protcol(scheme) for URL class, thus the following exception, java.net.MalformedURLException: unknown protocol: javascript at java.net.URL.<init>(Unknown Source) at java.net.URL.<init>(Unknown Source) at sun.plugin2.message.helper.URLHelper.read(URLHelper.java:42) at sun.plugin2.message.CookieOpMessage.readFields(CookieOpMessage.java:67) at sun.plugin2.message.transport.SerializingTransport.read(SerializingTransport.java:108) at sun.plugin2.message.Pipe$WorkerThread.run(Pipe.java:308) JVMInstance (1.8.0.ea) processing CookieOpMessage The above exception caused URL to be NULL, while MozillaPlugin catch NPE caused by that and throw CookieUnavailableException accordingly, IExplorerPlugin doesn't handle NPE properly thus cause not responding. Exception in thread "Thread-0" java.lang.NullPointerException at com.sun.deploy.net.cookie.IExplorerCookieHandler.getCookieInfo(IExplorerCookieHandler.java:55) at sun.plugin2.main.server.IExplorerPlugin.getCookie(IExplorerPlugin.java:468) at sun.plugin2.main.server.CookieSupport.getCookieReply(CookieSupport.java:17) at sun.plugin2.main.server.JVMInstance$6.run(JVMInstance.java:1206) at sun.plugin2.main.server.IExplorerPlugin$1.run(IExplorerPlugin.java:388)
24-01-2012