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 2023d7f576e..bead8f79282 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 @@ -180,15 +180,14 @@ public void testCreateLocation04() throws IllegalStateException, MalformedURLExc } @Test - public void testCreateLocation05() { + public void testCreateLocation05() throws IllegalStateException, MalformedURLException, IOException { Location configLocation = configLocationTracker.getService(); File testLocationFile = OSGiTestsActivator.getContext().getDataFile("testLocations/testCreateLocation01"); Location testLocation = configLocation.createLocation(null, null, false); - try { - testLocation.set(testLocationFile.toURL(), false); - } catch (Throwable t) { - fail("Failed to set location", t); - } + + assertTrue("Could not set location", testLocation.set(testLocationFile.toURL(), false)); + assertTrue("Location should be set", testLocation.isSet()); + try { assertTrue("Could not lock location", testLocation.lock()); assertFalse("Could lock a secend time", testLocation.lock()); 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 45e95e12c5f..4b238ad483c 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 @@ -136,6 +136,7 @@ public synchronized boolean set(URL value, boolean lock) throws IllegalStateExce @Override public synchronized boolean set(URL value, boolean lock, String lockFilePath) throws IllegalStateException, IOException { + boolean gotLock = false; synchronized (this) { if (location != null) throw new IllegalStateException(Msg.ECLIPSE_CANNOT_CHANGE_LOCATION); @@ -159,10 +160,11 @@ public synchronized boolean set(URL value, boolean lock, String lockFilePath) file = new File(value.getPath(), DEFAULT_LOCK_FILENAME); } } - lock = lock && !isReadOnly; - if (lock) { - if (!lock(file, value)) + if (lock && !isReadOnly) { + if (!lock(file, value)) { return false; + } + gotLock = true; } lockFile = file; location = value; @@ -171,7 +173,7 @@ public synchronized boolean set(URL value, boolean lock, String lockFilePath) } } updateUrl(serviceRegistration); - return lock; + return lock ? gotLock : true; } private void updateUrl(ServiceRegistration registration) {