StreamHandlerFactory shf = (StreamHandlerFactory) factoryField.get(null);
URLStreamHandlerFactory factory = (URLStreamHandlerFactory) factoryField.get(null); if (factory == streamHandlerFactory) { factory = (URLStreamHandlerFactory) streamHandlerFactory.designateSuccessor(); } else { Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); unregister.invoke(factory, new Object[] {streamHandlerFactory}); }
	private static void uninstallURLStreamHandlerFactory() {		try {			Field factoryField = getStaticField(URL.class, URLStreamHandlerFactory.class);			if (factoryField == null)				return; // oh well, we tried			// look for a lock to synchronize on			Object lock;			try {				Field streamHandlerLockField = URL.class.getDeclaredField("streamHandlerLock"); //$NON-NLS-1$				streamHandlerLockField.setAccessible(true);				lock = streamHandlerLockField.get(null);			} catch (NoSuchFieldException noField) {				// could not find the lock, lets sync on the class object				lock = URL.class;			}			synchronized (lock) {				StreamHandlerFactory shf = (StreamHandlerFactory) factoryField.get(null);				factoryField.set(null, null);				// always attempt to clear the handlers cache				// Note that the call to setURLStreamHandlerFactory below may clear this cache				// but we want to be sure to clear it here just incase the parent is null.				// In this case the call below would not occur.				Field handlersField = getStaticField(URL.class, Hashtable.class);				if (handlersField != null) {					Hashtable handlers = (Hashtable) handlersField.get(null);					if (handlers != null)						handlers.clear();				}				if (shf != null && shf.getParentFactory() != null) 					URL.setURLStreamHandlerFactory(shf.getParentFactory());			}		} catch (Exception e) {			// ignore and continue closing the framework		}	}