Ensure no NullPointerException is thrown when reading ldd

This commit is contained in:
hedgecrw85 2019-02-11 09:53:10 -06:00
parent 62fc0f0184
commit 30a464cad7
1 changed files with 5 additions and 4 deletions

View File

@ -2,10 +2,10 @@
* SerialPort.java * SerialPort.java
* *
* Created on: Feb 25, 2012 * Created on: Feb 25, 2012
* Last Updated on: Oct 29, 2018 * Last Updated on: Feb 11, 2019
* Author: Will Hedgecock * Author: Will Hedgecock
* *
* Copyright (C) 2012-2018 Fazecast, Inc. * Copyright (C) 2012-2019 Fazecast, Inc.
* *
* This file is part of jSerialComm. * This file is part of jSerialComm.
* *
@ -169,11 +169,12 @@ public final class SerialPort
libraryPath += "-hf"; libraryPath += "-hf";
else else
{ {
String line;
ProcessBuilder pb = new ProcessBuilder("/bin/sh", "-c", "ls /lib/ld-linux*"); ProcessBuilder pb = new ProcessBuilder("/bin/sh", "-c", "ls /lib/ld-linux*");
Process p = pb.start(); Process p = pb.start();
p.waitFor(); p.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
if (br.readLine().contains("armhf")) if (((line = br.readLine()) != null) && line.contains("armhf"))
libraryPath += "-hf"; libraryPath += "-hf";
else else
{ {
@ -181,7 +182,7 @@ public final class SerialPort
p = pb.start(); p = pb.start();
p.waitFor(); p.waitFor();
br = new BufferedReader(new InputStreamReader(p.getInputStream())); br = new BufferedReader(new InputStreamReader(p.getInputStream()));
if (br.readLine().contains("armhf")) if (((line = br.readLine()) != null) && line.contains("armhf"))
libraryPath += "-hf"; libraryPath += "-hf";
} }
} }