Bug: RMIR/RMDU crashes on filename without directory

Discussion forum for JP1 software tools currently in use, or being developed, such as IR, KM, RemoteMaster, and other misc apps/tools.

Moderator: Moderators

Post Reply
Barf
Expert
Posts: 1522
Joined: Fri Oct 24, 2008 1:54 pm
Location: Munich, Germany
Contact:

Bug: RMIR/RMDU crashes on filename without directory

Post by Barf »

To reproduce: start rmir or rmdu from the command line with a file name without directory, like

Code: Select all

java -jar ***.jar Aiwa-CX.rmdu
The program crashed. rmaster,err says:

Code: Select all

...
java.lang.NullPointerException: Cannot invoke "java.io.File.getAbsolutePath()" because "file" is null
        at com.hifiremote.jp1.PropertyFile.setProperty(PropertyFile.java:112)
        at com.hifiremote.jp1.Preferences.setUpgradePath(Preferences.java:245)
        at com.hifiremote.jp1.KeyMapMaster.loadUpgrade(KeyMapMaster.java:1479)
        at com.hifiremote.jp1.RemoteMaster$1.run(RemoteMaster.java:506)
...
This is while on the user supplied file name (fileToOpen) first File.parentFile() is preformed (returns null), then on the result File.getParentFile() is done, which of course bombs.

One possible fix would be to replace all getParentFile() by getCanonicFile.getParent(), but there are several of those. A more elegant fix appears to be to canonicalize the file name just when read, i.e.,

Code: Select all

Index: src/main/java/com/hifiremote/jp1/RemoteMaster.java
===================================================================
--- src/main/java/com/hifiremote/jp1/RemoteMaster.java  (revision 2082)
+++ src/main/java/com/hifiremote/jp1/RemoteMaster.java  (working copy)
@@ -358,7 +358,7 @@
       File fileToOpen = null;
       if ( commandLineArgs.fileName != null ) 
       {
-        fileToOpen = new File( commandLineArgs.fileName );
+        fileToOpen = new File( commandLineArgs.fileName ).getCanonicalFile();
         if ( hasEnding( commandLineArgs.fileName, upgradeEndings, upgradeImportEndings ) ) 
         {
           if ( commandLineArgs.launchRMIR || commandLineArgs.launchRMPB ) 
Will check in on request.
mathdon
Expert
Posts: 4725
Joined: Tue Jul 22, 2008 8:53 am
Location: Cambridge, UK

Post by mathdon »

Thanks for discovering this bug. Yes, please check it in.
Graham
Barf
Expert
Posts: 1522
Joined: Fri Oct 24, 2008 1:54 pm
Location: Munich, Germany
Contact:

Post by Barf »

Done. 8-)
Post Reply