1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

Java OCA: bug in PoolElement uid() and gid() methods

This commit is contained in:
Carlos Martín 2011-06-09 17:09:12 +02:00
parent 099b748585
commit c48db468e1
2 changed files with 27 additions and 5 deletions

View File

@ -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)

View File

@ -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() );