Page 1 of 1

Bug: RMIR/RMDU crashes on filename without directory

Posted: Sat Nov 23, 2024 5:13 am
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.

Posted: Sat Nov 23, 2024 5:41 am
by mathdon
Thanks for discovering this bug. Yes, please check it in.

Posted: Sat Nov 23, 2024 6:21 am
by Barf
Done. 8-)