changeset 184:061aaa895a57

8130314: XXXPermission("::", good) doesn't throw an IAE Summary: Verefication of permission parameters format is added Reviewed-by: snazarki Contributed-by: olga.milovskaya@oracle.com
author snazarki
date Thu, 02 Jul 2015 18:13:06 +0300
parents da7936b5c7b6
children 3185db9d38e2
files src/share/classes/com/oracle/dio/utils/Utils.java src/share/classes/jdk/dio/DeviceMgmtPermission.java src/share/classes/jdk/dio/DevicePermission.java src/share/classes/jdk/dio/adc/ADCChannelConfig.java src/share/classes/jdk/dio/adc/ADCPermission.java src/share/classes/jdk/dio/atcmd/ATPermission.java src/share/classes/jdk/dio/counter/CounterPermission.java src/share/classes/jdk/dio/dac/DACChannelConfig.java src/share/classes/jdk/dio/dac/DACPermission.java src/share/classes/jdk/dio/generic/GenericPermission.java src/share/classes/jdk/dio/gpio/GPIOPinPermission.java src/share/classes/jdk/dio/gpio/GPIOPortPermission.java src/share/classes/jdk/dio/i2cbus/I2CPermission.java src/share/classes/jdk/dio/pwm/PWMChannelConfig.java src/share/classes/jdk/dio/pwm/PWMPermission.java src/share/classes/jdk/dio/spibus/SPIPermission.java src/share/classes/jdk/dio/uart/UARTPermission.java src/share/classes/jdk/dio/watchdog/WatchdogTimerPermission.java
diffstat 18 files changed, 257 insertions(+), 148 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/utils/Utils.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/com/oracle/dio/utils/Utils.java	Thu Jul 02 18:13:06 2015 +0300
@@ -34,6 +34,11 @@
  * Utility class for device permission class
  */
 public final class Utils {
+
+    public static final int EMPTY = 0;
+    public static final int DECIMAL_DIGITS = 1;
+    public static final int HEXADECIMAL_DIGITS = 2;
+    public static final int HEXADECIMAL_DIGITS_INTERVAL = 3;
     /**
      * Checks if <code>actions1</code> list "implies"
      * <code>actions2</code> list
@@ -195,10 +200,88 @@
     /**
      * Checks if no NaN and positive value
      */
-    public static void checkDoubleGreaterThanOne(double val) {
-
+    public static void checkDoubleGreaterThanZero(double val) {
         if (Double.compare(val, 1.0d) < 0 || Double.compare(val, Double.NaN) == 0 || Double.compare(val, Double.POSITIVE_INFINITY) == 0) {
             throw new IllegalArgumentException(Double.toString(val));
         }
     }
+
+    public static String[] parseDevicePermissionName(String name) {
+        String[] ret = new String[2];
+        int idx = -1;
+        while (-1 != (idx = name.indexOf(':', idx + 1))) {
+            if (idx == 0 || '\\' != name.charAt(idx - 1)) {
+                break;
+            }
+        }
+        if (-1 == idx) {
+            ret[0] = name;
+            ret[1] = "";
+
+        } else {
+            ret[0] = name.substring(0, idx);
+            ret[1] = name.substring(idx + 1);
+        }
+        return ret;
+    }
+
+    // type 0 - decimal digit
+    // type 1 - hexadecimal digit
+    // any other type - check empty string
+    public static void checkDevicePermissionChannelFormat(String name, int type) {
+
+        String channel = parseDevicePermissionName(name)[1];
+
+        if (channel.equals("*") || channel.equals(""))
+            return;
+
+        switch(type) {
+            //decimal digit
+            case DECIMAL_DIGITS:
+               if (!isNonNegativeNumber(channel, 10)) {
+                    throw new IllegalArgumentException();
+                }
+                break;
+            //hexadecimal digit
+            case HEXADECIMAL_DIGITS:
+                if (!isNonNegativeNumber(channel, 16)) {
+                    throw new IllegalArgumentException();
+                }
+                break;
+            case HEXADECIMAL_DIGITS_INTERVAL:
+                if (!isNonNegativeNumberInterval(channel)) {
+                    throw new IllegalArgumentException();
+                }
+                break;
+            default:
+               throw new IllegalArgumentException(name);
+        }
+
+    }
+
+    // Check all characters in the string are decimal digits
+    private static boolean isNonNegativeNumber(String str, int radix) {
+        try {
+            return Integer.parseInt(str, radix) >= 0;
+        } catch (NumberFormatException e) {
+            return false;
+        }
+    }
+
+    // Check the string has format {hexadecimal}-{hexadecimal}
+    private static boolean isNonNegativeNumberInterval(String str) {
+        int len = str.length();
+        int idx = str.indexOf('-');
+
+        if (-1 == idx || (len - 1) <= idx) {
+            return false;
+        }
+        try {
+            return Integer.parseInt(str.substring(0, idx), 16) >=0
+                && Integer.parseInt(str.substring(idx + 1), 16) >= 0;
+        } catch (NumberFormatException e) {
+            return false;
+        }
+    }
+
 }
--- a/src/share/classes/jdk/dio/DeviceMgmtPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/DeviceMgmtPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -142,6 +142,7 @@
      *             </ul>
      */
     public DeviceMgmtPermission(String name, String actions) {
+        // null check
         super(name.toString());
         if (null == actions) {
             throw new IllegalArgumentException(
--- a/src/share/classes/jdk/dio/DevicePermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/DevicePermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -33,59 +33,69 @@
 import romizer.Local;
 
 /**
- * The {@code DevicePermission} abstract class is the superclass of all device permissions.
+ * The {@code DevicePermission} abstract class is the superclass of all device
+ * permissions.
  * <p>
- * A {@code DevicePermission} permission has a target name and, optionally, a list of actions.
+ * A {@code DevicePermission} permission has a target name and, optionally, a
+ * list of actions.
  * </p><p>
- * The target name contains hardware addressing information. It takes the following form:</p>
- * <blockquote> <code>( {controller-spec} ) [ ":" {channel-spec}]</code> </blockquote>
+ * The target name contains hardware addressing information. It takes the
+ * following form:</p>
+ * <blockquote> <code>( {controller-spec} ) [ ":" {channel-spec}]</code>
+ * </blockquote>
  * <dl>
  * <dt><code>{controller-spec}</code></dt>
  * <dd>The <code>{controller-spec}</code> takes the following form: <blockquote>
- * <code>{controller-name-spec} | {controller-number} | "*" | ""</code> </blockquote>
+ * <code>{controller-name-spec} | {controller-number} | "*" | ""</code>
+ * </blockquote>
  * <dl>
  * <dt><code>{controller-name-spec}</code></dt>
- * <dd>The <code>{controller-name-spec}</code> string is the string representation of a controller name as
- * may be returned by a call to {@link DeviceConfig.HardwareAddressing#getControllerName
- * DeviceConfig.HardwareAddressing.getControllerName}. A controller name is Operating System specific
- * such as a <em>device file</em> name on UNIX systems. Occurrences of the semicolon character (
- * {@code ":"}) must be escaped with a backslash ({@code "\"}). A <code>{controller-name-spec}</code>
- * string that ends with an asterisk ({@code "*"}) is a prefix pattern that matches all the controller
- * names starting with the same prefix.</dd>
+ * <dd>The <code>{controller-name-spec}</code> string is the string
+ * representation of a controller name as may be returned by a call to {@link DeviceConfig.HardwareAddressing#getControllerName
+ * DeviceConfig.HardwareAddressing.getControllerName}. A controller name is
+ * Operating System specific such as a <em>device file</em> name on UNIX
+ * systems. Occurrences of the semicolon character ( {@code ":"}) must be
+ * escaped with a backslash ({@code "\"}). A <code>{controller-name-spec}</code>
+ * string that ends with an asterisk ({@code "*"}) is a prefix pattern that
+ * matches all the controller names starting with the same prefix.</dd>
  * <dt><code>{controller-number}</code></dt>
- * <dd>The <code>{controller-number}</code> string is the decimal string representation of a controller
- * number as may be returned by a call to
- * {@link DeviceConfig.HardwareAddressing#getControllerNumber
- * DeviceConfig.HardwareAddressing.getControllerNumber}. The characters in the string must all be
- * decimal digits.</dd>
+ * <dd>The <code>{controller-number}</code> string is the decimal string
+ * representation of a controller number as may be returned by a call to  {@link DeviceConfig.HardwareAddressing#getControllerNumber
+ * DeviceConfig.HardwareAddressing.getControllerNumber}. The characters in the
+ * string must all be decimal digits.</dd>
  * </dl>
- * A <code>{controller-spec}</code> specification consisting of the asterisk ({@code "*"}) matches all
- * controller names or numbers. A <code>{controller-spec}</code> specification consisting of the empty
- * string ({@code ""}) designates an undefined controller name or number that may only be matched by an
- * empty string or an asterisk.</dd>
+ * A <code>{controller-spec}</code> specification consisting of the asterisk
+ * ({@code "*"}) matches all controller names or numbers. A
+ * <code>{controller-spec}</code> specification consisting of the empty string
+ * ({@code ""}) designates an undefined controller name or number that may only
+ * be matched by an empty string or an asterisk.</dd>
  * <dt>{channel-spec}</dt>
  * <dd>The <code>{channel-spec}</code> takes the following form: <blockquote>
  * <code>{channel-desc} | "*" | ""</code> </blockquote>
  * <dl>
  * <dt><code>{channel-desc}</code></dt>
- * <dd>The <code>{channel-desc}</code> string is device type-specific and must be defined by
- * subclasses.</dd>
+ * <dd>The <code>{channel-desc}</code> string is device type-specific and must
+ * be defined by subclasses.</dd>
  * </dl>
- * A <code>{channel-spec}</code> specification consisting of the asterisk ({@code "*"}) matches all
- * channels. A <code>{channel-spec}</code> specification consisting of the empty string ({@code ""})
- * designates an undefined channel that may only be matched by an empty string or an asterisk.
+ * A <code>{channel-spec}</code> specification consisting of the asterisk
+ * ({@code "*"}) matches all channels. A <code>{channel-spec}</code>
+ * specification consisting of the empty string ({@code ""}) designates an
+ * undefined channel that may only be matched by an empty string or an asterisk.
  * <br>
- * The {@code DevicePermission} abstract class treats the <code>{channel-desc}</code> string
- * as an opaque string: a <code>{channel-spec}</code> string may therefore only be matched
- * by the exact same <code>{channel-spec}</code> string or by the asterisk ({@code "*"}).
+ * The {@code DevicePermission} abstract class treats the
+ * <code>{channel-desc}</code> string as an opaque string: a
+ * <code>{channel-spec}</code> string may therefore only be matched by the exact
+ * same <code>{channel-spec}</code> string or by the asterisk ({@code "*"}).
  * </dd>
  * </dl>
- * Subclasses of {@code DevicePermission} may defined additional specific target name formats to
- * designate devices using their specific hardware addressing information.
+ * Subclasses of {@code DevicePermission} may defined additional specific target
+ * name formats to designate devices using their specific hardware addressing
+ * information.
  * <p>
- * The actions to be granted are passed to the constructor in a string containing a list of one or
- * more comma-separated keywords. The supported common actions are {@code open} and
- * {@code powermanage}. Their meaning is defined as follows:</p>
+ * The actions to be granted are passed to the constructor in a string
+ * containing a list of one or more comma-separated keywords. The supported
+ * common actions are {@code open} and {@code powermanage}. Their meaning is
+ * defined as follows:</p>
  * <dl>
  * <dt>{@code open}</dt>
  * <dd>open a device (see {@link DeviceManager#open DeviceManager.open})</dd>
@@ -102,6 +112,7 @@
  */
 @apimarker.API("device-io_1.1")
 public abstract class DevicePermission extends Permission {
+
     /**
      * The {@code open} action.
      */
@@ -118,36 +129,31 @@
      */
     private String myActions;
 
+    private String thisDevice;
+    private String thisChannel;
+
     /**
-     * Constructs a new {@code DevicePermission} with the specified target name and the implicit
-     * {@code open} action.
-     * The target name is normalized so that leading and trailing spaces are removed
-     * and each occurrence of <code>{controller-number}</code> is represented in its canonical
-     * decimal representation form (without leading zeros).
+     * Constructs a new {@code DevicePermission} with the specified target name
+     * and the implicit {@code open} action. The target name is normalized so
+     * that leading and trailing spaces are removed and each occurrence of
+     * <code>{controller-number}</code> is represented in its canonical decimal
+     * representation form (without leading zeros).
      *
-     * @param name
-     *            the target name (as defined above).
-     * @throws NullPointerException
-     *             if {@code name} is {@code null}.
-     * @throws IllegalArgumentException
-     *             if {@code name} is not properly formatted.
+     * @param name the target name (as defined above).
+     * @throws NullPointerException if {@code name} is {@code null}.
+     * @throws IllegalArgumentException if {@code name} is not properly
+     * formatted.
      * @see #getName getName
      */
     public DevicePermission(String name) {
-        super(checkName(name));
+        // null check
+        super(name.toString());
+        String[] ret = Utils.parseDevicePermissionName(name);
+        thisDevice  = ret[0];
+        thisChannel = ret[1];
         myActions = OPEN;
     }
 
-    private static String checkName(String name) {
-        if(name == null){
-            throw new NullPointerException(
-                ExceptionMessage.format(ExceptionMessage.DEVICE_NULL_NAME)
-            );
-        }
-
-        return name;
-    }
-
     /**
      * Constructs a new {@code DevicePermission} instance with the specified target name and
      * action list.
@@ -171,19 +177,25 @@
      * @see #getName getName
      */
     public DevicePermission(String name, String actions) {
-        super(checkName(name));
+        // null check
+        super(name.toString());
+        String[] ret = Utils.parseDevicePermissionName(name);
+        thisDevice  = ret[0];
+        thisChannel = ret[1];
         myActions = actions;
     }
 
     /**
-     * Checks two {@code DevicePermission} objects for equality.
-     * Checks that {@code obj}'s class is the same as this object's class and has the
-     * same name (as returned by {@link Permission#getName Permission.getName}) and same actions (sorted as per {@link #getActions getActions}) as this object.
+     * Checks two {@code DevicePermission} objects for equality. Checks that
+     * {@code obj}'s class is the same as this object's class and has the same
+     * name (as returned by {@link Permission#getName Permission.getName}) and
+     * same actions (sorted as per {@link #getActions getActions}) as this
+     * object.
      *
-     * @param obj
-     *         the object to test for equality with this object.
-     * @return {@code true} if {@code obj}'s class is the same as this object's class and has the same target
-     *         name and actions as this object; {@code false} otherwise.
+     * @param obj the object to test for equality with this object.
+     * @return {@code true} if {@code obj}'s class is the same as this object's
+     * class and has the same target name and actions as this object;
+     * {@code false} otherwise.
      */
     @Override
     public boolean equals(Object obj) {
@@ -197,15 +209,16 @@
      * @param obj1 First object to compare
      * @param obj2 Second object to compare
      *
-     * @return {@code true} if objects are equals, {@code false}
-     *         otherwise
+     * @return {@code true} if objects are equals, {@code false} otherwise
      */
     static boolean equals(Object obj1, Object obj2) {
-        if (obj1 == obj2)
+        if (obj1 == obj2) {
             return true;
+        }
 
-        if ((obj1 == null) || (obj2 == null) || (obj1.getClass() != obj2.getClass()))
+        if ((obj1 == null) || (obj2 == null) || (obj1.getClass() != obj2.getClass())) {
             return false;
+        }
 
         Permission p1 = (Permission) obj1;
         Permission p2 = (Permission) obj2;
@@ -214,8 +227,8 @@
     }
 
     /**
-     * Returns the list of possible actions in the following order: {@code open} or
-     * {@code powermanage} (additional actions may be defined by subclasses).
+     * Returns the list of possible actions in the following order: {@code open}
+     * or {@code powermanage} (additional actions may be defined by subclasses).
      *
      * @return comma-separated list of possible actions.
      */
@@ -226,11 +239,14 @@
 
     /**
      * Returns the hash code value for this object. The hash code is calculated
-     * from this permission's name (as returned by {@link Permission#getName Permission.getName}) and actions (sorted as per {@link #getActions getActions})
-     * in a way that ensures that {@code permission1.equals(permission2)} implies
-     * that {@code permission1.hashCode()==permission2.hashCode()} for any two permissions,
-     * {@code permission1} and {@code permission2}, as required by the general contract of {@link Object#hashCode() Object.hashCode}
-     * and the contract of {@link Permission#hashCode Permission.hashCode}.
+     * from this permission's name (as returned by
+     * {@link Permission#getName Permission.getName}) and actions (sorted as per
+     * {@link #getActions getActions}) in a way that ensures that
+     * {@code permission1.equals(permission2)} implies that
+     * {@code permission1.hashCode()==permission2.hashCode()} for any two
+     * permissions, {@code permission1} and {@code permission2}, as required by
+     * the general contract of {@link Object#hashCode() Object.hashCode} and the
+     * contract of {@link Permission#hashCode Permission.hashCode}.
      *
      * @return a hash code value for this object.
      */
@@ -244,69 +260,46 @@
      * <p>
      * More specifically, this method returns {@code true} if:</p>
      * <ul>
-     * <li>{@code permission}'s class is the same as this object's class, and</li>
-     * <li>{@code permission}'s actions (as returned by {@link #getActions getActions}) are a proper subset of this object's action list, and</li>
-     * <li>{@code permission}'s hardware addressing information or range thereof is included in this
-     * object's hardware addressing information range; the implementation of this method by
-     * the {@code DevicePermission} abstract class treats the channel description (<code>{channel-desc}</code>) string
-     * as an opaque string: a channel specification (<code>{channel-spec}</code>) string may therefore only be matched
-     * by the exact same a channel specification string or by the asterisk ({@code "*"}).</li>
+     * <li>{@code permission}'s class is the same as this object's class,
+     * and</li>
+     * <li>{@code permission}'s actions (as returned by
+     * {@link #getActions getActions}) are a proper subset of this object's
+     * action list, and</li>
+     * <li>{@code permission}'s hardware addressing information or range thereof
+     * is included in this object's hardware addressing information range; the
+     * implementation of this method by the {@code DevicePermission} abstract
+     * class treats the channel description (<code>{channel-desc}</code>) string
+     * as an opaque string: a channel specification
+     * (<code>{channel-spec}</code>) string may therefore only be matched by the
+     * exact same a channel specification string or by the asterisk
+     * ({@code "*"}).</li>
      * </ul>
      *
-     * @param permission
-     *            the permission to check against.
-     * @return {@code true} if the specified permission is not {@code null} and is implied by this
-     *         object, {@code false} otherwise.
+     * @param permission the permission to check against.
+     * @return {@code true} if the specified permission is not {@code null} and
+     * is implied by this object, {@code false} otherwise.
      */
     @Override
     public boolean implies(Permission permission) {
 
-        if ((permission == null) || (permission.getClass() != getClass()))
+        if ((permission == null) || (permission.getClass() != getClass())) {
             return false;
-
-        if (!Utils.implies(myActions, permission.getActions())) return false;
-
-        int idx = -1;
-        String name = permission.getName();
-        while (-1 != (idx = name.indexOf(':', idx + 1))) {
-            if (idx == 0 || '\\' != name.charAt(idx - 1) ) {
-                break;
-            }
-        }
-        String thatDevice;
-        String thatChannel = "";
-        if (-1 == idx) {
-            thatDevice = name;
-        } else {
-            thatDevice = name.substring(0, idx);
-            thatChannel = name.substring(idx + 1);
         }
 
-        idx = -1;
-        name = getName();
-        while (-1 != (idx = name.indexOf(':', idx + 1))) {
-            if (idx == 0 || '\\' != name.charAt(idx - 1) ) {
-                break;
-            }
+        if (!Utils.implies(myActions, permission.getActions())) {
+            return false;
         }
 
-        String thisDevice;
-        String thisChannel = "";
-        if (-1 == idx) {
-            thisDevice = name;
-        } else {
-            thisDevice = name.substring(0, idx);
-            thisChannel = name.substring(idx + 1);
-        }
-
+        String thatDevice = ((DevicePermission) permission).thisDevice;
+        String thatChannel = ((DevicePermission) permission).thisChannel;
 
         // compare names
         if (!"*".equals(thisDevice)) { // if not pure wildcard
             if (thisDevice.endsWith("*")) {
                 // compare "\dev\tty*" and "\dev\*" or "\dev\tty1" and "\dev\*"
                 if (thisDevice.length() > thatDevice.length() || // wildcard has to be shorter or equals to other name or whildcard
-                    !thatDevice.startsWith(thisDevice.substring(0, thisDevice.length()-1)) // other name should starts with our wildcard
-                    ) {
+                        !thatDevice.startsWith(thisDevice.substring(0, thisDevice.length() - 1)) // other name should starts with our wildcard
+                        ) {
                     return false;
                 }
             } else {
@@ -331,17 +324,19 @@
     }
 
     @Local(WeakDontRenameSubtypes = {"jdk.dio.DevicePermission"})
-    public String toString(){
+    public String toString() {
         return getClass().getName() + " \'" + getName() + "\' " + getActions();
     }
 
     /**
-     * Returns a new {@code PermissionCollection} for storing {@code DevicePermission} objects.
+     * Returns a new {@code PermissionCollection} for storing
+     * {@code DevicePermission} objects.
      * <p>
-     * {@code DevicePermission} objects must be stored in a manner that allows them to be
-     * inserted into the collection in any order, but that also enables the
-     * {@link PermissionCollection#implies PermissionCollection.implies} method to be implemented in an efficient (and
-     * consistent) manner.
+     * {@code DevicePermission} objects must be stored in a manner that allows
+     * them to be inserted into the collection in any order, but that also
+     * enables the
+     * {@link PermissionCollection#implies PermissionCollection.implies} method
+     * to be implemented in an efficient (and consistent) manner.
      * </p><p>
      * For example, assuming a {@code PermissionCollection} object containing
      * the two following {@code DevicePermission}s:</p>
@@ -355,16 +350,19 @@
      * </p><pre>
      *   "adc:1", "open,powermanage",
      * </pre>
-     * <p>the {@code implies} method must take into account both the "adc:*"
-     * and "adc:1" permissions, so the effective permission is
-     * "open,powermanage", and {@code implies} returns {@code true}. The
-     * "implies" semantics for {@code DevicePermission}s are handled properly by
-     * the {@code PermissionCollection} object returned by this method. If a device-specific subclass
-     * of {@code DevicePermission} defines a different "implies" semantics then
-     * that subclass must re-implement this method accordingly.
+     * <p>
+     * the {@code implies} method must take into account both the "adc:*" and
+     * "adc:1" permissions, so the effective permission is "open,powermanage",
+     * and {@code implies} returns {@code true}. The "implies" semantics for
+     * {@code DevicePermission}s are handled properly by the
+     * {@code PermissionCollection} object returned by this method. If a
+     * device-specific subclass of {@code DevicePermission} defines a different
+     * "implies" semantics then that subclass must re-implement this method
+     * accordingly.
      * </p>
      *
-     * @return a new {@code PermissionCollection} suitable for storing {@code DevicePermission}.
+     * @return a new {@code PermissionCollection} suitable for storing
+     * {@code DevicePermission}.
      */
     @Override
     public PermissionCollection newPermissionCollection() {
@@ -377,7 +375,8 @@
     private final Vector<DevicePermission> permissions = new Vector<>(6);
     /**
      * The class to which all PeripheralPermissios in this
-     * PeripheralPermissionCollection belongs.*/
+     * PeripheralPermissionCollection belongs.
+     */
     private final Class permClazz;
 
     PeripheralPermissionCollection(Class clazz) {
@@ -386,7 +385,7 @@
 
     public boolean implies(Permission permission) {
         if (!permClazz.isInstance(permission)) {
-          return false;
+            return false;
         }
         DevicePermission perm = (DevicePermission) permission;
         Enumeration<DevicePermission> search = permissions.elements();
@@ -397,19 +396,22 @@
         }
         return false;
     }
+
     public void add(Permission permission) {
-        if (!permClazz.isInstance(permission))
+        if (!permClazz.isInstance(permission)) {
             throw new IllegalArgumentException(
-                ExceptionMessage.format(ExceptionMessage.DEVICE_INVALID_PERMISSION, permission)
+                    ExceptionMessage.format(ExceptionMessage.DEVICE_INVALID_PERMISSION, permission)
             );
+        }
         if (isReadOnly()) {
             throw new SecurityException(
-                ExceptionMessage.format(ExceptionMessage.DEVICE_READONLY_PERMISSION_COLLECTION)
+                    ExceptionMessage.format(ExceptionMessage.DEVICE_READONLY_PERMISSION_COLLECTION)
             );
         }
 
-        permissions.addElement((DevicePermission)permission);
+        permissions.addElement((DevicePermission) permission);
     }
+
     public Enumeration elements() {
         return permissions.elements();
     }
--- a/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/adc/ADCChannelConfig.java	Thu Jul 02 18:13:06 2015 +0300
@@ -127,8 +127,6 @@
          * @return this {@code Builder} instance.
          */
         public Builder setControllerName(String controllerName) {
-            // null check
-            controllerName.length();
             instance.controllerName = controllerName;
             return this;
         }
@@ -226,7 +224,7 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
-            Utils.checkDoubleGreaterThanOne(scaleFactor);
+            Utils.checkDoubleGreaterThanZero(scaleFactor);
             instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
             return this;
         }
--- a/src/share/classes/jdk/dio/adc/ADCPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/adc/ADCPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -70,6 +70,7 @@
      */
     public ADCPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -96,5 +97,7 @@
      */
     public ADCPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
+
 }
--- a/src/share/classes/jdk/dio/atcmd/ATPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/atcmd/ATPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -82,6 +82,7 @@
      */
     public ATPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -105,5 +106,6 @@
      */
     public ATPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderActions(actions, DevicePermission.OPEN + "," + DATA + "," + DevicePermission.POWER_MANAGE));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }
--- a/src/share/classes/jdk/dio/counter/CounterPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/counter/CounterPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -70,6 +70,7 @@
      */
     public CounterPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -96,6 +97,7 @@
      */
     public CounterPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }
 
--- a/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/dac/DACChannelConfig.java	Thu Jul 02 18:13:06 2015 +0300
@@ -203,7 +203,7 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
-            Utils.checkDoubleGreaterThanOne(scaleFactor);
+            Utils.checkDoubleGreaterThanZero(scaleFactor);
             instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
             return this;
         }
--- a/src/share/classes/jdk/dio/dac/DACPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/dac/DACPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -69,6 +69,7 @@
      */
     public DACPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -95,5 +96,6 @@
      */
     public DACPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }
--- a/src/share/classes/jdk/dio/generic/GenericPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/generic/GenericPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -68,6 +68,7 @@
      */
     public GenericPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -94,6 +95,7 @@
      */
     public GenericPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }
 
--- a/src/share/classes/jdk/dio/gpio/GPIOPinPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/gpio/GPIOPinPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -79,6 +79,7 @@
      */
     public GPIOPinPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -105,5 +106,6 @@
      */
     public GPIOPinPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderActions(actions, DevicePermission.OPEN + "," + DevicePermission.POWER_MANAGE + "," + SET_DIRECTION));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }
--- a/src/share/classes/jdk/dio/gpio/GPIOPortPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/gpio/GPIOPortPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -77,6 +77,7 @@
      */
     public GPIOPortPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.EMPTY);
     }
 
     /**
@@ -103,5 +104,6 @@
      */
     public GPIOPortPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderActions(actions, DevicePermission.OPEN + "," + DevicePermission.POWER_MANAGE + "," + SET_DIRECTION));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.EMPTY);
     }
 }
--- a/src/share/classes/jdk/dio/i2cbus/I2CPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/i2cbus/I2CPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -70,6 +70,7 @@
      */
     public I2CPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.HEXADECIMAL_DIGITS);
     }
 
     /**
@@ -96,5 +97,6 @@
      */
     public I2CPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.HEXADECIMAL_DIGITS);
     }
 }
--- a/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/pwm/PWMChannelConfig.java	Thu Jul 02 18:13:06 2015 +0300
@@ -242,7 +242,7 @@
          * defined range.
          */
         public Builder setScaleFactor(double scaleFactor) {
-            Utils.checkDoubleGreaterThanOne(scaleFactor);
+            Utils.checkDoubleGreaterThanZero(scaleFactor);
             instance.scaleFactor = Double.doubleToLongBits(scaleFactor);
             return this;
         }
--- a/src/share/classes/jdk/dio/pwm/PWMPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/pwm/PWMPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -72,6 +72,7 @@
      */
     public PWMPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -97,6 +98,7 @@
      */
     public PWMPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }
 
--- a/src/share/classes/jdk/dio/spibus/SPIPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/spibus/SPIPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -72,6 +72,7 @@
      */
     public SPIPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.HEXADECIMAL_DIGITS);
     }
 
     /**
@@ -97,6 +98,7 @@
      */
     public SPIPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+       Utils.checkDevicePermissionChannelFormat(name, Utils.HEXADECIMAL_DIGITS);
     }
 }
 
--- a/src/share/classes/jdk/dio/uart/UARTPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/uart/UARTPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -73,6 +73,7 @@
      */
     public UARTPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -98,6 +99,7 @@
      */
     public UARTPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }
 
--- a/src/share/classes/jdk/dio/watchdog/WatchdogTimerPermission.java	Thu Jun 25 15:09:14 2015 +0300
+++ b/src/share/classes/jdk/dio/watchdog/WatchdogTimerPermission.java	Thu Jul 02 18:13:06 2015 +0300
@@ -73,6 +73,7 @@
      */
     public WatchdogTimerPermission(String name) {
         super(name);
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 
     /**
@@ -98,6 +99,7 @@
      */
     public WatchdogTimerPermission(String name, String actions) {
         super(name, Utils.verifyAndOrderDeviceActions(actions));
+        Utils.checkDevicePermissionChannelFormat(name, Utils.DECIMAL_DIGITS);
     }
 }