changeset 78:405b79ef234d

8068181: Unexpected ServiceConfigurationError Summary: Added try/catch Reviewed-by: snazarki Contributed-by: alexey.mironov@oracle.com
author amironov
date Wed, 24 Dec 2014 14:17:57 +0300
parents 8109a64f0ee6
children f383add578f5
files src/share/classes/jdk/dio/DeviceManager.java
diffstat 1 files changed, 60 insertions(+), 50 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/jdk/dio/DeviceManager.java	Tue Dec 23 15:46:19 2014 +0400
+++ b/src/share/classes/jdk/dio/DeviceManager.java	Wed Dec 24 14:17:57 2014 +0300
@@ -29,6 +29,7 @@
 import java.security.AccessController;
 import java.util.Iterator;
 import java.util.Random;
+import java.util.ServiceConfigurationError;
 import java.util.ServiceLoader;
 
 import com.oracle.dio.impl.PeripheralDescriptorImpl;
@@ -1112,44 +1113,49 @@
         ServiceLoader<DeviceProvider> loader = ServiceLoader.load(DeviceProvider.class);
         Iterator<DeviceProvider>  iter = loader.iterator();
 
-        if (!iter.hasNext()) {
-            return null;
+        boolean found = false;
+        try {
+            if (!iter.hasNext()) {
+                return null;
+            }
+
+            int rejected, total;
+            rejected = total = 0;
+            while (iter.hasNext()) {
+                total++;
+                DeviceProvider provider = iter.next();
+                if (!provider.getConfigType().isAssignableFrom(config.getClass())) {
+                    rejected++;
+                }
+            }
+
+            if (rejected == total) {
+                // caller will rethrow UDTE or DNFE
+                return null;
+            }
+
+            iter = loader.iterator();
+
+            while (iter.hasNext()) {
+                DeviceProvider provider = iter.next();
+
+                try {
+                    // properties was checked by Registry when descriptor was loaded up
+                    return (P)provider.open(config,null,mode);
+                } catch (UnavailableDeviceException e) {
+                    // throw UPE if sunsequent operation is not success
+                    found = true;
+                    continue;
+                } catch (DeviceNotFoundException e2) {
+                    // try other driver.
+                    // now there is no way to determine what driver accepts config with correct hardware information
+                    // therefore it is neccesarry to test all of them
+                    continue;
+                }
         }
-
-        int rejected, total;
-        rejected = total = 0;
-        while (iter.hasNext()) {
-            total++;
-            DeviceProvider provider = iter.next();
-            if (!provider.getConfigType().isAssignableFrom(config.getClass())) {
-                rejected++;
-            }
-        }
-
-        if (rejected == total) {
-            // caller will rethrow UDTE or DNFE
-            return null;
-        }
-
-        iter = loader.iterator();
-
-        boolean found = false;
-        while (iter.hasNext()) {
-            DeviceProvider provider = iter.next();
-
-            try {
-                // properties was checked by Registry when descriptor was loaded up
-                return (P)provider.open(config,null,mode);
-            } catch (UnavailableDeviceException e) {
-                // throw UPE if sunsequent operation is not success
-                found = true;
-                continue;
-            } catch (DeviceNotFoundException e2) {
-                // try other driver.
-                // now there is no way to determine what driver accepts config with correct hardware information
-                // therefore it is neccesarry to test all of them
-                continue;
-            }
+        } catch (ServiceConfigurationError  ex) {
+                             // service framework exception equals to empty iterator
+                             return null;
         }
         if (found) {
             throw new UnavailableDeviceException(
@@ -1166,25 +1172,29 @@
         DeviceNotFoundException, UnavailableDeviceException, InvalidDeviceConfigException,
         UnsupportedAccessModeException, IOException {
         Iterator<DeviceProvider>  iter = ServiceLoader.load(DeviceProvider.class).iterator();
-        while (iter.hasNext()) {
-            DeviceProvider provider = iter.next();
+        try {
+            while (iter.hasNext()) {
+                DeviceProvider provider = iter.next();
 
-            if (!provider.getConfigType().isAssignableFrom(intf)) {
-                continue;
-            }
+                if (!provider.getConfigType().isAssignableFrom(intf)) {
+                    continue;
+                }
 
-            // found driver that recognizes intf type
-            supported = true;
+                // found driver that recognizes intf type
+                supported = true;
 
-            if (provider.matches(props)) {
-                try {
-                    return (P)provider.open(null, props, mode);
-                } catch (UnavailableDeviceException e) {
-                    if (!iter.hasNext()) {
-                        throw e;
+                if (provider.matches(props)) {
+                    try {
+                        return (P)provider.open(null, props, mode);
+                    } catch (UnavailableDeviceException e) {
+                        if (!iter.hasNext()) {
+                            throw e;
+                        }
                     }
                 }
             }
+        } catch (ServiceConfigurationError ex) {
+            // intentionally ignored
         }
         if (supported) {
             throw new DeviceNotFoundException(