I am getting sometimes problems with creating a list of names of the attached files in a NotesDocument. The custom message looks as followed:
AttachmentDominoDAO - General problem during reading attachment from entry 39E411CEC4AD22F3C1258821003399EF in database mail.nsf. fileObject.getName() returns null. Files found in document [contract.pdf]
Here is the method that I am calling:
private Attachment loadFromEntry(ViewEntry entry) {
utils.printToConsole(this.getClass().getSimpleName().toString() + " - loadFromEntry(...) unid=" + entry.getUniversalID());
Attachment attachment = new Attachment();
try{
attachment.setUnid(entry.getUniversalID());
Document doc = entry.getDocument();
if (null != doc){
attachment.setCreated(doc.getCreated().toJavaDate());
if(doc.hasItem("$FILE")){
List<String> files = doc.getAttachmentNames();
for (int j = 0; j < files.size(); ++j) {
EmbeddedObject fileObject = doc.getAttachment(files.get(j));
if(null != fileObject.getName()) {
if(null != fileObject.getName()) {
attachment.setFile(fileObject.getName());
} else {
XspOpenLogUtil.logEvent(null, "Problem with reading attachment from entry " + entry.getUniversalID() + ", fileName.getName() returns " + fileObject.getName(), Level.SEVERE, null);
}
if(null != fileObject.getName() && !utils.Right(fileObject.getName(),".").isEmpty()) {
attachment.setExtension(utils.Right(fileObject.getName(),"."));
} else {
XspOpenLogUtil.logEvent(null, "Problem with reading attachment from entry " + entry.getUniversalID() + ", extension is empty for file " + fileObject.getName(), Level.SEVERE, null);
}
attachment.setSizeHuman(FileUtils.byteCountToDisplaySize(fileObject.getFileSize()));
if(fileObject.getFileSize() > 0) {
attachment.setSize(fileObject.getFileSize());
} else {
XspOpenLogUtil.logEvent(null, "Problem with reading attachment from entry " + entry.getUniversalID() + ", fileName.size() returns " + fileObject.getFileSize(), Level.SEVERE, null);
}
if(null != doc.getAuthors() && null != doc.getAuthors().firstElement()) {
attachment.setCreator(doc.getAuthors().firstElement());
} else {
XspOpenLogUtil.logEvent(null, "Problem with reading attachment from entry " + entry.getUniversalID() + ", doc.getAuthors().firstElement() returns " + doc.getAuthors().firstElement(), Level.SEVERE, null);
}
String fieldName = "type";
if (doc.hasItem(fieldName)) {
attachment.setType(fieldName);
}
}else {
XspOpenLogUtil.logEvent(null, "AttachmentDominoDAO - General problem during reading attachment from entry " + entry.getUniversalID() + " in database " + entry.getDocument().getParentDatabase().getFileName() + ". fileObject.getName() returns null. Files found in document " + doc.getAttachmentNames().toString(), Level.SEVERE, null);
}
}
}
}
}catch (Exception e) {
XspOpenLogUtil.logEvent(e, "General problem with reading attachment from entry " + entry.getUniversalID() + " in database " + entry.getDocument().getParentDatabase().getFileName(), Level.SEVERE, null);
}
return attachment;
}
One document can only contain one file. When I check the document there is only one attachment and the attachment mentioned in the error message.
Anyone has a suggestion how to fix this issue?
Note: in 99% of the cases the error does not occur.