Skip to content

Commit

Permalink
pcorlessGH-308 Checks for null embeddedFileStream
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Tâche committed Oct 9, 2023
1 parent 8287862 commit 1764194
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ public DictionaryEntries getEmbeddedFileDictionary() {
*/
public EmbeddedFileStream getEmbeddedFileStream(){
DictionaryEntries fileDictionary = getEmbeddedFileDictionary();
Reference fileRef = (Reference) fileDictionary.get(FileSpecification.F_KEY);
Reference fileRef = fileDictionary == null ? null : (Reference) fileDictionary.get(FileSpecification.F_KEY);
if (fileRef != null) {
Stream fileStream = (Stream) library.getObject(fileRef);
if (fileStream != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,12 @@ public void actionPerformed(ActionEvent e) {
if (value instanceof FileSpecification) {
FileSpecification fileSpecification = (FileSpecification) value;
final EmbeddedFileStream embeddedFileStream = fileSpecification.getEmbeddedFileStream();
final String fileName = (String) fileTableModel.getValueAt(selectedRow, NAME_COLUMN);
// already on awt thread but still nice to play by the rules.
Runnable doSwingWork = () -> saveFile(fileName, embeddedFileStream);
SwingUtilities.invokeLater(doSwingWork);
if (embeddedFileStream != null) {
final String fileName = (String) fileTableModel.getValueAt(selectedRow, NAME_COLUMN);
// already on awt thread but still nice to play by the rules.
Runnable doSwingWork = () -> saveFile(fileName, embeddedFileStream);
SwingUtilities.invokeLater(doSwingWork);
}
}
}
}
Expand All @@ -185,7 +187,7 @@ public void mouseClicked(MouseEvent mouseEvent) {
EmbeddedFileStream embeddedFileStream = fileSpecification.getEmbeddedFileStream();
String fileName = (String) fileTableModel.getValueAt(selectedRow, NAME_COLUMN);
// load the file stream if it's PDF.
if (fileName.toLowerCase().endsWith(PDF_EXTENSION)) {
if (embeddedFileStream != null && fileName.toLowerCase().endsWith(PDF_EXTENSION)) {
try {
InputStream fileInputStream = embeddedFileStream.getDecodedStreamData();
Document embeddedDocument = new Document();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public FileTableModel(ResourceBundle messageBundle, HashMap<String, FileSpecific
fileSpecification.getFileSpecification() : "";
data[i][DESCRIPTION_COLUMN] = fileSpecification.getDescription() != null ?
fileSpecification.getDescription() : "";
data[i][MODIFIED_COLUMN] = embeddedFileStream.getParamLastModifiedData() != null ?
data[i][MODIFIED_COLUMN] = embeddedFileStream != null && embeddedFileStream.getParamLastModifiedData() != null ?
embeddedFileStream.getParamLastModifiedData() : "";
data[i][SIZE_COLUMN] = Utils.byteFormatter(embeddedFileStream.getParamUncompressedSize(), true);
data[i][COMPRESSION_COLUMN] = Utils.byteFormatter(embeddedFileStream.getCompressedSize(), true);
data[i][SIZE_COLUMN] = embeddedFileStream == null ? "" : Utils.byteFormatter(embeddedFileStream.getParamUncompressedSize(), true);
data[i][COMPRESSION_COLUMN] = embeddedFileStream == null ? "" : Utils.byteFormatter(embeddedFileStream.getCompressedSize(), true);
data[i][DATA_COLUMN] = fileSpecification;
i++;
}
Expand Down

0 comments on commit 1764194

Please sign in to comment.