Skip to content

Instantly share code, notes, and snippets.

@bastoche
Last active December 20, 2015 12:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastoche/6133227 to your computer and use it in GitHub Desktop.
Save bastoche/6133227 to your computer and use it in GitHub Desktop.
Test case reproducing a crash on a few Android devices
package com.example;
import junit.framework.TestCase;
import org.apache.http.impl.client.DefaultHttpClient;
public final class HttpClientTest extends TestCase {
// won't pass on T-Mobile MyTouch Q
public void testInstanciateAsynchronously() {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
new DefaultHttpClient();
}
});
thread.start();
boolean result = false;
try {
thread.join();
result = true;
} catch (InterruptedException e) {
e.printStackTrace();
}
assertTrue(result);
}
// will always pass
public void testInstanciateSynchronouslyThenAsynchronously() {
new DefaultHttpClient();
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
new DefaultHttpClient();
}
});
thread.start();
boolean result = false;
try {
thread.join();
result = true;
} catch (InterruptedException e) {
e.printStackTrace();
}
assertTrue(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment