You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Pavel B (JIRA)" <ji...@apache.org> on 2013/06/17 20:41:20 UTC

[jira] [Comment Edited] (FELIX-4068) Restarting Felix from Web Console throwing a NullPointerException and wouldn't restart (2 fixes/work-arounds required in org.apache.felix.framework.BundleRevisionImpl)

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

Pavel B edited comment on FELIX-4068 at 6/17/13 6:41 PM:
---------------------------------------------------------

While trying to make Felix Restart option working – I am faced another place of NULL Pointer Exceptions in
Felix/src/main/java/org/apache/felix/framework/Felix.java
•	URL getBundleResource(BundleImpl bundle, String name)
•	Enumeration getBundleResources(BundleImpl bundle, String name)
•	Class loadBundleClass(BundleImpl bundle, String name)

Proposed temporally Fixed/Workaround code as following (after applying this fix for symptoms - real issue is easy to catch) :

    /**
     * Implementation for Bundle.getResource().
    **/
    URL getBundleResource(BundleImpl bundle, String name)
    {
        URL bundleResources = null;
        BundleWiringImpl bwi = null;
        BundleRevisionImpl bri = null;
                   . . .
        // If the bundle revision isn't resolved, then just search locally, otherwise delegate.
        try
        {
            bwi = (BundleWiringImpl)bundle.adapt(BundleRevision.class).getWiring();
        }
        catch(Throwable te)
        {
            bwi = null;
        }
        if(bwi == null)
        {
            bri = (BundleRevisionImpl)bundle.adapt(BundleRevision.class);
            bundleResources = bri.getResourceLocal(name);
        }
        else
        {
            bundleResources = bwi.getResourceByDelegation(name);
        }
        return bundleResources;
    }


    /**
     * Implementation for Bundle.getResources().
    **/
    Enumeration getBundleResources(BundleImpl bundle, String name)
    {
        Enumeration bundleResources = null;
        BundleWiringImpl bwi = null;
        BundleRevisionImpl bri = null;
                   . . .
        // If the bundle revision isn't resolved, then just search locally, otherwise delegate.
        try
        {
            bwi = (BundleWiringImpl)bundle.adapt(BundleRevision.class).getWiring();
        }
        catch(Throwable te)
        {
            bwi = null;
        }
        if(bwi == null)
        {
            bri = (BundleRevisionImpl)bundle.adapt(BundleRevision.class);
            bundleResources = bri.getResourcesLocal(name);
        }
        else
        {
            bundleResources = bwi.getResourcesByDelegation(name);
        }
        return bundleResources;
    }

    /**
     * Implementation for Bundle.loadClass().
    **/
    Class loadBundleClass(BundleImpl bundle, String name) throws ClassNotFoundException
    {
        Class bundleClass = null;
        BundleWiringImpl bwi = null;
                   . . .
        try
        {
            bwi = (BundleWiringImpl)bundle.adapt(BundleWiring.class);
        }
        catch(Throwable te)
        {
            bwi = null;
        }
        if(bwi != null)
        {
            if (name.charAt(0) == '[')
            {
                    bundleClass = Class.forName(name, false, bwi.getClassLoader());
            }
            else
            {
                    bundleClass = bwi.getClassLoader().loadClass(name);
            }
        }
        return bundleClass;
    }


                
      was (Author: pavelb01):
    While trying to make Felix Restart option working – I am faced another place of NULL Pointer Exceptions in
Felix/src/main/java/org/apache/felix/framework/Felix.java
•	URL getBundleResource(BundleImpl bundle, String name)
•	Enumeration getBundleResources(BundleImpl bundle, String name)
•	Class loadBundleClass(BundleImpl bundle, String name)

Proposed temporally Fixed/Workaround code as following (after applying this fix for symptoms - real issue is easy to catch) :

    /**
     * Implementation for Bundle.getResource().
    **/
    URL getBundleResource(BundleImpl bundle, String name)
    {
        URL bundleResources = null;
        BundleWiringImpl bwi = null;
        BundleRevisionImpl bri = null;
                   . . .
        bwi = (BundleWiringImpl)bundle.adapt(BundleRevision.class).getWiring();
        if(bwi == null)
        {
            bri = (BundleRevisionImpl)bundle.adapt(BundleRevision.class);
            bundleResources = bri.getResourceLocal(name);
        }
        else
        {
            bundleResources = bwi.getResourceByDelegation(name);
        }
        return bundleResources;
    }


    /**
     * Implementation for Bundle.getResources().
    **/
    Enumeration getBundleResources(BundleImpl bundle, String name)
    {
        Enumeration bundleResources = null;
        BundleWiringImpl bwi = null;
        BundleRevisionImpl bri = null;
                   . . .
        bwi = (BundleWiringImpl)bundle.adapt(BundleRevision.class).getWiring();
        if(bwi == null)
        {
            bri = (BundleRevisionImpl)bundle.adapt(BundleRevision.class);
            bundleResources = bri.getResourcesLocal(name);
        }
        else
        {
            bundleResources = bwi.getResourcesByDelegation(name);
        }
        return bundleResources;
    }

    /**
     * Implementation for Bundle.loadClass().
    **/
    Class loadBundleClass(BundleImpl bundle, String name) throws ClassNotFoundException
    {
        Class bundleClass = null;
        BundleWiringImpl bwi = null;
                   . . .
        try
        {
            bwi = (BundleWiringImpl)bundle.adapt(BundleWiring.class);
        }
        catch(Throwable te)
        {
            bwi = null;
        }
        if(bwi != null)
        {
            if (name.charAt(0) == '[')
            {
                    bundleClass = Class.forName(name, false, bwi.getClassLoader());
            }
            else
            {
                    bundleClass = bwi.getClassLoader().loadClass(name);
            }
        }
        return bundleClass;
    }


                  
> Restarting Felix from Web Console throwing a NullPointerException and wouldn't restart (2 fixes/work-arounds required in org.apache.felix.framework.BundleRevisionImpl)
> -----------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: FELIX-4068
>                 URL: https://issues.apache.org/jira/browse/FELIX-4068
>             Project: Felix
>          Issue Type: Bug
>          Components: Framework
>    Affects Versions: framework-4.0.0
>         Environment: I am running OSGi Felix 4.2.0, and when re-starting from Web console - following error created for pax-web-jetty-bundle-2.1.2.jar
> java.lang.NullPointerException
>                 at org.apache.felix.framework.BundleRevisionImpl.getResourceLocal(BundleRevisionImpl.java:498)
>                 at org.apache.felix.framework.Felix.getBundleResource(Felix.java:1595)
>                 at org.apache.felix.framework.BundleImpl.getResource(BundleImpl.java:639)
>                 at org.ops4j.pax.swissbox.core.BundleClassLoader.findResource(BundleClassLoader.java:210)
>                 at org.ops4j.pax.swissbox.core.BundleClassLoader.getResource(BundleClassLoader.java:142)
>                 at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:1193)
>                 at javax.xml.parsers.SecuritySupport$4.run(SecuritySupport.java:96)
>                 at java.security.AccessController.doPrivileged(Native Method)
>                 at javax.xml.parsers.SecuritySupport.getResourceAsStream(SecuritySupport.java:89)
>                 at javax.xml.parsers.FactoryFinder.findJarServiceProvider(FactoryFinder.java:250)
>                 at javax.xml.parsers.FactoryFinder.find(FactoryFinder.java:223)
>                 at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:123)
>                 at org.ops4j.util.xml.ElementHelper.getRootElement(ElementHelper.java:68)
>                 at org.ops4j.pax.web.service.internal.DefaultPropertyResolver.getDefaltProperties(DefaultPropertyResolver.java:64)
>                 at org.ops4j.pax.web.service.internal.DefaultPropertyResolver.<init>(DefaultPropertyResolver.java:55)
>                 at org.ops4j.pax.web.service.internal.Activator.updateController(Activator.java:289)
>                 at org.ops4j.pax.web.service.internal.Activator$4.run(Activator.java:258)
>                 at org.ops4j.pax.web.service.internal.Executor$Future.run(Executor.java:45)
>                 at org.ops4j.pax.web.service.internal.Executor$Worker.run(Executor.java:122)
> Following is the set of my bundles:
> cd /Felix/felix-framework-4.2.0
> java -Dorg.osgi.framework.bootdelegation=sun.misc -jar bin/felix.jar
> install file:bin/logging/slf4j-api-1.7.2.jar
> install file:bin/logging/logback-core-1.0.9.jar
> install file:bin/logging/logback-classic-1.0.9.jar
> install file:bin/console/org.apache.felix.configadmin-1.6.0.jar
> install file:bin/base/pax-web-jetty-bundle-2.1.2.jar
> install file:bin/base/commons-io-2.4.jar
> install file:bin/base/commons-codec-1.7.jar
> install file:bin/base/commons-collections-3.2.1.jar
> install file:bin/base/commons-httpclient-3.1.0.jar
> install file:bin/base/commons-fileupload-1.2.2.jar
> install file:bin/base/commons-logging-1.1.1.jar
> install file:bin/base/org.ow2.chameleon.commons.json-20090911-0002.jar
> install file:bin/console/org.apache.felix.webconsole-4.0.0.jar
> install file:bin/console/org.apache.felix.metatype-1.0.6.jar
> install file:bin/console/org.apache.felix.log-1.0.1.jar
>            Reporter: Pavel B
>              Labels: Restart-Felix
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Same fix/work-around in 2 methods of class: org.apache.felix.framework.BundleRevisionImpl
>     URL getResourceLocal(String name)
>     Enumeration getResourcesLocal(String name)
> Instead of:                if (contentPath.get(i).hasEntry(name))
> Should be:                if (contentPath.get(i) != null && contentPath.get(i).hasEntry(name))

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira