From c48db468e1b27cfc791ec2db3de83236726cfbb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 9 Jun 2011 17:09:12 +0200 Subject: [PATCH] Java OCA: bug in PoolElement uid() and gid() methods --- .../org/opennebula/client/PoolElement.java | 31 ++++++++++++++++--- src/oca/java/test/TemplateTest.java | 1 + 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/oca/java/src/org/opennebula/client/PoolElement.java b/src/oca/java/src/org/opennebula/client/PoolElement.java index d2355fc990..72ea4e6b69 100644 --- a/src/oca/java/src/org/opennebula/client/PoolElement.java +++ b/src/oca/java/src/org/opennebula/client/PoolElement.java @@ -141,9 +141,19 @@ public abstract class PoolElement { */ public int uid() { - String uid = xpath("UID"); + String uid_str = xpath("UID"); + int uid_int = -1; - return uid != null ? Integer.parseInt( uid ) : -1; + if ( uid_str != null ) + { + try + { + uid_int = Integer.parseInt( uid_str ); + } + catch (NumberFormatException e) {} + } + + return uid_int; } /** @@ -153,9 +163,19 @@ public abstract class PoolElement { */ public int gid() { - String gid = xpath("GID"); + String gid_str = xpath("GID"); + int gid_int = -1; - return gid != null ? Integer.parseInt( gid ) : -1; + if ( gid_str != null ) + { + try + { + gid_int = Integer.parseInt( gid_str ); + } + catch (NumberFormatException e) {} + } + + return gid_int; } /** @@ -165,7 +185,8 @@ public abstract class PoolElement { * * @param expression The XPath expression. * @return The String that is the result of evaluating the - * expression and converting the result to a String. Null if + * expression and converting the result to a String. An empty String is + * returned if the expression is not a valid path; null if * the internal xml representation is not built. */ public String xpath(String expression) diff --git a/src/oca/java/test/TemplateTest.java b/src/oca/java/test/TemplateTest.java index 90bdacb43b..3513a85ecc 100644 --- a/src/oca/java/test/TemplateTest.java +++ b/src/oca/java/test/TemplateTest.java @@ -214,6 +214,7 @@ public class TemplateTest assertTrue( template.gid() == 0 ); res = template.chown(uid, gid); + assertTrue( !res.isError() ); res = template.info(); assertTrue( !res.isError() );