From 8e89831f3447378c71393a5c20d91ad27504b1d1 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Thu, 20 Jun 2024 08:24:15 -0500 Subject: [PATCH] Fix BasicLocation set method when read-only and lock requested https://github.com/eclipse-equinox/equinox.framework/pull/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. --- .../datalocation/BasicLocationTests.java | 18 ++++++++++-------- .../osgi/internal/location/BasicLocation.java | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java index 750ae482c2f..2023d7f576e 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/BasicLocationTests.java @@ -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; @@ -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; @@ -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 diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/BasicLocation.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/BasicLocation.java index 2c52c946431..45e95e12c5f 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/BasicLocation.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/location/BasicLocation.java @@ -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) {