Skip to content

NullPointerException in HIDManager.openByPath() and openById() #59

Description

@GoogleCodeExporter
What steps will reproduce the problem?
1. In 32-bit Linux, attempt to open a device when there are none plugged into 
the system. I tried both OpenJDK and Oracle JREs. The issue is not present on 
my 64-bit Windows machine.

The line:

for(HIDDeviceInfo d : devs)

throws a NullPointerException because listDevices() returns null.

I fixed the problem by changing to the source code:

public HIDDevice openById(int vendor_id, int product_id, String serial_number) 
throws IOException, HIDDeviceNotFoundException
{
    HIDDeviceInfo[] devs = listDevices();

    if(devs == null)
    {
        throw new HIDDeviceNotFoundException();
    }
    else
    {
        for(HIDDeviceInfo d : devs)
        {
            if(d.getVendor_id() == vendor_id && d.getProduct_id() == product_id && (serial_number == null || d.getSerial_number().equals(serial_number)))
                return d.open();
        }
        throw new HIDDeviceNotFoundException();
    }
}

Original issue reported on code.google.com by dmorr...@gmail.com on 23 Nov 2013 at 5:01

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions