This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 191035 - Exception "Fragment bundles can not be started."
Summary: Exception "Fragment bundles can not be started."
Status: RESOLVED FIXED
Alias: None
Product: platform
Classification: Unclassified
Component: Netigso (show other bugs)
Version: 6.x
Hardware: PC Linux
: P1 normal with 1 vote (vote)
Assignee: Jaroslav Tulach
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-15 15:55 UTC by vadeg
Modified: 2010-11-02 03:58 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Sample with fragment bundle (168.14 KB, application/octet-stream)
2010-10-28 05:54 UTC, vadeg
Details

Note You need to log in before you can comment on or make changes to this bug.
Description vadeg 2010-10-15 15:55:59 UTC
If add to any module fragment bundle as dependency and build and start platform with modules, an exception will be thrown:
org.osgi.framework.BundleException: Fragment bundles can not be started.
        at org.apache.felix.framework.Felix.startBundle(Felix.java:1600)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:905)
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:892)
        at org.netbeans.core.netigso.Netigso.createLoader(Netigso.java:233)

This caused, because Netigso trying to start all bundles into Felix calling
Bundle.start() method. Here is the "bug" code:

Method:
org.netbeans.core.netigso.Netigso#createLoader(ModuleInfo m, ProxyClassLoader pcl, File jar)

Line: 231-234
pcl.append(new ClassLoader[]{ l });
LOG.log(Level.FINE, "Starting bundle {0}", m.getCodeNameBase());
b.start();

Calling b.start(); on Fragment bundle caused exception above.
Comment 1 Jaroslav Tulach 2010-10-18 09:47:51 UTC
Is it wise to depend on a fragment? I'd expect one depends only on real bundles, fragments get loaded by default then.

Can you prepare me some bundles (or at least their manifests), so I can create a JUnit test case?
Comment 2 vadeg 2010-10-18 12:37:21 UTC
I think it doesn't matter. Netigso loads all bundles automcatically and calls start() on every bundle.

Ok, I'll prepare a bundle for the tests.
Comment 3 Jaroslav Tulach 2010-10-19 10:24:40 UTC
Right. As soon as NetBeans module depends on a bundle, the bundle.start() is called.

So far it worked well, but I admit I have not used a bundle fragment yet. I hope that by reading your sample/test case, I will gain more knowledge about OSGi fragments.
Comment 4 Jaroslav Tulach 2010-10-27 14:21:47 UTC
7.0 Beta is supposed to be released soon. If you want this fix in there, please prepare the sample soon.
Comment 5 vadeg 2010-10-28 05:54:52 UTC
Created attachment 102692 [details]
Sample with fragment bundle

Hello!

I've prepared an example with fragment bundle. Here is some description:
Module "fragment.bundle" - this is the fragment bundle, which contains log4j config file.

Module "fragmenthost" - this a simple OSGi bundle, which depends of "com.springsource.org.apache.log4j" bundle and prints a few messages via log4j in Activator. 
"com.springsource.org.apache.log4j" uses fragment bundle to get logger propeties - "fragment.bundle". This is a common way to configure Log4j in OSGi.

Module "fragment.test-sample" - simple NB module, which uses "fragmenthost" and "fragment.bundle".

If you'll start platform application, you'll see an error:
"org.osgi.framework.BundleException: Fragment bundles can not be started."

If you'll comment dependency from "fragment.bundle" in "fragment.test-sample" module, everything will be fine.

A successful result will be, if you see log messages from activator in application log.


If you'll start
Comment 6 Jaroslav Tulach 2010-11-01 08:17:18 UTC
I am getting error during Clean&Build on the fragment.test project:

Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
Copying 0 resource
Downloading: http://bits.netbeans.org/maven2/org/apache/log4j/com.springsource.org.apache.log4j/1.2.16/com.springsource.org.apache.log4j-1.2.16.pom
Unable to find resource 'org.apache.log4j:com.springsource.org.apache.log4j:pom:1.2.16' in repository netbeans (http://bits.netbeans.org/maven2)
Downloading: http://repository.springsource.com/maven/bundles/release/org/apache/log4j/com.springsource.org.apache.log4j/1.2.16/com.springsource.org.apache.log4j-1.2.16.pom
Unable to find resource 'org.apache.log4j:com.springsource.org.apache.log4j:pom:1.2.16' in repository com.springsource.repository.bundles.release (http://repository.springsource.com/maven/bundles/release)
Downloading: http://repo1.maven.org/maven2/org/apache/log4j/com.springsource.org.apache.log4j/1.2.16/com.springsource.org.apache.log4j-1.2.16.pom
Unable to find resource 'org.apache.log4j:com.springsource.org.apache.log4j:pom:1.2.16' in repository central (http://repo1.maven.org/maven2)
Downloading: http://bits.netbeans.org/maven2/org/apache/log4j/com.springsource.org.apache.log4j/1.2.16/com.springsource.org.apache.log4j-1.2.16.jar
Unable to find resource 'org.apache.log4j:com.springsource.org.apache.log4j:jar:1.2.16' in repository netbeans (http://bits.netbeans.org/maven2)
Downloading: http://repository.springsource.com/maven/bundles/release/org/apache/log4j/com.springsource.org.apache.log4j/1.2.16/com.springsource.org.apache.log4j-1.2.16.jar
Unable to find resource 'org.apache.log4j:com.springsource.org.apache.log4j:jar:1.2.16' in repository com.springsource.repository.bundles.release (http://repository.springsource.com/maven/bundles/release)
Downloading: http://repo1.maven.org/maven2/org/apache/log4j/com.springsource.org.apache.log4j/1.2.16/com.springsource.org.apache.log4j-1.2.16.jar
Unable to find resource 'org.apache.log4j:com.springsource.org.apache.log4j:jar:1.2.16' in repository central (http://repo1.maven.org/maven2)
------------------------------------------------------------------------
BUILD ERROR
------------------------------------------------------------------------
Failed to resolve artifact.

Missing:
----------
1) org.apache.log4j:com.springsource.org.apache.log4j:jar:1.2.16

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=org.apache.log4j -DartifactId=com.springsource.org.apache.log4j -Dversion=1.2.16 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there: 
      mvn deploy:deploy-file -DgroupId=org.apache.log4j -DartifactId=com.springsource.org.apache.log4j -Dversion=1.2.16 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
          1) com.mycompany:fragmenthost:bundle:1.0-SNAPSHOT
          2) org.apache.log4j:com.springsource.org.apache.log4j:jar:1.2.16
Comment 7 Jaroslav Tulach 2010-11-01 08:55:06 UTC
Anyway thanks for the sample, I guess I got idea how fragment looks like. Few questions first: Why do you depend on the fragment bundle? 

To compile and use its classes? Then you can use just compile time dependency.
To use the classes during runtime? Well, I am expecting the OSGi container to use the fragment as soon as its fragment host is started.

Anyway I can disable calling of the fragment start() method easily: core-main#73616c5ec0c5
Comment 8 vadeg 2010-11-01 09:11:55 UTC
(In reply to comment #7)
> Anyway thanks for the sample, I guess I got idea how fragment looks like. Few
> questions first: 
Why do you depend on the fragment bundle? 

Because some bundles need some configuration files, which are packaged as additional bundles. F.e. I'm developing some bundle, which has different behavior, which depends on runtime environment (netbeans app, standalone, etc.) Behavior depends on some setting in configuration files. I can make one bundle for any environment and 2 fragment bundles with different settings.

> 
> To compile and use its classes? Then you can use just compile time dependency.

Yes, but I'm using thirdparty libraries, which I don't want to change. :)

> To use the classes during runtime? Well, I am expecting the OSGi container to
> use the fragment as soon as its fragment host is started.
> 
> Anyway I can disable calling of the fragment start() method easily:
> core-main#73616c5ec0c5

You don't need to disable start() for all bundles. Only for fragment bundles. :)


I forgot to add one repository. Just put in "fragment.test" module
<repository>
    <id>com.springsource.repository.bundles.external</id>
    <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name>
    <url>http://repository.springsource.com/maven/bundles/external</url>
</repository>
and it should work.
Comment 9 Quality Engineering 2010-11-02 03:58:24 UTC
Integrated into 'main-golden', will be available in build *201011020000* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main/rev/73616c5ec0c5
User: Jaroslav Tulach <jtulach@netbeans.org>
Log: #191035: Don't start fragment bundles