changeset 16:2bb46da74667

Detect unsupported file types on input.
author David Barts <n5jrn@me.com>
date Mon, 20 Jul 2020 12:56:07 -0700
parents fad32eda667f
children d71523cde521
files src/name/blackcap/imageprep/Misc.kt src/name/blackcap/imageprep/RotateDialog.kt
diffstat 2 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/name/blackcap/imageprep/Misc.kt	Sun Jul 19 13:49:23 2020 -0700
+++ b/src/name/blackcap/imageprep/Misc.kt	Mon Jul 20 12:56:07 2020 -0700
@@ -233,6 +233,14 @@
         border = BorderFactory.createCompoundBorder(b, border)
 }
 
+/**
+ * Display an error dialog pertaining to an IOException.
+ *
+ * @param parent Parent component for this dialog
+ * @param file java.io.File object associated with this error
+ * @param op Operation that failed (e.g. "read", "write", etc.)
+ * @param e An IOException
+ */
 fun ioExceptionDialog(parent: Component, file: File, op: String, e: IOException) {
     val msg = e.message
     val fileName = file.getName()
--- a/src/name/blackcap/imageprep/RotateDialog.kt	Sun Jul 19 13:49:23 2020 -0700
+++ b/src/name/blackcap/imageprep/RotateDialog.kt	Mon Jul 20 12:56:07 2020 -0700
@@ -146,6 +146,8 @@
                 inBackground {
                     try {
                         val imageIn = ImageIO.read(input) /* IOException */
+                        if (imageIn == null)
+                            throw IOException("Unsupported file type.")
                         val ratio = Settings.maxDimension.toDouble() / max(imageIn.width, imageIn.height).toDouble()
                         if (ratio >= 1.0) {
                             Pair(null, null)