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

Peter Gardfjäll commented on FELIX-2191:
----------------------------------------

I did some research into this matter.
Without being familiar with the inner workings of the FeatureServiceImpl class, 
there seems to be something weird going on which causes the features map to be 
nulled whenever a feature repository is added/removed. This causes the NPE 
later on in installFeatures. I made some small changes to prevent the features 
map from being nulled and apparently that made the NPE go away. I don't know if 
it's a solution but I thought it might at least provide some guidance to 
solving this issue. The following is a diff of the changes I introduced against 
the karaf 1.4.0 branch.

Index: 
src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java
===================================================================
--- 
src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java 
    (revision 925639)
+++ 
src/main/java/org/apache/felix/karaf/features/internal/FeaturesServiceImpl.java 
    (working copy)
@@ -85,7 +85,7 @@
     private PreferencesService preferences;
     private Set<URI> uris;
     private Map<URI, RepositoryImpl> repositories = new HashMap<URI, 
RepositoryImpl>();
-    private Map<String, Map<String, Feature>> features;
+    private Map<String, Map<String, Feature>> features = new HashMap<String, 
Map<String,Feature>>();
     private Map<Feature, Set<Long>> installed = new HashMap<Feature, 
Set<Long>>();
     private String boot;
     private boolean bootFeaturesInstalled;
@@ -170,7 +170,9 @@
         repo.load();
         repositories.put(uri, repo);
         callListeners(new RepositoryEvent(repo, 
RepositoryEvent.EventType.RepositoryAdded, false));
-        features = null;
+        LOGGER.info("internalAddRepository: " + uri);
+        Thread.currentThread().dumpStack();
+        features.clear();
         return repo;
         
     }
@@ -185,7 +187,8 @@
     public void internalRemoveRepository(URI uri) {
         Repository repo = repositories.remove(uri);
         callListeners(new RepositoryEvent(repo, 
RepositoryEvent.EventType.RepositoryRemoved, false));
-        features = null;
+        LOGGER.info("internalRemoveRepository");
+        features.clear();
     }
 
     public Repository[] listRepositories() {
@@ -603,7 +606,7 @@
     }
 
     protected Map<String, Map<String, Feature>> getFeatures() throws Exception 
{
-        if (features == null) {
+        if (features.isEmpty()) {
                //the outer map's key is feature name, the inner map's key is 
feature version       
             Map<String, Map<String, Feature>> map = new HashMap<String, 
Map<String, Feature>>();
             // Two phase load:
@@ -895,6 +898,7 @@
     }
 
     public Set<Feature> getFeaturesContainingBundle (Bundle bundle) {
+       LOGGER.info("getFeaturesContainingBundle: this.features: " + 
this.features);
         Set<Feature> features = new HashSet<Feature>();
         for (Map<String, Feature> featureMap : this.features.values()) {
             for (Feature f : featureMap.values()) {


> Drop-in deployment of feature descriptor with spring-dm bundles fails
> ---------------------------------------------------------------------
>
>                 Key: FELIX-2191
>                 URL: https://issues.apache.org/jira/browse/FELIX-2191
>             Project: Felix
>          Issue Type: Bug
>          Components: Karaf
>    Affects Versions: karaf-1.4.0
>         Environment: Windows 7
> Java 1.6.0_16
>            Reporter: Peter Gardfjäll
>
> Drop-in deployment of a feature descriptor in the deploy/ directory fails 
> when the feature descriptor contains spring-dm 1.2.1 bundles.
> Reproduce as follows:
> (1) Start a fresh instance of Karaf 1.4.0 (unzip a new distribution and run 
> bin\karaf.bat) 
> (2) Copy a feature.xml file with the following contents to the deploy/ 
> directory
> <features>
>   <feature name="org.osgi.sample.sample.dependencies">
>     <bundle>mvn:org.springframework.osgi/spring-osgi-extender/1.2.1</bundle>
>     <bundle>mvn:org.springframework.osgi/spring-osgi-core/1.2.1</bundle>
>     <bundle>mvn:org.springframework.osgi/spring-osgi-io/1.2.1</bundle>
>     <bundle>mvn:org.springframework.osgi/spring-osgi-web/1.2.1</bundle>
>   </feature>
> </features>
> This fails and gives the following error entry in the log:
> 20:09:20,819 | ERROR | lixDispatchQueue | FeatureDeploymentListener
>     | atures.FeatureDeploymentListener  136 | Unable to install
> features
> java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>         at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:597)
>         at 
> org.apache.geronimo.blueprint.container.AbstractServiceReferenceRecipe$JdkProxyFactory$1.invoke(AbstractServiceReferenceRecipe.java:561)
>         at $Proxy4.installFeatures(Unknown Source)
>         at 
> org.apache.felix.karaf.deployer.features.FeatureDeploymentListener.bundleChanged(FeatureDeploymentListener.java:132)
>         at 
> org.apache.felix.framework.util.EventDispatcher.invokeBundleListenerCallback(EventDispatcher.java:800)
>         at 
> org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:728)
>         at 
> org.apache.felix.framework.util.EventDispatcher.run(EventDispatcher.java:942)
>         at 
> org.apache.felix.framework.util.EventDispatcher.access$000(EventDispatcher.java:54)
>         at 
> org.apache.felix.framework.util.EventDispatcher$1.run(EventDispatcher.java:106)
>         at java.lang.Thread.run(Thread.java:619)
> Caused by: java.lang.NullPointerException
>         at 
> org.apache.felix.karaf.features.internal.FeaturesServiceImpl.getFeaturesContainingBundle(FeaturesServiceImpl.java:899)
>         at 
> org.apache.felix.karaf.features.internal.FeaturesServiceImpl.getFeaturesContainingBundleList(FeaturesServiceImpl.java:910)
>         at 
> org.apache.felix.karaf.features.internal.FeaturesServiceImpl.installFeatures(FeaturesServiceImpl.java:296)
>         ... 13 more

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to