Bug 64134 NPE in JavaRuntime on Workbench Exit.
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/Framework.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/Framework.java
index fcc080f..f92a823 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/Framework.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/Framework.java
@@ -447,6 +447,11 @@
 		if (!active) {
 			return;
 		}
+		/*
+		 * set the state of the System Bundle to STOPPING.
+		 * this must be done first according to section 4.19.2 from the OSGi R3 spec.  
+		 */
+		systemBundle.state = AbstractBundle.STOPPING;
 		/* call the FrameworkAdaptor.frameworkStopping method first */
 		try {
 			adaptor.frameworkStopping(systemBundle.getContext());
diff --git a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java
index db6443b..066950b 100644
--- a/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java
+++ b/bundles/org.eclipse.osgi/core/framework/org/eclipse/osgi/framework/internal/core/StartLevelManager.java
@@ -599,9 +599,6 @@
 		BundleRepository bundles = framework.bundles;
 
 		if (activeSL == 0) { // stopping the framework
-
-			framework.systemBundle.state = AbstractBundle.STOPPING;
-
 			/* stop all running bundles */
 
 			suspendAllBundles(bundles);