Skip to content

Commit

Permalink
Improved error handling
Browse files Browse the repository at this point in the history
Rely on BundleContext.(un)getService(...) instead of ServiceTracker impl
  • Loading branch information
kwin authored and laeubi committed Oct 21, 2023
1 parent 0884d2d commit 97e0144
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,11 @@ public void start(BundleContext context) throws Exception {

@Override
public IWorkspace addingService(ServiceReference<IWorkspace> reference) {
IWorkspace workspace = super.addingService(reference);
IWorkspace workspace = context.getService(reference);
if (workspace == null) {
logMessage("Could not add save participant as IWorkspace service is unavailable", null); //$NON-NLS-1$
return null;
}
try {
workspace.addSaveParticipant(getUniqueIdentifier(), new ISaveParticipant() {
@Override
Expand All @@ -764,14 +768,16 @@ public void doneSaving(ISaveContext saveContext) {
});
} catch (CoreException e) {
log(e.getStatus());
context.ungetService(reference);
return null;
}
return workspace;
}

@Override
public void removedService(ServiceReference<IWorkspace> reference, IWorkspace service) {
service.removeSaveParticipant(getUniqueIdentifier());
super.removedService(reference, service);
context.ungetService(reference);
}

};
Expand Down

0 comments on commit 97e0144

Please sign in to comment.