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

Race condition in URLConnection::getContentHandler

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • None
    • 9
    • core-libs
    • None

      URLConnection::getContentHandler has a benign race condition on stuffing URLConnection.handlers map with new handlers.

      URLConnection::getContentHandler synchronizes on an instance rather than on the class:

      private static Hashtable<String, ContentHandler> handlers = new Hashtable<>();

          /**
           * Gets the Content Handler appropriate for this connection.
           */
          synchronized ContentHandler getContentHandler()
              throws UnknownServiceException
          {
              String contentType = stripOffParameters(getContentType());
              ContentHandler handler = null;
              if (contentType == null)
                  throw new UnknownServiceException("no content-type");
              try {
                  handler = handlers.get(contentType);
                  if (handler != null)
                      return handler;
              } catch(Exception e) {
              }

              if (factory != null)
                  handler = factory.createContentHandler(contentType);
              if (handler == null) {
                  try {
                      handler = lookupContentHandlerClassFor(contentType);
                  } catch(Exception e) {
                      e.printStackTrace();
                      handler = UnknownContentHandler.INSTANCE;
                  }
                  handlers.put(contentType, handler);
              }
              return handler;
          }

            prappo Pavel Rappo (Inactive)
            prappo Pavel Rappo (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: