Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7038890

CookieHandler.getDefault().get() with "javascript:" URI hangs or otherwise works incorrectly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 8
    • 6u24
    • deploy
    • b23
    • generic
    • generic
    • Verified

        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.

              henryjen Henry Jen
              vbaranov Vasiliy Baranov (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: