Restore interrupt status before throwing exception
authorgumartinm <gustavo@gumartinm.name>
Fri, 7 Dec 2012 18:40:20 +0000 (19:40 +0100)
committergumartinm <gustavo@gumartinm.name>
Fri, 7 Dec 2012 18:40:20 +0000 (19:40 +0100)
Always write the restore interrupt status just after catching th Interrupted exception.
In this way you make sure the interrupt status is not lost because something in your code
throws an exception before the line where you actually restore the interrupt status.

JavaPOS/KeyBoardDriver/src/main/java/de/javapos/example/hardware/KeyBoardDeviceLinux.java

index 2c7edd8..2c26547 100644 (file)
@@ -116,9 +116,9 @@ public class KeyBoardDeviceLinux implements BaseKeyBoardDriver {
                     throw new JposException(JposConst.JPOS_E_CLAIMED,
                             "Error while trying to claim device.", e);
                 } catch (InterruptedException e) {
-                    closeFileLock(fileChannelLock);
                     // restore interrupt status.
                     Thread.currentThread().interrupt();
+                    closeFileLock(fileChannelLock);
                     throw new JposException(JposConst.JPOSERR,
                             "Interrupt exception detected.", e);
                 }
@@ -152,9 +152,9 @@ public class KeyBoardDeviceLinux implements BaseKeyBoardDriver {
                     throw new JposException(JposConst.JPOS_E_CLAIMED,
                             "Error while trying to claim device.", e);
                 } catch (InterruptedException e) {
-                    closeFileLock(fileChannelLock);
                     // restore interrupt status.
                     Thread.currentThread().interrupt();
+                    closeFileLock(fileChannelLock);
                     throw new JposException(JposConst.JPOSERR,
                             "Interrupt exception detected.", e);
                 }
@@ -179,7 +179,7 @@ public class KeyBoardDeviceLinux implements BaseKeyBoardDriver {
             fileChannelLock.close();
         } catch (IOException e) {
             throw new JposException(JposConst.JPOSERR,
-                    "Error while closing the file lock", e);
+                    "Error while closing the lock file", e);
         }
     }