Skip to content

Commit b672b4c

Browse files
committed
Defer accessing instance preferences until service is registered
Otherwise one might run into "ISE: The instance data location has not been specified yet." depending on the bundle start order Also only register workspace change listener when workspace service is available. This closes #684
1 parent 093343f commit b672b4c

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingPlugin.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,17 @@
8383
import org.eclipse.jdt.launching.JavaRuntime;
8484
import org.eclipse.jdt.launching.VMStandin;
8585
import org.eclipse.jdt.launching.sourcelookup.ArchiveSourceLocation;
86+
import org.eclipse.osgi.service.datalocation.Location;
8687
import org.eclipse.osgi.service.debug.DebugOptions;
8788
import org.eclipse.osgi.service.debug.DebugOptionsListener;
8889
import org.eclipse.osgi.service.debug.DebugTrace;
8990
import org.eclipse.osgi.util.NLS;
9091
import org.osgi.framework.BundleContext;
92+
import org.osgi.framework.Filter;
9193
import org.osgi.framework.ServiceReference;
9294
import org.osgi.service.prefs.BackingStoreException;
9395
import org.osgi.util.tracker.ServiceTracker;
96+
import org.osgi.util.tracker.ServiceTrackerCustomizer;
9497
import org.w3c.dom.Document;
9598
import org.w3c.dom.Element;
9699
import org.w3c.dom.Node;
@@ -201,6 +204,11 @@ public class LaunchingPlugin extends Plugin implements DebugOptionsListener, IEc
201204
*/
202205
private ServiceTracker<IWorkspace, IWorkspace> fWorkspaceServiceTracker;
203206

207+
/**
208+
* Service tracker for the instance location service
209+
*/
210+
private ServiceTracker<Location, Location> fInstanceLocationServiceTracker;
211+
204212
/**
205213
* Stores VM changes resulting from a JRE preference change.
206214
*/
@@ -535,13 +543,12 @@ public void stop(BundleContext context) throws Exception {
535543

536544
DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
537545
DebugPlugin.getDefault().removeDebugEventListener(this);
538-
ResourcesPlugin.getWorkspace().removeResourceChangeListener(this);
539546
ArchiveSourceLocation.closeArchives();
540-
InstanceScope.INSTANCE.getNode(ID_PLUGIN).removePreferenceChangeListener(this);
541547
JavaRuntime.removeVMInstallChangedListener(this);
542548
JavaRuntime.saveVMConfiguration();
543549
fgXMLParser = null;
544550
fWorkspaceServiceTracker.close();
551+
fInstanceLocationServiceTracker.close();
545552
} finally {
546553
super.stop(context);
547554
}
@@ -584,6 +591,7 @@ public void saving(ISaveContext context1) throws CoreException {
584591
writeInstallInfo();
585592
}
586593
});
594+
workspace.addResourceChangeListener(LaunchingPlugin.this, IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
587595
} catch (CoreException e) {
588596
log(e.getStatus());
589597
context.ungetService(reference);
@@ -595,15 +603,36 @@ public void saving(ISaveContext context1) throws CoreException {
595603
@Override
596604
public void removedService(ServiceReference<IWorkspace> reference, IWorkspace service) {
597605
service.removeSaveParticipant(ID_PLUGIN);
606+
service.removeResourceChangeListener(LaunchingPlugin.this);
598607
context.ungetService(reference);
599608
}
600609

601610
};
602611
fWorkspaceServiceTracker.open();
603612

604-
InstanceScope.INSTANCE.getNode(ID_PLUGIN).addPreferenceChangeListener(this);
613+
Filter instanceLocationFilter = context.createFilter("(&(objectClass=" + Location.class.getName() + ")(" + Location.SERVICE_PROPERTY_TYPE //$NON-NLS-1$ //$NON-NLS-2$
614+
+ "=" + Location.INSTANCE_AREA_TYPE + "))"); //$NON-NLS-1$ //$NON-NLS-2$
615+
fInstanceLocationServiceTracker = new ServiceTracker<>(context, instanceLocationFilter, new ServiceTrackerCustomizer<Location, Location>() {
616+
@Override
617+
public void removedService(ServiceReference<Location> reference, Location service) {
618+
InstanceScope.INSTANCE.getNode(ID_PLUGIN).removePreferenceChangeListener(LaunchingPlugin.this);
619+
}
620+
621+
@Override
622+
public Location addingService(ServiceReference<Location> reference) {
623+
InstanceScope.INSTANCE.getNode(ID_PLUGIN).addPreferenceChangeListener(LaunchingPlugin.this);
624+
// no need to track the service
625+
return null;
626+
}
627+
628+
@Override
629+
public void modifiedService(ServiceReference<Location> reference, Location service) {
630+
}
631+
632+
});
633+
fInstanceLocationServiceTracker.open();
634+
605635
JavaRuntime.addVMInstallChangedListener(this);
606-
ResourcesPlugin.getWorkspace().addResourceChangeListener(this, IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
607636
DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
608637
DebugPlugin.getDefault().addDebugEventListener(this);
609638
AdvancedSourceLookupSupport.start();

0 commit comments

Comments
 (0)