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

Remove javax.imageio.spi.ServiceRegistry.finalize()

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 26
    • client-libs
    • None
    • behavioral
    • low
    • Hide
      The risk of this low because the only JDK instance will never be collected/freed, and 3rd parties are very limited in their use of this API since it supports only the standard Image I/O providers, and the JDK instance already supports that. So non-JDK instances are likely extremely rare and may not need collecting even if they do exist.
      Show
      The risk of this low because the only JDK instance will never be collected/freed, and 3rd parties are very limited in their use of this API since it supports only the standard Image I/O providers, and the JDK instance already supports that. So non-JDK instances are likely extremely rare and may not need collecting even if they do exist.
    • Java API
    • SE

      Summary

      javax.imageio.spi.ServiceRegistry.finalize() is removed.

      Problem

      Finalization is deprecated, but javax.imageio.spi.ServiceRegistry has a finalize() method.

      Solution

      • Remove the finalize() method.
      • Document that if a ServiceRegistry is no longer needed, the application should call ServiceRegistry.deregisterAll()
      • Remove from other methods javadoc, text related to the finalization behaviour
      • Not related, but also update the class doc to remove obsolete reference to runtime permissions.
      • Update the implementation and specification of javax.imageio.spi.IIORegistry.getDefaultInstance() so that it is now a singleton in all cases, and so never will be collected.

      Specification

      javax/imageio/spi/ServiceRegistry.java class doc

      * <p> An application may customize the contents of a registry as it
      - * sees fit, so long as it has the appropriate runtime permission.
      + * sees fit.

      finalize method removal

      -    /**
      -     * Finalizes this object prior to garbage collection.  The
      -     * {@code deregisterAll} method is called to deregister all
      -     * currently registered service providers.  This method should not
      -     * be called from application code.
      -     *
      -     * @throws Throwable if an error occurs during superclass
      -     * finalization.
      -     *
      -     * @deprecated Finalization has been deprecated for removal.  See
      -     * {@link java.lang.Object#finalize} for background information and details
      -     * about migration options.
      -     */
      -    @Deprecated(since="9", forRemoval=true)
      -    @SuppressWarnings("removal")
      -    public void finalize() throws Throwable 
      public void registerServiceProvider(Object provider)
            * {@code onDeregistration} method will be called each time
      -     * it is deregistered from a category or when the registry is
      -     * finalized.
      +     * it is deregistered from a category.
      public void registerServiceProviders(Iterator<?> providers) {
            * {@code onDeregistration} method will be called each time
      -     * it is deregistered from a category or when the registry is
      -     * finalized.
      +     * it is deregistered from a category.
           public void deregisterAll() 
      +     * If an application creates a new {@code ServiceRegistry} instance and registers providers,
      +     * and at some point no longer needs the instance, it should call this method to ensure
      +     * that all providers which are instances of {@link RegisterableService}
      +     * receive a {@link RegisterableService#onDeregistration(ServiceRegistry, Class<?>)} call back,
      +     * before allowing the instance to be garbage collected.

      javax/imageio/spi/IIORegistry

           /**
            * Returns the default {@code IIORegistry} instance used by
            * the Image I/O API.  This instance should be used for all
            * registry functions.
      -     *
      -     * <p> Each {@code ThreadGroup} will receive its own instance.
      -     *
      -     * @return the default registry for the current
      -     * {@code ThreadGroup}.
      +     * @return the default registry for the Image I/O API
            */
           public static IIORegistry getDefaultInstance()

            prr Philip Race
            prr Philip Race
            Alexander Zvegintsev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: