Skip to content

Commit

Permalink
Fail if a workspace is disposed outside the manager
Browse files Browse the repository at this point in the history
Currently one can obtain a workspace baseline and dispose it leading to
hard to track errors.

This now fails if someone tries to dispose the baseline without using
the manager.
  • Loading branch information
laeubi committed Dec 27, 2024
1 parent 0d51f20 commit 7c521f8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion apitools/org.eclipse.pde.api.tools/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.pde.api.tools;singleton:=true
Bundle-Version: 1.3.600.qualifier
Bundle-Version: 1.3.700.qualifier
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public final class ApiBaselineManager implements IApiBaselineManager, ISaveParti
/**
* The current workspace baseline
*/
private volatile IApiBaseline workspacebaseline;
private volatile WorkspaceBaseline workspacebaseline;

/**
* The default save location for persisting the cache from this manager.
Expand Down Expand Up @@ -548,7 +548,7 @@ public void stop() {
}
synchronized (this) {
if (workspacebaseline != null) {
workspacebaseline.dispose();
workspacebaseline.disposeInternal();
}
}
if (handlecache != null) {
Expand Down Expand Up @@ -620,12 +620,12 @@ public IApiBaseline getWorkspaceBaseline() {
* the next request.
*/
public void disposeWorkspaceBaseline() {
final IApiBaseline originalBaseline = workspacebaseline;
final WorkspaceBaseline originalBaseline = workspacebaseline;
if (originalBaseline == null) {
return;
}
IJobFunction runnable = m -> {
IApiBaseline oldBaseline = null;
WorkspaceBaseline oldBaseline = null;
synchronized (ApiBaselineManager.this) {
if (workspacebaseline != null && originalBaseline == workspacebaseline) {
if (ApiPlugin.DEBUG_BASELINE_MANAGER) {
Expand All @@ -637,7 +637,7 @@ public void disposeWorkspaceBaseline() {
}
}
if (oldBaseline != null) {
oldBaseline.dispose();
oldBaseline.disposeInternal();
}
return Status.OK_STATUS;
};
Expand Down Expand Up @@ -681,9 +681,9 @@ public boolean isConflicting(ISchedulingRule rule) {
*
* @return a new workspace {@link IApiBaseline} or <code>null</code>
*/
private IApiBaseline createWorkspaceBaseline() throws CoreException {
private WorkspaceBaseline createWorkspaceBaseline() throws CoreException {
long time = System.currentTimeMillis();
IApiBaseline baseline = new WorkspaceBaseline();
WorkspaceBaseline baseline = new WorkspaceBaseline();
try {
// populate it with only projects that are API aware
List<IPluginModelBase> models = Arrays.asList(PluginRegistry.getWorkspaceModels());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public WorkspaceBaseline() {

@Override
public void dispose() {
throw new UnsupportedOperationException(
"ApiBaselineManager.disposeWorkspaceBaseline() must be used to dispose the workspace baseline"); //$NON-NLS-1$
}

/**
* <b>Only public for technical reasons</b> do not call directly!
*/
public void disposeInternal() {
doDispose();
mismatch.clear();
}
Expand Down

0 comments on commit 7c521f8

Please sign in to comment.