Skip to content

Commit 16c0edb

Browse files
committed
Use Initialize-on-demand holder idiom for StateObjectFactory
As a result of 14f66ae, it might happen that the MinimalState is shut down, even though it was never started. In such a case, the class is implicitly loaded while stopping the plug-in. When loading this class, the "stateObjectFactory" is initialized using the PlatformAdmin provided by the PDE Build bundle. If this bundle is stopped before the PDE Core bundle, an exception is thrown because the PlatformAdmin is no longer available. To resolve this, the StateObjectFactory is loaded only when required for the first time. Closes #1714
1 parent 14f66ae commit 16c0edb

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/MinimalState.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666

6767
public class MinimalState {
6868

69+
protected static class SingletonHolder {
70+
protected static final StateObjectFactory STATE_OBJECT_FACTORY = BundleHelper.getPlatformAdmin().getFactory();
71+
}
72+
6973
private static final IPreferenceChangeListener PREF_CHANGE_LISTENER = e -> {
7074
if (e.getKey().equals("org.eclipse.jdt.launching.PREF_DEFAULT_ENVIRONMENTS_XML")) { //$NON-NLS-1$
7175
Object oldValue = e.getOldValue() == null ? "" : e.getOldValue(); //$NON-NLS-1$
@@ -111,16 +115,10 @@ public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
111115

112116
private boolean fNoProfile;
113117

114-
protected static StateObjectFactory stateObjectFactory;
115-
116118
protected String fSystemBundle = IPDEBuildConstants.BUNDLE_OSGI;
117119

118-
static {
119-
stateObjectFactory = BundleHelper.getPlatformAdmin().getFactory();
120-
}
121-
122120
protected MinimalState(MinimalState state) {
123-
this.fState = stateObjectFactory.createState(state.fState);
121+
this.fState = SingletonHolder.STATE_OBJECT_FACTORY.createState(state.fState);
124122
this.fState.setPlatformProperties(state.fState.getPlatformProperties());
125123
this.fState.setResolver(BundleHelper.getPlatformAdmin().createResolver());
126124
this.fId = state.fId;
@@ -213,8 +211,8 @@ public BundleDescription addBundle(Map<String, String> manifest, File bundleLoca
213211
try {
214212
// OSGi requires a dictionary over any map
215213
Dictionary<String, String> dictionaryManifest = FrameworkUtil.asDictionary(manifest);
216-
BundleDescription descriptor = stateObjectFactory.createBundleDescription(fState, dictionaryManifest,
217-
bundleLocation.getAbsolutePath(), bundleId == -1 ? getNextId() : bundleId);
214+
BundleDescription descriptor = SingletonHolder.STATE_OBJECT_FACTORY.createBundleDescription(fState,
215+
dictionaryManifest, bundleLocation.getAbsolutePath(), bundleId == -1 ? getNextId() : bundleId);
218216
// new bundle
219217
if (bundleId == -1 || !fState.updateBundle(descriptor)) {
220218
fState.addBundle(descriptor);

ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/PDEState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2005, 2016 IBM Corporation and others.
2+
* Copyright (c) 2005, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -77,7 +77,7 @@ public PDEState(URI[] target, boolean addResolver, boolean removeDuplicates, IPr
7777
}
7878

7979
private void createNewTargetState(boolean resolve, URI[] uris, IProgressMonitor monitor) {
80-
fState = stateObjectFactory.createState(resolve);
80+
fState = SingletonHolder.STATE_OBJECT_FACTORY.createState(resolve);
8181
if (resolve) {
8282
final String systemBSN = getSystemBundle();
8383
Comparator<BaseDescription> policy = systemBundlesFirst(systemBSN)

0 commit comments

Comments
 (0)