[ 
https://issues.apache.org/jira/browse/FELIX-4837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16133983#comment-16133983
 ] 

Nicolas Roduit commented on FELIX-4837:
---------------------------------------

Thanks for sharing your experience! It is also one of the strangest and most 
difficult bugs I have ever dealt with.

As it has been fixed in Java 9, I will add a check:

{code}
    /**
     * @see https://bugs.openjdk.java.net/browse/JDK-8054639
     *
     */
    private static void evilEvilWebstartHack() {
        // Handle new versioning from Java 9
        String jvmVersionString = 
System.getProperty("java.specification.version");
        int verIndex = jvmVersionString.indexOf("1.");
        if (verIndex >= 0) {
            jvmVersionString = jvmVersionString.substring(verIndex + 2);
        }
        int major = Integer.parseInt(jvmVersionString);
        if (major < 9) {
            // this is the hack of a lifetime here.
            // there is a bug that arrived sometime around the mid java7 
releases. shutdown hooks get created that
            // shutdown loggers and close down the classloader jars that means 
that anything we try to do in our
            // shutdown hook throws an exception, but only after some random 
amount of time
            try {
                Class<?> clazz = 
Class.forName("java.lang.ApplicationShutdownHooks");
                Field field = clazz.getDeclaredField("hooks");
                field.setAccessible(true);
                Map<?, Thread> hooks = (Map<?, Thread>) field.get(clazz);
                for (Iterator<Thread> it = hooks.values().iterator(); 
it.hasNext();) {
                    Thread thread = it.next();
                    if 
("javawsSecurityThreadGroup".equals(thread.getThreadGroup().getName())) {
                        it.remove();
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
{code}

> Workaround for JNLPClassLoader in ShutdownHook 
> -----------------------------------------------
>
>                 Key: FELIX-4837
>                 URL: https://issues.apache.org/jira/browse/FELIX-4837
>             Project: Felix
>          Issue Type: Bug
>          Components: Framework
>    Affects Versions: framework-5.0.1, framework-5.6.1, framework-5.6.4
>         Environment: all
>            Reporter: Nicolas Roduit
>            Assignee: Karl Pauls
>
> This a workaround of the issue that I submitted on 
> https://bugs.openjdk.java.net/browse/JDK-8054639
> The Java Web Start classloader doesn't support to have anonymous classes or 
> enum within the shutdown hook.
> The patch below allows to stop all the bundles correctly when calling  
> m_felix.stop() in the shutdown hook. Otherwise the framework throws an 
> exception and do not call the bundle stop. This is a problem when each bundle 
> write its preferences or state during the stop method.
> {code}                 
> diff --git a/framework/src/main/java/org/apache/felix/framework/Felix.java 
> b/framework/src/main/java/org/apache/felix/framework/Felix.java
> index c6b305a..e44ccea 100644
> --- a/framework/src/main/java/org/apache/felix/framework/Felix.java
> +++ b/framework/src/main/java/org/apache/felix/framework/Felix.java
> @@ -1023,7 +1023,7 @@
>          {
>              // Spec says stop() on SystemBundle should return immediately and
>              // shutdown framework on another thread.
> -            new Thread(new Runnable() {
> +            Thread t = new Thread( "FelixShutdown"){
>                  public void run()
>                  {
>                      try
> @@ -1038,7 +1038,8 @@
>                              ex);
>                      }
>                  }
> -            }, "FelixShutdown").start();
> +            };
> +            t.start();
>          }
>      }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to