Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 347559

Summary: Setting the Frameworks Startlevel while another thread shut down the framework produce null-pointer
Product: [Eclipse Project] Equinox Reporter: Christoph Laeubrich <laeubi>
Component: FrameworkAssignee: Thomas Watson <tjwatson>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: tjwatson
Version: unspecified   
Target Milestone: Luna M1   
Hardware: PC   
OS: Linux   
Whiteboard:

Description Christoph Laeubrich CLA 2011-05-28 15:39:16 EDT
Build Identifier: Equinox 3.6

[ERROR] Stopping the framework failed! [d.l.a.i.WebUpdateService] 
java.lang.IllegalArgumentException: null
	at org.eclipse.osgi.framework.eventmgr.ListenerQueue.<init>(ListenerQueue.java:61) ~[na:na]
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.issueEvent(StartLevelManager.java:404) ~[na:na]
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.setStartLevel(StartLevelManager.java:200) ~[na:na]
	at org.eclipse.osgi.framework.internal.core.StartLevelManager.setStartLevel(StartLevelManager.java:205) ~[na:na]
	at de.laeubisoft.autoupdate.internal.WebUpdateService.installUpdatesNow(WebUpdateService.java:212) [de.laeubisoft.autoupdate/:na]
	at de.laeubisoft.autoupdate.internal.WebUpdateService.access$2(WebUpdateService.java:137) [de.laeubisoft.autoupdate/:na]
	at de.laeubisoft.autoupdate.internal.WebUpdateService$1.installUpdates(WebUpdateService.java:96) [de.laeubisoft.autoupdate/:na]
	at de.laeubisoft.autoupdate.gui.UpdateGUI$3$2.run(UpdateGUI.java:252) [de.laeubisoft.autoupdate.gui/:na]
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [na:1.6.0_23]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [na:1.6.0_23]
	at java.lang.Thread.run(Thread.java:662) [na:1.6.0_23]

Reproducible: Sometimes

Steps to Reproduce:
1. One thread issues BundleContext.getBundle(0).start()
2. Another issuses StartLevel.setStartLevel(...)
3. java.lang.IllegalArgumentException: null is thrown
Comment 1 Thomas Watson CLA 2011-05-31 09:51:31 EDT
The StartLevelManager code needs to be cleaned up a bit.  It has some static fields for the manager and listeners that should be instance fields that never get nulled out.  

(In reply to comment #0)
> Steps to Reproduce:
> 1. One thread issues BundleContext.getBundle(0).start()
> 2. Another issuses StartLevel.setStartLevel(...)
> 3. java.lang.IllegalArgumentException: null is thrown

I suspect step 1) is really to call STOP BundleContext.getBundle(0).stop() on bundle id=0?

There are two ways I could see a framework deciding to react to this situation.  1) throw some kind of runtime exception indicating that the StartLevel service is no longer functional (similar to what is done right now) 2) silently ignoring the request because the framework has shutdown.

Personally I think option 1 is the better behavior.  Just to confirm, this exception did not prevent the framework from shutting down, correct?
Comment 2 Christoph Laeubrich CLA 2011-05-31 10:35:31 EDT
(In reply to comment #1)
> I suspect step 1) is really to call STOP BundleContext.getBundle(0).stop() on
> bundle id=0?
You are right of course :)

> Just to confirm, this exception did not prevent the framework from shutting down, correct?
I'm not 100% sure but I think yes, the shutdown is not interrupted.

> There are two ways I could see a framework deciding to react to this situation.
I would prefer the first since there is nothing the application could do about it it should be ignored, maybe a warning can be issued to the Logservice, because the specification does not state that any exception should be exspected beside IllegalArgumentException and SecurityException, and even it is mandatory to change the startlevel in a background thread, so the caller should never get an exception which is caused by the progress of changing levels!

Beside this, I confess its a very rare use-case ;)
Comment 3 Christoph Laeubrich CLA 2011-05-31 10:51:08 EDT
Another think comes up when while I reading spec:
8.2.2 (changeing the active startlevel) it is stated that each request of changing the startlevel must first be completed before the next one is starte.

A little further (8.2.4: Shutdown sequence) it is mentioned, that the framework must behave as if the startlevel is set to ZERO!

imo this has the following consequences: stopping the systembundle (and therefore shut down the framework as changing to level 0) should either
a) simply shut down and nothing happens if the concurrent levelchange happens before
b) first progress the startlevelchange from the other thread and after that shut down
c) throw an IllegalstateException or whatever is sufficent when calling framework methods on an already shut down framework
Comment 4 Thomas Watson CLA 2011-06-08 11:31:04 EDT
Move all 3.8 bugs to Juno.
Comment 5 Thomas Watson CLA 2012-05-14 10:51:16 EDT
The start-level code is going to be restructured when we prototype OSGi inter-op and Java 8 modules.
Comment 6 Thomas Watson CLA 2013-03-20 11:24:13 EDT
This is fixed in the twatson/container branch where the restructuring of the framework is going on for Luna.
Comment 7 Thomas Watson CLA 2013-05-06 12:01:43 EDT
Marking fixed for M1.