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 219a7a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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 @@ -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 219a7a9

Please sign in to comment.