From 423b2917d9895c84dae60489cf73759cd7c4187a Mon Sep 17 00:00:00 2001 From: Jakob Heher Date: Wed, 15 Jun 2022 13:58:33 +0200 Subject: proper null checking for EXIF metadata, cf. #25 --- .../main/java/at/asit/pdfover/gui/composites/OutputComposite.java | 4 ++-- .../main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java index 69bf66aa..84ef58d3 100644 --- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java +++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/composites/OutputComposite.java @@ -313,7 +313,7 @@ public class OutputComposite extends StateComposite { source.getByteArray().length); outstream.close(); } catch (FileNotFoundException e) { - log.error("File not found", e); //$NON-NLS-1$ + log.warn("Failed to open output file", e); //$NON-NLS-1$ ErrorDialog dialog = new ErrorDialog(getShell(), String.format(Messages.getString("output.save_failed"), //$NON-NLS-1$ targetFile.getName(), e.getLocalizedMessage()), @@ -322,7 +322,7 @@ public class OutputComposite extends StateComposite { return null; retry = true; } catch (IOException e) { - log.error("IO Error", e); //$NON-NLS-1$ + log.error("I/O Error", e); //$NON-NLS-1$ ErrorDialog dialog = new ErrorDialog(getShell(), String.format(Messages.getString("output.save_failed"), //$NON-NLS-1$ targetFile.getName(), e.getLocalizedMessage()), diff --git a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java index 2b70afa3..51d094eb 100644 --- a/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java +++ b/pdf-over-signator/src/main/java/at/asit/pdfover/signator/CachedFileNameEmblem.java @@ -101,10 +101,9 @@ public class CachedFileNameEmblem implements Emblem { if (reader.getFormatName().equals("JPEG")) { try { Metadata metadata = ImageMetadataReader.readMetadata(imgFile); - - if(metadata != null) { - int orientation = metadata.getFirstDirectoryOfType( - ExifIFD0Directory.class).getInt( + ExifIFD0Directory metaDirectory = (metadata != null) ? metadata.getFirstDirectoryOfType(ExifIFD0Directory.class) : null; + if (metaDirectory != null) { + int orientation = metaDirectory.getInt( ExifDirectoryBase.TAG_ORIENTATION); if (orientation > 2) { // rotate -- cgit v1.2.3