Skip to content

Commit

Permalink
Merge pull request DSpace#8955 from amgciadev/fix-8954-b
Browse files Browse the repository at this point in the history
Prevent NPE during indexing if bitstream is null
  • Loading branch information
tdonohue authored Jul 28, 2023
2 parents de3daa1 + acf376d commit 7f9ec2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ private void buildFullTextList(Item parentItem) {
if (StringUtils.equals(FULLTEXT_BUNDLE, myBundle.getName())) {
// a-ha! grab the text out of the bitstreams
List<Bitstream> bitstreams = myBundle.getBitstreams();
log.debug("Processing full-text bitstreams. Item handle: " + sourceInfo);

for (Bitstream fulltextBitstream : emptyIfNull(bitstreams)) {
fullTextStreams.add(new FullTextBitstream(sourceInfo, fulltextBitstream));

log.debug("Added BitStream: "
+ fulltextBitstream.getStoreNumber() + " "
+ fulltextBitstream.getSequenceID() + " "
+ fulltextBitstream.getName());
if (fulltextBitstream != null) {
log.debug("Added BitStream: "
+ fulltextBitstream.getStoreNumber() + " "
+ fulltextBitstream.getSequenceID() + " "
+ fulltextBitstream.getName());
} else {
log.error("Found a NULL bitstream when processing full-text files: item handle:" + sourceInfo);
}
}
}
}
Expand Down Expand Up @@ -158,16 +163,16 @@ public FullTextBitstream(final String parentHandle, final Bitstream file) {
}

public String getContentType(final Context context) throws SQLException {
BitstreamFormat format = bitstream.getFormat(context);
BitstreamFormat format = bitstream != null ? bitstream.getFormat(context) : null;
return format == null ? null : StringUtils.trimToEmpty(format.getMIMEType());
}

public String getFileName() {
return StringUtils.trimToEmpty(bitstream.getName());
return bitstream != null ? StringUtils.trimToEmpty(bitstream.getName()) : null;
}

public long getSize() {
return bitstream.getSizeBytes();
return bitstream != null ? bitstream.getSizeBytes() : -1;
}

public InputStream getInputStream() throws SQLException, IOException, AuthorizeException {
Expand Down
5 changes: 5 additions & 0 deletions dspace-oai/src/main/java/org/dspace/xoai/util/ItemUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ private static Element createBundlesElement(Context context, Item item) throws S
bundle.getElement().add(bitstreams);
List<Bitstream> bits = b.getBitstreams();
for (Bitstream bit : bits) {
// Check if bitstream is null and log the error
if (bit == null) {
log.error("Null bitstream found, check item uuid: " + item.getID());
break;
}
Element bitstream = create("bitstream");
bitstreams.getElement().add(bitstream);
String url = "";
Expand Down

0 comments on commit 7f9ec2e

Please sign in to comment.