Skip to content

Commit

Permalink
propsReader & mountReader will return a zero length array on error
Browse files Browse the repository at this point in the history
fixed propsReader null pointer exception if no 'getprop' is available
  • Loading branch information
BIOCATCH\Leon.Karabchevsky committed Jun 7, 2017
1 parent 240491c commit 65c7647
Showing 1 changed file with 12 additions and 27 deletions.
39 changes: 12 additions & 27 deletions rootbeerlib/src/main/java/com/scottyab/rootbeer/RootBeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,42 +194,27 @@ public void setLogging(boolean logging) {
}

private String[] propsReader() {
InputStream inputstream = null;
String[] result = new String[0];
try {
inputstream = Runtime.getRuntime().exec("getprop").getInputStream();
} catch (IOException e) {
InputStream inputstream = Runtime.getRuntime().exec("getprop").getInputStream();
String propVal = new Scanner(inputstream).useDelimiter("\\A").next();
result = propVal.split("\n");
} catch (IOException | NoSuchElementException e) {
e.printStackTrace();
}
String propval = "";
try {
propval = new Scanner(inputstream).useDelimiter("\\A").next();

} catch (NoSuchElementException e) {
QLog.e("Error getprop, NoSuchElementException: " +e.getMessage(), e);
}

return propval.split("\n");
return result;
}

private String[] mountReader() {
InputStream inputstream = null;
try {
inputstream = Runtime.getRuntime().exec("mount").getInputStream();
} catch (IOException e) {
e.printStackTrace();
}

// If input steam is null, we can't read the file, so return null
if (inputstream == null) return null;

String propval = "";
String[] result = new String[0];
try {
propval = new Scanner(inputstream).useDelimiter("\\A").next();
} catch (NoSuchElementException e) {
InputStream inputstream = Runtime.getRuntime().exec("mount").getInputStream();
String propVal = new Scanner(inputstream).useDelimiter("\\A").next();
result = propVal.split("\n");
} catch (IOException | NoSuchElementException e) {
e.printStackTrace();
}

return propval.split("\n");
return result;
}

/**
Expand Down

0 comments on commit 65c7647

Please sign in to comment.