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

Adam Pilkington commented on ARIES-1225:
----------------------------------------

I noticed that check as well, and did some cross referencing with the OSGi 
spec, and the subsystem moves through a number of states - would the check be 
better to say that unless the subsystem was in one of the states that is 
guaranteed to have the region set it returns null ? This would then cover other 
transient states such as installing. The reason for asking is that this error 
was thrown during server startup/bundle installation.

> NPE thrown by GetBundleContextAction 
> -------------------------------------
>
>                 Key: ARIES-1225
>                 URL: https://issues.apache.org/jira/browse/ARIES-1225
>             Project: Aries
>          Issue Type: Improvement
>          Components: Subsystem
>            Reporter: Adam Pilkington
>            Priority: Trivial
>   Original Estimate: 10m
>  Remaining Estimate: 10m
>
> Hi, I'm currently investigating a NPE thrown by GetBundleContextAction - 
> stack trace is below.
> java.lang.NullPointerException
>       at 
> org.apache.aries.subsystem.core.internal.GetBundleContextAction.run(GetBundleContextAction.java:35)
>       at 
> org.apache.aries.subsystem.core.internal.GetBundleContextAction.run(GetBundleContextAction.java:22)
>       at 
> java.security.AccessController.doPrivileged(AccessController.java:273)
>       at 
> org.apache.aries.subsystem.core.internal.BasicSubsystem.getBundleContext(BasicSubsystem.java:186)
>       <snip>
>       
> I don't know what has caused this, but looking at GetBundleContextAction, 
> line 35 contains nested method invocations more than one of which can return 
> null. I'd like to submit/suggest the following patch which just splits this 
> line out and adds some basic error checking. 
> Index: GetBundleContextAction.java
> ===================================================================
> --- GetBundleContextAction.java       (revision 1607078)
> +++ GetBundleContextAction.java       (working copy)
> @@ -16,6 +16,8 @@
>  import java.security.PrivilegedAction;
>  import java.util.EnumSet;
>  
> +import org.eclipse.equinox.region.Region;
> +import org.osgi.framework.Bundle;
>  import org.osgi.framework.BundleContext;
>  import org.osgi.service.subsystem.Subsystem.State;
>  
> @@ -26,15 +28,23 @@
>               this.subsystem = subsystem;
>       }
>       
> -     @Override
>       public BundleContext run() {
>               if (EnumSet.of(State.INSTALL_FAILED, 
> State.UNINSTALLED).contains(
>                               subsystem.getState()))
>                       return null;
>               BasicSubsystem subsystem = 
> Utils.findScopedSubsystemInRegion(this.subsystem);
> -             return subsystem.getRegion().getBundle(
> -                             RegionContextBundleHelper.SYMBOLICNAME_PREFIX
> -                                             + subsystem.getSubsystemId(),
> -                             
> RegionContextBundleHelper.VERSION).getBundleContext();
> +             
> +             Region region = subsystem.getRegion();
> +             if(region == null) {
> +                     //can return null as under the covers it calls 
> RegionDigraph.getRegion(name)
> +                     return null;
> +             }
> +             Bundle bundle = 
> region.getBundle(RegionContextBundleHelper.SYMBOLICNAME_PREFIX
> +                                             + subsystem.getSubsystemId(), 
> RegionContextBundleHelper.VERSION);
> +             if(bundle == null) {
> +                     //null if no such bundle
> +                     return null;
> +             }
> +             return bundle.getBundleContext();
>       }
>  }



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to