summaryrefslogtreecommitdiff
path: root/tests/UsbHostExternalManagmentTest
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2017-03-22 14:28:08 +0000
committerNarayan Kamath <narayan@google.com>2017-04-03 18:12:04 +0100
commit492e9e851cadca62df84eaff1a3c1ba788492fba (patch)
tree61d47e46bb22366413a021f025b3c8e16713c55b /tests/UsbHostExternalManagmentTest
parent2a071d69b455399474d56cd2099e9944aec83224 (diff)
Properly guard access to CloseGuard in finalizers.
CloseGuard instances are allocated in constructors and usually assigned to final fields. This implies they're non-null in finalizers except in the case where the constructor throws. We add a null check to make sure we can continue cleaning up other state in the finalizer (if applicable). Also, this change decouples closeguard warnings in constructors from other state based logic. This because the logic there is usually duplicated with the call to close(). NOTE: This change is not a "complete" fix. Many of these finalizers are broken in the case where <init> throws. The only objective of this change is to make such errors more obvious. Note that some of these classes don't have CTS tests. Test: make, CtsMediaTestCases. Bug: 35609098 Change-Id: I24d9e0215f80e44914dba8ab99b6312fd6ed1fc0
Diffstat (limited to 'tests/UsbHostExternalManagmentTest')
-rw-r--r--tests/UsbHostExternalManagmentTest/UsbHostExternalManagmentTestApp/src/com/android/hardware/usb/externalmanagementtest/UsbDeviceStateController.java5
1 files changed, 4 insertions, 1 deletions
diff --git a/tests/UsbHostExternalManagmentTest/UsbHostExternalManagmentTestApp/src/com/android/hardware/usb/externalmanagementtest/UsbDeviceStateController.java b/tests/UsbHostExternalManagmentTest/UsbHostExternalManagmentTestApp/src/com/android/hardware/usb/externalmanagementtest/UsbDeviceStateController.java
index 1cb394e4d2ab..42f7955bee98 100644
--- a/tests/UsbHostExternalManagmentTest/UsbHostExternalManagmentTestApp/src/com/android/hardware/usb/externalmanagementtest/UsbDeviceStateController.java
+++ b/tests/UsbHostExternalManagmentTest/UsbHostExternalManagmentTestApp/src/com/android/hardware/usb/externalmanagementtest/UsbDeviceStateController.java
@@ -89,7 +89,10 @@ public class UsbDeviceStateController {
@Override
protected void finalize() throws Throwable {
try {
- mCloseGuard.warnIfOpen();
+ if (mCloseGuard != null) {
+ mCloseGuard.warnIfOpen();
+ }
+
release();
} finally {
super.finalize();