Skip to content

Commit

Permalink
Prevent NPE when GC is calling finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Jan 31, 2018
1 parent da4a969 commit 729c28d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ protected void onCreate(Bundle savedInstanceState) {

// Run the shell command in the input box synchronously
sync_cmd.setOnClickListener(v -> {
Shell.Sync.su(consoleList, input.getText().toString());
Shell.Sync.sh(consoleList, input.getText().toString());
input.setText("");
});

// Run the shell command in the input box asynchronously.
// Also demonstrates that Async.Callback works
async_cmd.setOnClickListener(v -> {
Shell.Async.su(consoleList, consoleList,
Shell.Async.sh(consoleList, consoleList,
(out, err) -> Log.d(TAG, "in_async_callback"),
input.getText().toString());
input.setText("");
Expand Down
4 changes: 3 additions & 1 deletion superuser/src/main/java/com/topjohnwu/superuser/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public class Shell implements Closeable {
final InputStream STDERR;
final ReentrantLock lock;

private int status;
private int status = -2;
private CharSequence token;
private StreamGobbler outGobbler;
private StreamGobbler errGobbler;
Expand Down Expand Up @@ -581,6 +581,8 @@ public static void loadScript(List<String> output, List<String> error, Callback

@Override
public void close() throws IOException {
if (status < UNKNOWN)
return;
// Make sure no thread is currently using the shell before closing
lock.lock();
try {
Expand Down

0 comments on commit 729c28d

Please sign in to comment.