Juan Hernandez has uploaded a new change for review.

Change subject: restapi: Avoid NPE when enum has no value
......................................................................

restapi: Avoid NPE when enum has no value

The mechanism that we currently use to validate enum values donsn't take
into account that the values may be null. When this happens a NPE is
triggered and logged, instead of generating a user friendly message.
This patch changes the validation logic so that it will generate a
reasonable error message.

Change-Id: Ie8e2ba41729bcbbf5b24a64e51dd258c039bed4e
Signed-off-by: Juan Hernandez <[email protected]>
---
M 
backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/EnumValidator.java
1 file changed, 2 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/80/36080/1

diff --git 
a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/EnumValidator.java
 
b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/EnumValidator.java
index 9b7eeb1..797f135 100644
--- 
a/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/EnumValidator.java
+++ 
b/backend/manager/modules/restapi/interface/common/jaxrs/src/main/java/org/ovirt/engine/api/common/util/EnumValidator.java
@@ -84,7 +84,7 @@
     public static <E extends Enum<E>> E validateEnum(String reason, String 
detail, Class<E> clz, String name, boolean toUppercase) {
         try {
             return Enum.valueOf(clz, toUppercase ? name.toUpperCase() : name);
-        } catch (IllegalArgumentException e) {
+        } catch (IllegalArgumentException|NullPointerException e) {
             detail = detail + getPossibleValues(clz);
             throw new WebApplicationException(response(reason, 
MessageFormat.format(detail, name, clz.getSimpleName())));
         }
@@ -99,7 +99,7 @@
 
         try {
             return Enum.valueOf(clz, toUppercase ? name.toUpperCase() : 
name).name();
-        } catch (IllegalArgumentException e) {
+        } catch (IllegalArgumentException|NullPointerException e) {
             detail = detail + getPossibleValues(clz, 
OsTypeUtils.getAllValues());
             throw new WebApplicationException(response(reason, 
MessageFormat.format(detail, name, clz.getSimpleName())));
         }


-- 
To view, visit http://gerrit.ovirt.org/36080
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie8e2ba41729bcbbf5b24a64e51dd258c039bed4e
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Juan Hernandez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to