Skip to content

Commit

Permalink
If set doesn't request lock then true should be returned.
Browse files Browse the repository at this point in the history
  • Loading branch information
tjwatson committed Jun 20, 2024
1 parent 1c3c169 commit 029433d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit 029433d

Please sign in to comment.