Skip to content

Commit 870fbbf

Browse files
committed
Ensure no crashes if user force deletes expected System properties in their app
1 parent 5cacd51 commit 870fbbf

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/main/java/com/fazecast/jSerialComm/SerialPort.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ public class SerialPort
114114
String[] architectures;
115115
String libraryPath, libraryFileName, extractedFileName;
116116
final String manualLibraryPath = System.getProperty("jSerialComm.library.path", "");
117-
final String OS = System.getProperty("os.name").toLowerCase();
118-
final String arch = System.getProperty("os.arch").toLowerCase();
119-
final File tempFileDirectory = new File(System.getProperty("java.io.tmpdir"), "jSerialComm" + File.separator + System.getProperty(tmpdirAppIdProperty, ".") + File.separator + versionString).getCanonicalFile();
120-
final File userHomeDirectory = new File(System.getProperty("user.home"), ".jSerialComm" + File.separator + System.getProperty(tmpdirAppIdProperty, ".") + File.separator + versionString).getCanonicalFile();
117+
final String OS = System.getProperty("os.name", "").toLowerCase();
118+
final String arch = System.getProperty("os.arch", "").toLowerCase();
119+
final File tempFileDirectory = new File(System.getProperty("java.io.tmpdir", OS.contains("win") ? "C:\\Temp" : "/tmp"), "jSerialComm" + File.separator + System.getProperty(tmpdirAppIdProperty, ".") + File.separator + versionString).getCanonicalFile();
120+
final File userHomeDirectory = new File(System.getProperty("user.home", OS.contains("win") ? "C:\\Temp" : "/tmp"), ".jSerialComm" + File.separator + System.getProperty(tmpdirAppIdProperty, ".") + File.separator + versionString).getCanonicalFile();
121121
final boolean randomizeNativeName = System.getProperty("jSerialComm.library.randomizeNativeName", "false").equalsIgnoreCase("true");
122122
cleanUpDirectory(new File(tempFileDirectory, ".."));
123123
cleanUpDirectory(new File(userHomeDirectory, ".."));
124124

125125
// Determine Operating System and architecture
126-
if (System.getProperty("java.vm.vendor").toLowerCase().contains("android"))
126+
if (System.getProperty("java.vm.vendor", "").toLowerCase().contains("android"))
127127
{
128128
isAndroidDelete = true;
129129
libraryPath = "Android";
@@ -516,7 +516,7 @@ static public SerialPort getCommPort(String portDescriptor) throws SerialPortInv
516516
{
517517
// Resolve home directory ~
518518
if (portDescriptor.startsWith("~" + File.separator))
519-
portDescriptor = System.getProperty("user.home") + portDescriptor.substring(1);
519+
portDescriptor = System.getProperty("user.home", "/tmp") + portDescriptor.substring(1);
520520

521521
// See what kind of descriptor was passed in
522522
if (isWindows)

0 commit comments

Comments
 (0)