Wrap any fallible libvirt function in a call to
ErrorHandler.processError(..).
Adjust the doc comment for storageVolLookupByName to indicate that
it might return null.
Also correct wrong javadoc comments stating that methods would return
a value in case an error occurs.
Signed-off-by: Claudio Bley cb...@av-test.de
---
src/main/java/org/libvirt/StoragePool.java | 95 +---
1 file changed, 30 insertions(+), 65 deletions(-)
diff --git a/src/main/java/org/libvirt/StoragePool.java
b/src/main/java/org/libvirt/StoragePool.java
index 2d59f68..bb608e3 100644
--- a/src/main/java/org/libvirt/StoragePool.java
+++ b/src/main/java/org/libvirt/StoragePool.java
@@ -5,6 +5,7 @@ import org.libvirt.jna.StoragePoolPointer;
import org.libvirt.jna.StorageVolPointer;
import org.libvirt.jna.virStoragePoolInfo;
import static org.libvirt.Library.libvirt;
+import static org.libvirt.ErrorHandler.processError;
import com.sun.jna.Native;
import com.sun.jna.ptr.IntByReference;
@@ -72,8 +73,7 @@ public class StoragePool {
*future flags, use 0 for now
*/
public void build(int flags) throws LibvirtException {
-libvirt.virStoragePoolBuild(VSPP, flags);
-processError();
+processError(libvirt.virStoragePoolBuild(VSPP, flags));
}
/**
@@ -83,8 +83,7 @@ public class StoragePool {
*future flags, use 0 for now
*/
public void create(int flags) throws LibvirtException {
-libvirt.virStoragePoolCreate(VSPP, flags);
-processError();
+processError(libvirt.virStoragePoolCreate(VSPP, flags));
}
/**
@@ -95,8 +94,7 @@ public class StoragePool {
*flags for obliteration process
*/
public void delete(int flags) throws LibvirtException {
-libvirt.virStoragePoolDelete(VSPP, flags);
-processError();
+processError(libvirt.virStoragePoolDelete(VSPP, flags));
}
/**
@@ -106,8 +104,7 @@ public class StoragePool {
* This does not free the associated virStoragePoolPtr object.
*/
public void destroy() throws LibvirtException {
-libvirt.virStoragePoolDestroy(VSPP);
-processError();
+processError(libvirt.virStoragePoolDestroy(VSPP));
}
@Override
@@ -120,13 +117,12 @@ public class StoragePool {
* not change the state of the pool on the host.
*
* @throws LibvirtException
- * @return number of references left (= 0) for success, -1 for failure.
+ * @return number of references left (= 0)
*/
public int free() throws LibvirtException {
int success = 0;
if (VSPP != null) {
-success = libvirt.virStoragePoolFree(VSPP);
-processError();
+success = processError(libvirt.virStoragePoolFree(VSPP));
VSPP = null;
}
return success;
@@ -141,8 +137,7 @@ public class StoragePool {
*/
public boolean getAutostart() throws LibvirtException {
IntByReference autoStart = new IntByReference();
-libvirt.virStoragePoolGetAutostart(VSPP, autoStart);
-processError();
+processError(libvirt.virStoragePoolGetAutostart(VSPP, autoStart));
return autoStart.getValue() != 0 ? true : false;
}
@@ -164,8 +159,7 @@ public class StoragePool {
*/
public StoragePoolInfo getInfo() throws LibvirtException {
virStoragePoolInfo vInfo = new virStoragePoolInfo();
-libvirt.virStoragePoolGetInfo(VSPP, vInfo);
-processError();
+processError(libvirt.virStoragePoolGetInfo(VSPP, vInfo));
return new StoragePoolInfo(vInfo);
}
@@ -176,9 +170,7 @@ public class StoragePool {
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
-String returnValue = libvirt.virStoragePoolGetName(VSPP);
-processError();
-return returnValue;
+return processError(libvirt.virStoragePoolGetName(VSPP));
}
/**
@@ -189,13 +181,8 @@ public class StoragePool {
*/
public int[] getUUID() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
-int success = libvirt.virStoragePoolGetUUID(VSPP, bytes);
-processError();
-int[] returnValue = new int[0];
-if (success == 0) {
-returnValue = Connect.convertUUIDBytes(bytes);
-}
-return returnValue;
+processError(libvirt.virStoragePoolGetUUID(VSPP, bytes));
+return Connect.convertUUIDBytes(bytes);
}
/**
@@ -206,13 +193,8 @@ public class StoragePool {
*/
public String getUUIDString() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
-int success = libvirt.virStoragePoolGetUUIDString(VSPP, bytes);
-processError();
-String returnValue = null;
-if (success == 0) {
-returnValue =