Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: fail build on compiler warnings #348

Merged
merged 2 commits into from
Jul 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ android {
}
}

gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:all" << "-Werror"
}
}

coveralls {
jacocoReportPath = "$buildDir/reports/coverage/debug/report.xml"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ static SessionStore generateSessionStore() {
return new SessionStore(generateConfiguration(), InstrumentationRegistry.getContext());
}

@SuppressWarnings("deprecation")
@NonNull
static SessionTrackingApiClient generateSessionTrackingApiClient() {
return new SessionTrackingApiClient() {
Expand All @@ -83,6 +84,7 @@ public void postSessionTrackingPayload(String urlString,
};
}

@SuppressWarnings("deprecation")
static ErrorReportApiClient generateErrorReportApiClient() { // no-op
return new ErrorReportApiClient() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void testSetContext() throws Exception {
assertEquals("JunitTest", config.getContext());
}

@SuppressWarnings("deprecation")
@Test
public void testSetEndpoint() throws Exception {
client.setEndpoint("http://example.com/bugsnag");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ClientNotifyTest {
*
* @throws Exception if initialisation failed
*/
@SuppressWarnings("deprecation")
@Before
public void setUp() throws Exception {
client = BugsnagTestUtils.generateClient();
Expand Down Expand Up @@ -81,6 +82,7 @@ public void beforeNotify(Report report) {
assertEquals("Message", error.getExceptionMessage());
}

@SuppressWarnings("deprecation")
static class FakeClient implements ErrorReportApiClient {

CountDownLatch latch = new CountDownLatch(1);
Expand Down
5 changes: 3 additions & 2 deletions sdk/src/androidTest/java/com/bugsnag/android/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void testNotify() {
client.notify(new RuntimeException("Testing"));
}

@SuppressWarnings("deprecation")
@Test
public void testConfig() {
config.setEndpoint("new-endpoint");
Expand All @@ -107,9 +108,8 @@ public void testRestoreUserFromPrefs() {
setUserPrefs();

config.setPersistUserBetweenSessions(true);
config.setDelivery(BugsnagTestUtils.generateDelivery());
Client client = new Client(context, config);
client.setErrorReportApiClient(BugsnagTestUtils.generateErrorReportApiClient());
client.setSessionTrackingApiClient(BugsnagTestUtils.generateSessionTrackingApiClient());

final User user = new User();

Expand Down Expand Up @@ -269,6 +269,7 @@ public void testClientClearTab() {
assertTrue(client.getMetaData().getTab("drink").isEmpty());
}

@SuppressWarnings("deprecation")
@Test(expected = IllegalArgumentException.class)
public void testApiClientNullValidation() {
generateClient().setSessionTrackingApiClient(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void testAutoCaptureOverride() {
assertFalse(config.shouldAutoCaptureSessions());
}

@SuppressWarnings("deprecation")
@Test
public void testEndpoint() {
// Default endpoints
Expand All @@ -82,6 +83,7 @@ public void testEndpoint() {
assertEquals(endpoint, config.getEndpoint());
}

@SuppressWarnings("deprecation")
@Test
public void testSessionEndpoint() {
// Default endpoints
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

class CustomException extends Exception implements JsonStream.Streamable {

private static final long serialVersionUID = 1962801050513549513L;

CustomException(String message) {
super(message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void tearDown() throws Exception {
Async.cancelTasks();
}

@SuppressWarnings("deprecation")
@Test
public void deliverReport() throws Exception {
Report report = null;
Expand All @@ -54,6 +55,7 @@ public void postReport(String urlString,
assertEquals(1, customCount.get());
}

@SuppressWarnings("deprecation")
@Test
public void deliverSession() throws Exception {
SessionTrackingPayload payload = null;
Expand All @@ -73,6 +75,7 @@ public void postSessionTrackingPayload(String urlString,
assertEquals(1, customCount.get());
}

@SuppressWarnings("deprecation")
@Test
public void testClientCompat() {
Client client = BugsnagTestUtils.generateClient();
Expand All @@ -96,11 +99,13 @@ public void testClientCompat() {
assertEquals(sessionClient, compat.sessionTrackingApiClient);
}

@SuppressWarnings("deprecation")
@Test(expected = DeliveryFailureException.class)
public void testExceptionConversion() throws Exception {
deliveryCompat.handleException(new NetworkException("", null));
}

@SuppressWarnings("deprecation")
@Test
public void testSwallowExceptionConversion() throws Exception { // no exception thrown
deliveryCompat.handleException(new BadResponseException("", 0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ public void tearDown() throws Exception {
Async.cancelTasks();
}

@SuppressWarnings("deprecation")
@Test(expected = IllegalArgumentException.class)
public void testApiClientNullValidation() {
Bugsnag.setErrorReportApiClient(null);
}

@SuppressWarnings("deprecation")
@Test
public void testPostReportCalled() {
Bugsnag.setErrorReportApiClient(apiClient);
Expand All @@ -46,6 +48,7 @@ public void testPostReportCalled() {
assertNotNull(apiClient.report);
}

@SuppressWarnings("deprecation")
private static class FakeApiClient implements ErrorReportApiClient {
private Report report;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ public void testDeepMerge() {

MetaData merged = MetaData.merge(base, overrides);
Map<String, Object> tab = merged.getTab("example");

@SuppressWarnings("unchecked")
Map<String, String> mergedMap = (Map<String, String>) tab.get("map");
assertEquals("fromOverrides", mergedMap.get("key"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,7 @@ public class NullMetadataTest {
@Before
public void setUp() throws Exception {
config = new Configuration("api-key");
Bugsnag.init(InstrumentationRegistry.getContext(), config);
Bugsnag.setErrorReportApiClient(new ErrorReportApiClient() {
@Override
public void postReport(String urlString,
Report report,
Map<String, String> headers)
throws NetworkException, BadResponseException {

}
});

BugsnagTestUtils.generateClient();
throwable = new RuntimeException("Test");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void testModifyingGroupingHash() throws JSONException, IOException {
assertEquals(groupingHash, event.getString("groupingHash"));
}

@SuppressWarnings("deprecation")
@Test
public void testModifyReportDetails() throws Exception {
String apiKey = "custom-api-key";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
@Deprecated
public class BadResponseException extends Exception {
private static final long serialVersionUID = -870190454845379171L;

public BadResponseException(String msg, int responseCode) {
super(String.format(Locale.US, "%s (%d)", msg, responseCode));
}
Expand Down
1 change: 1 addition & 0 deletions sdk/src/main/java/com/bugsnag/android/Bugsnag.java
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ public static void notify(@NonNull final Throwable exception, final Severity sev
* @param metaData additional information to send with the exception
* @deprecated Use {@link #notify(Throwable, Callback)} to send and modify error reports
*/
@Deprecated
public static void notify(@NonNull final Throwable exception,
@NonNull final MetaData metaData) {
getClient().notify(exception, new Callback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
public class BugsnagException extends Throwable {

private static final long serialVersionUID = 5068182621179433346L;
/**
* The name of the exception (used instead of the exception class)
*/
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/java/com/bugsnag/android/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ public void notify(@NonNull Throwable exception, Severity severity) {
* @param metaData additional information to send with the exception
* @deprecated Use {@link #notify(Throwable, Callback)} to send and modify error reports
*/
@Deprecated
public void notify(@NonNull Throwable exception,
@NonNull MetaData metaData) {
Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession())
Expand Down Expand Up @@ -1051,6 +1052,7 @@ public void notifyBlocking(@NonNull String name,
* @param metaData additional information to send with the exception
* @deprecated Use {@link #notify(Throwable, Callback)} to send and modify error reports
*/
@Deprecated
public void notifyBlocking(@NonNull Throwable exception,
@NonNull MetaData metaData) {
Error error = new Error.Builder(config, exception, sessionTracker.getCurrentSession())
Expand Down
4 changes: 4 additions & 0 deletions sdk/src/main/java/com/bugsnag/android/DeliveryCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
*/
class DeliveryCompat implements Delivery {

// ignore deprecation of legacy clients
@SuppressWarnings("deprecation")
volatile ErrorReportApiClient errorReportApiClient;
@SuppressWarnings("deprecation")
volatile SessionTrackingApiClient sessionTrackingApiClient;

@Override
Expand Down Expand Up @@ -35,6 +38,7 @@ public void deliver(Report report, Configuration config) throws DeliveryFailureE
}
}

@SuppressWarnings("deprecation") // ignore networkexception deprecation
void handleException(Throwable throwable) throws DeliveryFailureException {
if (throwable instanceof NetworkException) {
throw new DeliveryFailureException(throwable.getMessage(), throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @see Delivery
*/
public class DeliveryFailureException extends Exception {
private static final long serialVersionUID = 1501477209400426470L;

public DeliveryFailureException(String message) {
super(message);
}
Expand Down
3 changes: 3 additions & 0 deletions sdk/src/main/java/com/bugsnag/android/DeviceData.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ private String[] getCpuAbi() {
* Get the free disk space on the smallest disk
*/
@Nullable
@SuppressWarnings("deprecation") // ignore blockSizeLong suggestions for now (requires API 18)
private Long calculateFreeDisk() {
try {
StatFs externalStat = new StatFs(Environment.getExternalStorageDirectory().getPath());
Expand Down Expand Up @@ -336,6 +337,7 @@ private Boolean isCharging() {
* Get the current status of location services
*/
@Nullable
@SuppressWarnings("deprecation") // LOCATION_PROVIDERS_ALLOWED is deprecated
private String getLocationStatus() {
try {
ContentResolver cr = appContext.getContentResolver();
Expand Down Expand Up @@ -404,6 +406,7 @@ static String[] getSupportedAbis() {
*/
static class Abi2Wrapper {
@NonNull
@SuppressWarnings("deprecation") // new API already used elsewhere
static String[] getAbi1andAbi2() {
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/main/java/com/bugsnag/android/JsonWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ enum JsonScope {
static {
REPLACEMENT_CHARS = new String[128];
for (int i = 0; i <= 0x1f; i++) {
REPLACEMENT_CHARS[i] = String.format("\\u%04x", (int) i);
REPLACEMENT_CHARS[i] = String.format("\\u%04x", i);
}
REPLACEMENT_CHARS['"'] = "\\\"";
REPLACEMENT_CHARS['\\'] = "\\\\";
Expand Down
10 changes: 8 additions & 2 deletions sdk/src/main/java/com/bugsnag/android/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void clearTab(String tabName) {

@NonNull
Map<String, Object> getTab(String tabName) {
@SuppressWarnings("unchecked")
Map<String, Object> tab = (Map<String, Object>) store.get(tabName);

if (tab == null) {
Expand Down Expand Up @@ -135,12 +136,14 @@ static MetaData merge(@NonNull MetaData... metaDataList) {
}
}

@SuppressWarnings({"unchecked", "rawtypes"})
MetaData newMeta = new MetaData(mergeMaps(stores.toArray(new Map[0])));
newMeta.setFilters(filters.toArray(new String[filters.size()]));

return newMeta;
}

@SafeVarargs
@NonNull
private static Map<String, Object> mergeMaps(@NonNull Map<String, Object>... maps) {
Map<String, Object> result = new ConcurrentHashMap<>();
Expand All @@ -163,8 +166,11 @@ private static Map<String, Object> mergeMaps(@NonNull Map<String, Object>... map
&& baseValue instanceof Map
&& overridesValue instanceof Map) {
// Both original and overrides are Maps, go deeper
result.put(key, mergeMaps((Map<String, Object>) baseValue,
(Map<String, Object>) overridesValue));
@SuppressWarnings("unchecked")
Map<String, Object> first = (Map<String, Object>) baseValue;
@SuppressWarnings("unchecked")
Map<String, Object> second = (Map<String, Object>) overridesValue;
result.put(key, mergeMaps(first, second));
} else {
result.put(key, overridesValue);
}
Expand Down
5 changes: 2 additions & 3 deletions sdk/src/main/java/com/bugsnag/android/NativeInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void configureClientObservers(@NonNull Client client) {
// Should only happen if the NDK library is present
try {
String className = "com.bugsnag.android.ndk.BugsnagObserver";
Class clz = Class.forName(className);
Class<?> clz = Class.forName(className);
Observer observer = (Observer) clz.newInstance();
client.addObserver(observer);
} catch (ClassNotFoundException exception) {
Expand Down Expand Up @@ -256,11 +256,10 @@ public void beforeNotify(@NonNull Report report) {
error.config.defaultExceptionType = "c";

for (String tab : metaData.keySet()) {

Object value = metaData.get(tab);

if (value instanceof Map) {
Map map = (Map) value;
@SuppressWarnings("unchecked") Map<Object, Object> map = (Map) value;

for (Object key : map.keySet()) {
error.getMetaData().addToTab(tab, key.toString(), map.get(key));
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/main/java/com/bugsnag/android/NetworkException.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
@Deprecated
public class NetworkException extends IOException {
private static final long serialVersionUID = -4370366096145029322L;

public NetworkException(String msg, Throwable cause) {
super(msg, cause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ void objectToStream(@Nullable Object obj,
// Map objects
writer.beginObject();
for (Object o : ((Map) obj).entrySet()) {
Map.Entry entry = (Map.Entry) o;

@SuppressWarnings("unchecked")
Map.Entry<Object, Object> entry = (Map.Entry<Object, Object>) o;

Object keyObj = entry.getKey();
if (keyObj instanceof String) {
String key = (String) keyObj;
Expand Down