mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 05:23:14 +00:00
[DS-2903] Fix potential Nullpointer exceptions indicated by FindBugs
This commit is contained in:
@@ -1840,6 +1840,7 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
|||||||
|
|
||||||
List<Collection> finalCollections = null;
|
List<Collection> finalCollections = null;
|
||||||
if (theOwningCollection != null){
|
if (theOwningCollection != null){
|
||||||
|
finalCollections = new ArrayList<>();
|
||||||
finalCollections.add(theOwningCollection);
|
finalCollections.add(theOwningCollection);
|
||||||
finalCollections.addAll(collectionList);
|
finalCollections.addAll(collectionList);
|
||||||
}
|
}
|
||||||
|
@@ -99,7 +99,11 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EPerson> search(Context context, String query) throws SQLException {
|
public List<EPerson> search(Context context, String query) throws SQLException {
|
||||||
if(StringUtils.isBlank(query)) query = null;
|
if(StringUtils.isBlank(query))
|
||||||
|
{
|
||||||
|
//If we don't have a query, just return everything.
|
||||||
|
return findAll(context, EPerson.EMAIL);
|
||||||
|
}
|
||||||
return search(context, query, -1, -1);
|
return search(context, query, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +120,10 @@ public class EPersonServiceImpl extends DSpaceObjectServiceImpl<EPerson> impleme
|
|||||||
} catch(IllegalArgumentException e) {
|
} catch(IllegalArgumentException e) {
|
||||||
MetadataField firstNameField = metadataFieldService.findByElement(context, "eperson", "firstname", null);
|
MetadataField firstNameField = metadataFieldService.findByElement(context, "eperson", "firstname", null);
|
||||||
MetadataField lastNameField = metadataFieldService.findByElement(context, "eperson", "lastname", null);
|
MetadataField lastNameField = metadataFieldService.findByElement(context, "eperson", "lastname", null);
|
||||||
if (StringUtils.isBlank(query)) query = null;
|
if (StringUtils.isBlank(query))
|
||||||
|
{
|
||||||
|
query = null;
|
||||||
|
}
|
||||||
return ePersonDAO.search(context, query, Arrays.asList(firstNameField, lastNameField), Arrays.asList(firstNameField, lastNameField), offset, limit);
|
return ePersonDAO.search(context, query, Arrays.asList(firstNameField, lastNameField), Arrays.asList(firstNameField, lastNameField), offset, limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -227,7 +227,11 @@ public class MetadataConverterPlugin implements ConverterPlugin
|
|||||||
}
|
}
|
||||||
config.read(is, "file://" + mappingPath, FileUtils.guessLang(mappingPath));
|
config.read(is, "file://" + mappingPath, FileUtils.guessLang(mappingPath));
|
||||||
try {
|
try {
|
||||||
is.close();
|
// Make sure that we have an input stream to avoid NullPointer
|
||||||
|
if(is != null)
|
||||||
|
{
|
||||||
|
is.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (IOException ex)
|
catch (IOException ex)
|
||||||
{
|
{
|
||||||
|
@@ -14,10 +14,7 @@ import gr.ekt.bte.core.Value;
|
|||||||
import gr.ekt.bte.exceptions.MalformedSourceException;
|
import gr.ekt.bte.exceptions.MalformedSourceException;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.http.HttpException;
|
import org.apache.http.HttpException;
|
||||||
@@ -78,7 +75,7 @@ public abstract class NetworkSubmissionLookupDataLoader implements
|
|||||||
: null;
|
: null;
|
||||||
String year = getSearchTerms().get("year") != null ? getSearchTerms()
|
String year = getSearchTerms().get("year") != null ? getSearchTerms()
|
||||||
.get("year").iterator().next()
|
.get("year").iterator().next()
|
||||||
: null;
|
: String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
|
||||||
int yearInt = Integer.parseInt(year);
|
int yearInt = Integer.parseInt(year);
|
||||||
results = search(null, title, authors, yearInt);
|
results = search(null, title, authors, yearInt);
|
||||||
}
|
}
|
||||||
|
@@ -361,7 +361,7 @@ public class XmlWorkflowServiceImpl implements XmlWorkflowService {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
if((nextStep != null && nextActionConfig != null) || wfi.getItem().isArchived()){
|
if((nextStep != null && currentStep != null && nextActionConfig != null) || (wfi.getItem().isArchived() && currentStep != null)){
|
||||||
logWorkflowEvent(c, currentStep.getWorkflow().getID(), currentStep.getId(), currentActionConfig.getId(), wfi, user, nextStep, nextActionConfig);
|
logWorkflowEvent(c, currentStep.getWorkflow().getID(), currentStep.getId(), currentActionConfig.getId(), wfi, user, nextStep, nextActionConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -95,6 +95,12 @@ public class AssignOriginalSubmitterAction extends UserSelectionAction{
|
|||||||
while(nextAction != null && !nextAction.requiresUI()){
|
while(nextAction != null && !nextAction.requiresUI()){
|
||||||
nextAction = nextAction.getStep().getNextAction(nextAction);
|
nextAction = nextAction.getStep().getNextAction(nextAction);
|
||||||
}
|
}
|
||||||
|
if(nextAction == null)
|
||||||
|
{
|
||||||
|
//Should never occur, but just in case
|
||||||
|
log.error("Could not find next action for step with id: " + step.getId() + " to assign a submitter to. Aborting the action.");
|
||||||
|
throw new IllegalStateException();
|
||||||
|
}
|
||||||
|
|
||||||
createTaskForEPerson(c, wfi, step, nextAction, submitter);
|
createTaskForEPerson(c, wfi, step, nextAction, submitter);
|
||||||
|
|
||||||
|
@@ -311,14 +311,16 @@ public class RequestItemServlet extends DSpaceServlet
|
|||||||
{
|
{
|
||||||
Item item = requestItem.getItem();
|
Item item = requestItem.getItem();
|
||||||
String title = "";
|
String title = "";
|
||||||
|
String handle = "";
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
title = itemService.getMetadataFirstValue(item, "dc", "title", null, Item.ANY);
|
title = itemService.getMetadataFirstValue(item, "dc", "title", null, Item.ANY);
|
||||||
if (title == null) {
|
if (title == null) {
|
||||||
title = "";
|
title = "";
|
||||||
}
|
}
|
||||||
|
handle = item.getHandle();
|
||||||
}
|
}
|
||||||
request.setAttribute("request-name", requestItem.getReqName());
|
request.setAttribute("request-name", requestItem.getReqName());
|
||||||
request.setAttribute("handle", item.getHandle());
|
request.setAttribute("handle", handle);
|
||||||
request.setAttribute("title", title);
|
request.setAttribute("title", title);
|
||||||
|
|
||||||
JSPManager.showJSP(request, response,
|
JSPManager.showJSP(request, response,
|
||||||
|
@@ -217,11 +217,11 @@ public class JSPUploadStep extends JSPStep
|
|||||||
size = bitstream.getSize();
|
size = bitstream.getSize();
|
||||||
url = request.getContextPath() + "/retrieve/" + bitstreamID
|
url = request.getContextPath() + "/retrieve/" + bitstreamID
|
||||||
+ "/" + UIUtil.encodeBitstreamName(bitstreamName);
|
+ "/" + UIUtil.encodeBitstreamName(bitstreamName);
|
||||||
|
jsonResponse.addUploadFileStatus(bitstreamName, bitstreamID, size,
|
||||||
|
url, status);
|
||||||
|
response.getWriter().print(gson.toJson(jsonResponse));
|
||||||
|
response.flushBuffer();
|
||||||
}
|
}
|
||||||
jsonResponse.addUploadFileStatus(bitstreamName, bitstreamID, size,
|
|
||||||
url, status);
|
|
||||||
response.getWriter().print(gson.toJson(jsonResponse));
|
|
||||||
response.flushBuffer();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -143,11 +143,11 @@ public class JSPUploadWithEmbargoStep extends JSPUploadStep
|
|||||||
size = bitstream.getSize();
|
size = bitstream.getSize();
|
||||||
url = request.getContextPath() + "/retrieve/" + bitstreamID
|
url = request.getContextPath() + "/retrieve/" + bitstreamID
|
||||||
+ "/" + UIUtil.encodeBitstreamName(bitstreamName);
|
+ "/" + UIUtil.encodeBitstreamName(bitstreamName);
|
||||||
|
jsonResponse.addUploadFileStatus(bitstreamName, bitstreamID, size,
|
||||||
|
url, status);
|
||||||
|
response.getWriter().print(gson.toJson(jsonResponse));
|
||||||
|
response.flushBuffer();
|
||||||
}
|
}
|
||||||
jsonResponse.addUploadFileStatus(bitstreamName, bitstreamID, size,
|
|
||||||
url, status);
|
|
||||||
response.getWriter().print(gson.toJson(jsonResponse));
|
|
||||||
response.flushBuffer();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,13 +10,14 @@ package org.dspace.xoai.services.api;
|
|||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
import org.dspace.content.Item;
|
import org.dspace.content.Item;
|
||||||
|
import org.dspace.xoai.services.api.context.ContextService;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public interface CollectionsService {
|
public interface CollectionsService {
|
||||||
List<UUID> getAllSubCollections(UUID communityId) throws SQLException;
|
List<UUID> getAllSubCollections(ContextService contextService, UUID communityId) throws SQLException;
|
||||||
List<Community> flatParentCommunities(Collection collection) throws SQLException;
|
List<Community> flatParentCommunities(Collection collection) throws SQLException;
|
||||||
List<Community> flatParentCommunities(Community community) throws SQLException;
|
List<Community> flatParentCommunities(Community community) throws SQLException;
|
||||||
List<Community> flatParentCommunities(Item item) throws SQLException;
|
List<Community> flatParentCommunities(Item item) throws SQLException;
|
||||||
|
@@ -25,12 +25,11 @@ import org.dspace.content.service.CommunityService;
|
|||||||
|
|
||||||
public class DSpaceCollectionsService implements CollectionsService {
|
public class DSpaceCollectionsService implements CollectionsService {
|
||||||
|
|
||||||
private ContextService contextService;
|
|
||||||
private static final CommunityService communityService
|
private static final CommunityService communityService
|
||||||
= ContentServiceFactory.getInstance().getCommunityService();
|
= ContentServiceFactory.getInstance().getCommunityService();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<UUID> getAllSubCollections(UUID communityId)
|
public List<UUID> getAllSubCollections(ContextService contextService, UUID communityId)
|
||||||
throws SQLException
|
throws SQLException
|
||||||
{
|
{
|
||||||
Queue<Community> comqueue = new LinkedList<>();
|
Queue<Community> comqueue = new LinkedList<>();
|
||||||
|
@@ -919,7 +919,6 @@ public class ItemsResource extends Resource
|
|||||||
// Must used own style.
|
// Must used own style.
|
||||||
if ((metadata.length < 2) || (metadata.length > 3))
|
if ((metadata.length < 2) || (metadata.length > 3))
|
||||||
{
|
{
|
||||||
context.abort();
|
|
||||||
log.error("Finding failed, bad metadata key.");
|
log.error("Finding failed, bad metadata key.");
|
||||||
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
throw new WebApplicationException(Response.Status.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
@@ -258,6 +258,9 @@ public class FlowAuthorizationUtils {
|
|||||||
.authorizeManageItemPolicy(context, (Item) (bitstreamService.getParentObject(context, (Bitstream) policyParent)));
|
.authorizeManageItemPolicy(context, (Item) (bitstreamService.getParentObject(context, (Bitstream) policyParent)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
//If we can't find a parent the policy will receive a NULL dspace object, this is not something we want.
|
||||||
|
throw new IllegalArgumentException("Invalid DSpaceObject type provided");
|
||||||
}
|
}
|
||||||
policy = resourcePolicyService.create(context);
|
policy = resourcePolicyService.create(context);
|
||||||
policy.setdSpaceObject(policyParent);
|
policy.setdSpaceObject(policyParent);
|
||||||
|
@@ -132,7 +132,7 @@ public class EditItemMetadataForm extends AbstractDSpaceTransformer {
|
|||||||
// Metadata editing is the only type of editing available for a template item.
|
// Metadata editing is the only type of editing available for a template item.
|
||||||
boolean editingTemplateItem = false;
|
boolean editingTemplateItem = false;
|
||||||
String templateCollectionID = parameters.getParameter("templateCollectionID", null);
|
String templateCollectionID = parameters.getParameter("templateCollectionID", null);
|
||||||
Collection templateCollection = templateCollectionID != null ? null : collectionService.find(context, UUID.fromString(templateCollectionID));
|
Collection templateCollection = templateCollectionID == null ? null : collectionService.find(context, UUID.fromString(templateCollectionID));
|
||||||
if (templateCollection != null)
|
if (templateCollection != null)
|
||||||
{
|
{
|
||||||
Item templateItem = templateCollection.getTemplateItem();
|
Item templateItem = templateCollection.getTemplateItem();
|
||||||
@@ -144,7 +144,7 @@ public class EditItemMetadataForm extends AbstractDSpaceTransformer {
|
|||||||
|
|
||||||
// DIVISION: main
|
// DIVISION: main
|
||||||
Division main = body.addInteractiveDivision("edit-item-status", contextPath+"/admin/item", Division.METHOD_POST,"primary administrative item");
|
Division main = body.addInteractiveDivision("edit-item-status", contextPath+"/admin/item", Division.METHOD_POST,"primary administrative item");
|
||||||
if (editingTemplateItem)
|
if (templateCollection != null && editingTemplateItem)
|
||||||
{
|
{
|
||||||
main.setHead(T_template_head.parameterize(templateCollection.getName()));
|
main.setHead(T_template_head.parameterize(templateCollection.getName()));
|
||||||
}
|
}
|
||||||
|
@@ -273,9 +273,16 @@ public class ConfigurableBrowse extends AbstractDSpaceTransformer implements
|
|||||||
HttpServletResponse response = (HttpServletResponse)objectModel
|
HttpServletResponse response = (HttpServletResponse)objectModel
|
||||||
.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
|
.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
|
||||||
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BrowseInfo info = getBrowseInfo();
|
BrowseInfo info = getBrowseInfo();
|
||||||
|
if(info == null)
|
||||||
|
{
|
||||||
|
HttpServletResponse response = (HttpServletResponse)objectModel.get(HttpEnvironment.HTTP_RESPONSE_OBJECT);
|
||||||
|
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String type = info.getBrowseIndex().getName();
|
String type = info.getBrowseIndex().getName();
|
||||||
|
|
||||||
|
@@ -81,7 +81,7 @@ public class ItemRequestResponseAction extends AbstractAction
|
|||||||
String title;
|
String title;
|
||||||
Item item = requestItem.getItem();
|
Item item = requestItem.getItem();
|
||||||
String titleDC = item.getName();
|
String titleDC = item.getName();
|
||||||
if (titleDC != null || titleDC.length() > 0)
|
if (titleDC != null && titleDC.length() > 0)
|
||||||
title=titleDC;
|
title=titleDC;
|
||||||
else
|
else
|
||||||
title="untitled";
|
title="untitled";
|
||||||
|
@@ -124,7 +124,7 @@ public class ItemRequestResponseTrueForm extends AbstractDSpaceTransformer imple
|
|||||||
String title;
|
String title;
|
||||||
Item item = requestItem.getItem();
|
Item item = requestItem.getItem();
|
||||||
String titleDC = item.getName();
|
String titleDC = item.getName();
|
||||||
if (titleDC != null || titleDC.length() > 0)
|
if (titleDC != null && titleDC.length() > 0)
|
||||||
title = titleDC;
|
title = titleDC;
|
||||||
else
|
else
|
||||||
title = "untitled";
|
title = "untitled";
|
||||||
|
@@ -142,6 +142,12 @@ public class HandleResolverReader extends AbstractReader implements Recyclable {
|
|||||||
log.error("SQLException: ", e);
|
log.error("SQLException: ", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if(jsonString == null)
|
||||||
|
{
|
||||||
|
//No handle found bad request
|
||||||
|
resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ObjectModelHelper.getResponse(objectModel).setHeader("Content-Type", CONTENTTYPE);
|
ObjectModelHelper.getResponse(objectModel).setHeader("Content-Type", CONTENTTYPE);
|
||||||
|
Reference in New Issue
Block a user