[RFC][icedtea-web] BasicService code does not work if used in applet constructors
Deepak Bhole
dbhole at redhat.com
Mon Dec 19 09:02:22 PST 2011
* Danesh Dadachanji <ddadacha at redhat.com> [2011-12-19 11:57]:
> Hi,
>
> When looking up BasicService, ServiceManager uses JNLPClassLoader's
> app var. This is setup when the application/applet is created.
> However, if BasicService code is used in the applet's constructor,
> it will produce an incomplete basic service var (i.e most vars are
> set to null).
>
> I've move the applet initialization code after the loader's app
> variable is set. However, in order to set the app, I've modified the
> initialization of AppletInstance to take a null parameter in place
> of the applet. I went through the code but found no use of this
> applet var until after the call to createApplet (i.e. after the var
> has been set). It is possible for another thread to access the
> AppletInstnace's applet var before it is actually set but there is
> no code in icedtea-web doing that so far.
>
ChangeLog indentation looks a bit off. After fixing, OK for head.
Cheers,
Deepak
> ChangeLog:
> +2011-12-19 Danesh Dadachanji <ddadacha at redhat.com>
> +
> + Fix for BasicService being used in applet constructors but not
> + having access to ApplicationInstance variable.
> + * netx/net/sourceforge/jnlp/Launcher.java:
> + (createApplet): Moved applet initialization below loader.setApplication,
> + appletInstance is now initialized with applet param as null.
> + * netx/net/sourceforge/jnlp/runtime/AppletInstance.java:
> + (setApplet): New method, allows setting of AppletInstance's applet
> + only once.
> +
>
> Regards,
> Danesh
> diff -r 331a58713544 netx/net/sourceforge/jnlp/Launcher.java
> --- a/netx/net/sourceforge/jnlp/Launcher.java Fri Dec 16 12:12:18 2011 -0500
> +++ b/netx/net/sourceforge/jnlp/Launcher.java Mon Dec 19 11:31:40 2011 -0500
> @@ -708,18 +708,19 @@ public class Launcher {
>
> ThreadGroup group = Thread.currentThread().getThreadGroup();
>
> + AppletInstance appletInstance;
> + if (cont == null)
> + appletInstance = new AppletInstance(file, group, loader, null);
> + else
> + appletInstance = new AppletInstance(file, group, loader, null, cont);
> +
> + loader.setApplication(appletInstance);
> +
> String appletName = file.getApplet().getMainClass();
> Class appletClass = loader.loadClass(appletName);
> Applet applet = (Applet) appletClass.newInstance();
> -
> - AppletInstance appletInstance;
> - if (cont == null)
> - appletInstance = new AppletInstance(file, group, loader, applet);
> - else
> - appletInstance = new AppletInstance(file, group, loader, applet, cont);
> -
> - loader.setApplication(appletInstance);
> -
> + appletInstance.setApplet(applet);
> +
> setContextClassLoaderForAllThreads(appletInstance.getThreadGroup(), appletInstance.getClassLoader());
>
> return appletInstance;
> diff -r 331a58713544 netx/net/sourceforge/jnlp/runtime/AppletInstance.java
> --- a/netx/net/sourceforge/jnlp/runtime/AppletInstance.java Fri Dec 16 12:12:18 2011 -0500
> +++ b/netx/net/sourceforge/jnlp/runtime/AppletInstance.java Mon Dec 19 11:31:40 2011 -0500
> @@ -52,6 +52,20 @@ public class AppletInstance extends Appl
> }
>
> /**
> + * Set the applet of this launched application; can only be called once.
> + */
> + public void setApplet(Applet applet) {
> + if (this.applet != null) {
> + if (JNLPRuntime.isDebug()) {
> + Exception ex = new IllegalStateException("Applet can only be set once.");
> + ex.printStackTrace();
> + }
> + return;
> + }
> + this.applet = applet;
> + }
> +
> + /**
> *
> */
> public AppletInstance(JNLPFile file, ThreadGroup group, ClassLoader loader, Applet applet, Container cont) {
More information about the distro-pkg-dev
mailing list