[icedtea-web] RFC: fix null dtd for swing applications rendering html

Deepak Bhole dbhole at redhat.com
Tue Oct 26 13:33:40 PDT 2010


* Omair Majid <omajid at redhat.com> [2010-10-26 15:46]:
> Hi,
> 
> There has been a regression in netx: applications that render html
> (using Swing components) now fail with a null pointer exception.
> This problem can be reproduced by running the program at [1].
> 

What caused this regression? I thought all the app context stuff was
still disabled, with just the support added on the side?

> The problem is caused by how HTMLEditorKit/HTMLDocument and
> ParserDelgator interact in the presence of multiple AppContexts. The
> instance of the ParserDelegate is shared between multiple
> HTMLEditorKit in different AppContexts. However, ParserDelegate
> maintains a per-AppContext dtd instance. The dtd is valid in the
> AppContext that created the ParserDelegate but null in all other
> AppContexts. Using this null dtd throws a NullPointerException. This
> is really a bug in OpenJDK6 rather than Netx. Fortunately, this bug
> has been fixed in OpenJDK7 - ParserDelegate maintains an instance of
> the dtd per runtime instead of per AppContext.
> 
> The attached patch works around this bug. It manually creates a
> ParserDelegate for each AppContext to avoid this problem.
> 

Assuming you have tested this, OK for head.

Cheers,
Deepak

> ChangeLog
> 2010-10-26  Omair Majid  <omajid at redhat.com>
> 
>     * netx/net/sourceforge/jnlp/Launcher.java
>     (doPerApplicationAppContextHacks): New method.
>     (TgThread.run): Call doPerApplicationAppContextHacks.
>     * netx/net/sourceforge/jnlp/runtime/JNLPRuntime
>     (initialize): Call doMainAppContextHacks.
>     (doMainAppContextHacks): New method.
> 
> Any comments?
> 
> Thanks,
> Omair
> 
> [1] http://www.ucware.com/apev/jaws/apev.jnlp

> diff -r b1b876d99849 netx/net/sourceforge/jnlp/Launcher.java
> --- a/netx/net/sourceforge/jnlp/Launcher.java	Mon Oct 25 17:16:13 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/Launcher.java	Tue Oct 26 13:55:32 2010 -0400
> @@ -50,6 +50,7 @@
>  import net.sourceforge.jnlp.util.Reflect;
>  
>  import javax.swing.SwingUtilities;
> +import javax.swing.text.html.parser.ParserDelegator;
>  
>  import sun.awt.SunToolkit;
>  
> @@ -778,6 +779,22 @@
>          }
>      }
>  
> +    /**
> +     * Do hacks on per-application level to allow different AppContexts to work
> +     *
> +     * @see JNLPRuntime#doMainAppContextHacks
> +     */
> +    private static void doPerApplicationAppContextHacks() {
> +
> +        /*
> +         * With OpenJDK6 (but not with 7) a per-AppContext dtd is maintained.
> +         * This dtd is created by the ParserDelgate. However, the code in
> +         * HTMLEditorKit (used to render HTML in labels and textpanes) creates
> +         * the ParserDelegate only if there are no existing ParserDelegates. The
> +         * result is that all other AppContexts see a null dtd.
> +         */
> +        new ParserDelegator();
> +    }
>  
>      /**
>       * This runnable is used to call the appropriate launch method
> @@ -815,6 +832,8 @@
>                  if (context && !isPlugin)
>                          SunToolkit.createNewAppContext();
>  
> +                doPerApplicationAppContextHacks();
> +
>                  if (isPlugin) {
>                          // Do not display download indicators if we're using gcjwebplugin.
>                          JNLPRuntime.setDefaultDownloadIndicator(null);
> diff -r b1b876d99849 netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java
> --- a/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java	Mon Oct 25 17:16:13 2010 -0400
> +++ b/netx/net/sourceforge/jnlp/runtime/JNLPRuntime.java	Tue Oct 26 13:55:32 2010 -0400
> @@ -27,6 +27,7 @@
>  import javax.jnlp.*;
>  import javax.naming.ConfigurationException;
>  import javax.swing.UIManager;
> +import javax.swing.text.html.parser.ParserDelegator;
>  
>  import net.sourceforge.jnlp.*;
>  import net.sourceforge.jnlp.cache.*;
> @@ -232,6 +200,8 @@
>              // ignore it
>          }
>  
> +        doMainAppContextHacks();
> +
>          if (securityEnabled) {
>              Policy.setPolicy(policy); // do first b/c our SM blocks setPolicy
>              System.setSecurityManager(security);
> @@ -261,6 +231,23 @@
>      }
>  
>      /**
> +     * Performs a few hacks that are needed for the main AppContext
> +     *
> +     * @see Launcher#doPerApplicationAppContextHacks
> +     */
> +    private static void doMainAppContextHacks() {
> +
> +        /*
> +         * With OpenJDK6 (but not with 7) a per-AppContext dtd is maintained.
> +         * This dtd is created by the ParserDelgate. However, the code in
> +         * HTMLEditorKit (used to render HTML in labels and textpanes) creates
> +         * the ParserDelegate only if there are no existing ParserDelegates. The
> +         * result is that all other AppContexts see a null dtd.
> +         */
> +        new ParserDelegator();
> +    }
> +
> +    /**
>       * Gets the Configuration associated with this runtime
>       * @return a {@link DeploymentConfiguration} object that can be queried to
>       * find relevant configuration settings




More information about the distro-pkg-dev mailing list