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

URI.getPath() throws NullPointerException if path has spaces and in event queue

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs
    • x86
    • windows_98



      Name: jl125535 Date: 12/21/2001


      java version "1.4.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
      Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)


      URI.getPath() throws NullPointerException if
      (1) path has space, and
      (2) method invoken in event queue handling thread

      I think this worked in 1.4 beta 1, maybe 1.4 beta 2 also.


      import java.awt.*;
      import java.net.*;

      /**
      Invoking URI.getPath() on a URI with encoded spaces (%20) in the path
      FROM WITHIN THE EVENT PROCESSING THREAD
      throws a NullPointerException.

      Java 1.4 beta 3. I think this worked in beta 1.

      Run code from command line, then move mouse into window to cause error.


      Sample trace:


      //D/prj/Multivalent/src/multivalent/std/adaptor/pdf % java phelps.UriBoom
      from main thread -- works
      uri = http://www.sun.com/some/path/with%20space/java.html#%23anyref
      scheme = http
      path = /some/path/with space/java.html


      [move mouse into window]
      from event queue thread -- THROWS EXCEPTION
      uri = http://www.sun.com/some/path/with%20space/java.html#%23anyref
      scheme = http
      java.lang.NullPointerException
      at sun.nio.cs.ThreadLocalCoders$Cache.forName(ThreadLocalCoders.java:45)

      at sun.nio.cs.ThreadLocalCoders.decoderFor(ThreadLocalCoders.java:86)
      at java.net.URI.decode(URI.java:2640)
      at java.net.URI.getPath(URI.java:1297)
      at phelps.UriBoom.showURI(UriBoom.java:21)
      at phelps.UriBoom.processEvent(UriBoom.java:12)
      at java.awt.Component.dispatchEventImpl(Component.java:3527)
      at java.awt.Container.dispatchEventImpl(Container.java:1440)
      at java.awt.Window.dispatchEventImpl(Window.java:1568)
      at java.awt.Component.dispatchEvent(Component.java:3368)
      at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
      at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
      read.java:193)
      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
      ad.java:147)
      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:141)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:133)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:101)

      */

      public class UriBoom extends Frame {
        protected void processEvent(AWTEvent e) {
      System.out.println("from event queue thread -- THROWS EXCEPTION");
      showURI();
        }


        static void showURI() {
      try {
      // path without space OK
      //URI uri = new URI("http",
                      // "www.sun.com",
                      // "/some/path/without/space/java.html",
                      // "#anyref");

      // path with space + getPath() => BOOM
      URI uri = new URI("http",
                                        "www.sun.com",
                                        "/some/path/with%20space/java.html",
                                        "anyref");

      System.out.println("uri = "+uri);
      System.out.println("scheme = "+uri.getScheme()); // ok
      System.out.println("path = "+uri.getPath()); // BOOM
      System.out.println();

      } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
      }
        }

        public static void main(String[] argv) {
      System.out.println("from main thread -- works");
      showURI(); // ok
      System.out.println();

      UriBoom f = new UriBoom();
      f.enableEvents(AWTEvent.MOUSE_EVENT_MASK | AWTEvent.MOUSE_MOTION_EVENT_MASK);
      f.setBounds(100,100, 200,200);
      f.show();
        }
      }

      (Review ID: 136876)
      ======================================================================

            Unassigned Unassigned
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: