Re: [PATCH] [libvirt-java] Fix Array IndexOutOfBoundsException for unknown error codes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

I re-formatted the patch such that "git am" understands it.

Is it OK?

At Mon, 09 Jul 2012 10:21:49 +0200,
Claudio Bley wrote:
>
> I'm using libvirt-java 0.4.7 and libvirt 0.9.8.
> 
> When libvirt returns an error code which is not mapped in enum
> ErrorNumber, an IndexOutOfBoundsException is thrown.
> 
> I realize that the freshly released libvirt-java 0.4.8 supports all
> error codes up to libvirt 0.9.12. But that doesn't fix the problem.
> 
> Would it be feasible to add a special UNKNOWN enum value?

-- >8 --
Subject: [PATCH] Fix IndexOutOfBoundsException for unknown error codes.

---
 src/main/java/org/libvirt/Error.java | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/main/java/org/libvirt/Error.java b/src/main/java/org/libvirt/Error.java
index f185ce0..faf89ff 100644
--- a/src/main/java/org/libvirt/Error.java
+++ b/src/main/java/org/libvirt/Error.java
@@ -186,9 +186,12 @@ public class Error implements Serializable {
     }
 
     public Error(virError vError) {
-        code = ErrorNumber.values()[vError.code];
-        domain = ErrorDomain.values()[vError.domain];
-        level = ErrorLevel.values()[vError.level];
+        if (ErrorNumber.values().length > vError.code)
+            code = ErrorNumber.values()[vError.code];
+        if (ErrorDomain.values().length > vError.domain)
+            domain = ErrorDomain.values()[vError.domain];
+        if (ErrorLevel.values().length > vError.level)
+            level = ErrorLevel.values()[vError.level];
         message = vError.message;
         str1 = vError.str1;
         str2 = vError.str2;
-- 
1.7.11.msysgit.0

-- 
AV-Test GmbH, Henricistraße 20, 04155 Leipzig, Germany
Phone: +49 341 265 310 19
Web:<http://www.av-test.org>

Eingetragen am / Registered at: Amtsgericht Stendal (HRB 114076)
Geschaeftsfuehrer (CEO): Andreas Marx, Guido Habicht, Maik Morgenstern

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]