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

Eric Blake eblake at redhat.com
Mon Jul 23 20:56:55 UTC 2012


On 07/23/2012 04:31 AM, Claudio Bley wrote:
>> 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?

I think that might be better, after all.  With your patch...

>      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];

the old version crashed, and your version leaves code as null (which is
a strict improvement, but might cause its own NullPointer issue later
on).  Having an else branch that sticks in a placeholder would be nicer
to end clients to at least recognize that they are talking to a newer
server, without crashing.

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120723/307cd327/attachment-0001.sig>


More information about the libvir-list mailing list