daledotshan/liferay-portal — pull request #147 by zxdgoal (2014-12-09 02:14:02+00:00)
Title: LPS-52059 Inconsistent 404 error for invalid links.

Hey Dale

You are right. I fixed it in a wrong place.

We cannot catch RepositoryException from upper layer as in _checkFileEntry#WebServerServlet.java
```
try {
DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(
uuid, groupId);
}
catch (RepositoryException re) {
}
```

RepositoryException is keep silent. So we must throw a specific Exception rather than general RepositoryException in order to make _checkFileEntry returning FALSE.

The key thing here in DLAppLocalServiceImpl.java#getLocalRepository
```
protected LocalRepository getLocalRepository(long repositoryId)
throws PortalException, SystemException {

try {
return repositoryLocalService.getLocalRepositoryImpl(repositoryId);
}
catch (InvalidRepositoryIdException irie) {
StringBundler sb = new StringBundler(3);

sb.append("No Group exists with the key {repositoryId=");
sb.append(repositoryId);
sb.append("}");

throw new NoSuchGroupException(sb.toString(), irie);
}
}
```
We should not catch InvalidRepositoryIdException as it means we cannot get a RepositoryId, but here we want to get a repository with a known repositoryId. Please refer getFileEntryLocalRepository(long fileEntryId) and getFileVersionLocalRepository(long fileVersionId).

Actually, there is no InvalidRepositoryIdException thrown as we do not call
```
long repositoryId = getRepositoryId(
folderId, fileEntryId, fileVersionId);
```
in RepositoryLocalServiceImpl.java

So the Exception we want to catch here is RepositoryException because a general RepositoryException is thrown means we fail to get a repository with the given repositoryId.

In getFileEntryLocalRepository and getFileVersionLocalRepository, the repositoryId is retrieved from database, but in getLocalRepository, the parameter is passed from URL so it cannot be trusted and we need catch this RepositoryException from getLocalRepository(), but no need from getFileEntryLocalRepository and getFileVersionLocalRepository.

Thanks
John.