Skip to content

Commit

Permalink
Fix BasicLocation set method when read-only and lock requested
Browse files Browse the repository at this point in the history
eclipse-equinox/equinox.framework#39 PR
introduced a breaking change that always returned true with a
read-only location and lock was requested to the set method.

The testCreateLocation04 method also needed fixing to properly
test this case.
  • Loading branch information
tjwatson committed Jun 20, 2024
1 parent c8ce736 commit 8e89831
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
Expand All @@ -42,7 +43,6 @@
import org.eclipse.osgi.service.datalocation.Location;
import org.eclipse.osgi.tests.OSGiTestsActivator;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand Down Expand Up @@ -164,17 +164,19 @@ public void testCreateLocation03() {
}

@Test
public void testCreateLocation04() {
public void testCreateLocation04() throws IllegalStateException, MalformedURLException, IOException {
Location configLocation = configLocationTracker.getService();
File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testCreateLocation04");
Location testLocation = configLocation.createLocation(null, null, true);
try {
testLocation.set(testLocationFile.toURL(), true);
// note that if read-only and lock was requested then false is returned; but the
// location is set
assertFalse("Could not set location", testLocation.set(testLocationFile.toURL(), true));
assertTrue("Location should be set", testLocation.isSet());

assertThrows("Should not be able to lock read-only location", IOException.class, () -> {
assertTrue("Could not lock location", testLocation.lock());
testLocation.release();
Assert.fail("Should not be able to lock read-only location");
} catch (Throwable t) {
// expected
}
});
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public synchronized boolean set(URL value, boolean lock, String lockFilePath)
}
}
updateUrl(serviceRegistration);
return true;
return lock;
}

private void updateUrl(ServiceRegistration<?> registration) {
Expand Down

0 comments on commit 8e89831

Please sign in to comment.