code simplification, added further assertions for Coverity issue 72293

This commit is contained in:
Sebastian Stenzel
2016-03-04 01:29:34 +01:00
parent 997f841662
commit adc20ea2f2
3 changed files with 8 additions and 9 deletions

View File

@@ -167,7 +167,9 @@ class DavFile extends DavNode<FileLocator> {
public ActiveLock lock(LockInfo reqLockInfo) throws DavException {
ActiveLock lock = super.lock(reqLockInfo);
if (!exists()) {
getCollection().addMember(this, new NullInputContext());
DavFolder parentFolder = getCollection();
assert parentFolder != null : "File always has a folder.";
parentFolder.addMember(this, new NullInputContext());
}
return lock;
}

View File

@@ -37,6 +37,7 @@ import org.apache.jackrabbit.webdav.property.DavPropertySet;
import org.apache.jackrabbit.webdav.property.DefaultDavProperty;
import org.apache.jackrabbit.webdav.property.PropEntry;
import org.cryptomator.filesystem.jackrabbit.FileSystemResourceLocator;
import org.cryptomator.filesystem.jackrabbit.FolderLocator;
abstract class DavNode<T extends FileSystemResourceLocator> implements DavResource {
@@ -187,18 +188,14 @@ abstract class DavNode<T extends FileSystemResourceLocator> implements DavResour
}
@Override
public DavResource getCollection() {
public DavFolder getCollection() {
if (node.isRootLocation()) {
return null;
}
assert node.parent().isPresent() : "as my mom always sais: if it's not root, it has a parent";
final FileSystemResourceLocator parentPath = node.parent().get();
try {
return factory.createResource(parentPath, session);
} catch (DavException e) {
throw new IllegalStateException("Unable to get parent resource with path " + parentPath, e);
}
final FolderLocator parentPath = node.parent().get();
return factory.createFolder(parentPath, session);
}
@Override

View File

@@ -50,7 +50,7 @@ class FilesystemResourceFactory implements DavResourceFactory {
}
@Override
public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
public DavResource createResource(DavResourceLocator locator, DavSession session) {
if (locator instanceof FolderLocator) {
FolderLocator folder = (FolderLocator) locator;
return createFolder(folder, session);