Skip to content

Commit

Permalink
Added check for not intended default workspace location use (eclipse-…
Browse files Browse the repository at this point in the history
…platform#35)

See original bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=514333
that was only partly fixed.

The original fix added -Dosgi.dataAreaRequiresExplicitInit=true system
property and changed org.eclipse.core.internal.runtime.DataArea in the
way that it doesn't allow to initialize itself if the workspace location
was not explicitly specified yet - either via -data or via workspace
selection prompt.

But the fix in DataArea does not work if bad client code calls
Platform.getLocation() *before* calling Plugin.getStateLocation(),
because Platform.getLocation() doesn't run into changed DataArea code at
all.

Exact this happened in commit
eclipse-platform/eclipse.platform.resources@a8a8d82
where workspace init order was slightly changed: original code
initialized LocalMetaArea first (which then failed as supposed in
assertLocationInitialized() if workspace was not set yet), and after
that initialized WorkspaceRoot (which uses Platform.getLocation() after
the check). Changed code initialized WorkspaceRoot first, and because
this uses Platform.getLocation(), the code silently initializes default
workspace location even if -Dosgi.dataAreaRequiresExplicitInit=true is
set.

The current fix makes sure that if the system flag is given, we disallow
silent workspace location initialization by adding similar check in
Platform.getLocation().

Fixes issue
eclipse-platform#35
  • Loading branch information
iloveeclipse committed Apr 22, 2022
1 parent 8e95f2d commit 1ab5d57
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public final class InternalPlatform {
public static final String PROP_NL = "osgi.nl"; //$NON-NLS-1$
public static final String PROP_OS = "osgi.os"; //$NON-NLS-1$

// OSGI IDE specific property, copied from DataArea
private static final String PROP_REQUIRES_EXPLICIT_INIT = "osgi.dataAreaRequiresExplicitInit"; //$NON-NLS-1$ ;

// Eclipse System Properties
public static final String PROP_PRODUCT = "eclipse.product"; //$NON-NLS-1$
public static final String PROP_WS = "osgi.ws"; //$NON-NLS-1$
Expand Down Expand Up @@ -341,11 +344,24 @@ public Location getInstanceLocation() {
public IPath getLocation() throws IllegalStateException {
if (cachedInstanceLocation == null) {
Location location = getInstanceLocation();
if (location == null)
if (location == null) {
return null;
}
if (!location.isSet()) {
boolean explicitInitRequired = Boolean
.parseBoolean(getBundleContext().getProperty(PROP_REQUIRES_EXPLICIT_INIT));
if (explicitInitRequired) {
// See bug 514333: don't allow clients to initialize instance location if the
// instance area is not explicitly defined yet
throw new IllegalStateException(CommonMessages.meta_instanceDataUnspecified);
}
}

// Note: if not explicitly set, this call will resolve to default location
// therefore we have the check above, but only if PROP_REQUIRES_EXPLICIT_INIT is set.
URL url = location.getURL();
if (url == null) {
throw new IllegalStateException("instance location is not (yet) set"); //$NON-NLS-1$
throw new IllegalStateException("Instance location is not (yet) set"); //$NON-NLS-1$
}
// This makes the assumption that the instance location is a file: URL
File file = new File(url.getFile());
Expand Down

0 comments on commit 1ab5d57

Please sign in to comment.