Program: 86276
Project: 86276
Buggy source:
public static List<InterfaceAssociationDescriptor> parseDescriptors(UsbDeviceConnection connection,byte[] rawDescriptor){
  int length;
  byte[] desc;
  Type type;
  int i=0;
  State state=null;
  InterfaceAssociationDescriptor iad=null;
  ArrayList<InterfaceAssociationDescriptor> iads=new ArrayList<>();
  UvcInterface uvcInterface=null;
  Endpoint aEndpoint=null;
  int endpointIndex=1;
  while (i < rawDescriptor.length) {
    length=rawDescriptor[i];
    desc=new byte[length];
    System.arraycopy(rawDescriptor,i,desc,0,length);
    type=Type.getType(desc);
switch (type) {
case INTERFACE_ASSOCIATION:
      if (state == State.STANDARD_ENDPOINT) {
        i=rawDescriptor.length;
        break;
      }
    if (state != null) {
      throw new IllegalStateException("String_Node_Str" + state);
    }
  state=State.IAD;
iad=InterfaceAssociationDescriptor.parseIAD(desc);
iads.add(iad);
Timber.d("String_Node_Str",iad);
break;
case INTERFACE:
if (state != State.IAD && state != State.CLASS_INTERFACE && state != State.STANDARD_ENDPOINT && state != State.CLASS_ENDPOINT) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.STANDARD_INTERFACE;
endpointIndex=1;
uvcInterface=UvcInterface.parseDescriptor(connection,desc);
if (iad != null && uvcInterface != null) {
final UvcInterface existing=iad.getInterface(uvcInterface.getInterfaceNumber());
if (existing != null) {
existing.parseAlternateFunction(connection,desc);
}
 else {
iad.addInterface(uvcInterface);
}
}
break;
case CS_INTERFACE:
if (uvcInterface == null) {
throw new IllegalStateException("String_Node_Str");
}
if (state != State.STANDARD_INTERFACE && state != State.CLASS_INTERFACE) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.CLASS_INTERFACE;
uvcInterface.parseClassDescriptor(desc);
break;
case ENDPOINT:
if (uvcInterface == null) {
throw new IllegalStateException("String_Node_Str");
}
if (state != State.STANDARD_INTERFACE && state != State.CLASS_INTERFACE) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.STANDARD_ENDPOINT;
aEndpoint=Endpoint.parseDescriptor(uvcInterface.getUsbInterface(),desc);
uvcInterface.addEndpoint(endpointIndex,aEndpoint);
++endpointIndex;
break;
case CS_ENDPOINT:
if (aEndpoint == null) {
throw new IllegalStateException("String_Node_Str");
}
if (state != State.STANDARD_ENDPOINT) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.CLASS_ENDPOINT;
aEndpoint.parseClassDescriptor(desc);
break;
case DEVICE:
case DEVICE_QUALIFIER:
case CONFIGURATION:
break;
default :
Timber.d("String_Node_Str",Hexdump.dumpHexString(desc));
}
i+=length;
}
return iads;
}

Fixed version (ground truth):
public static List<InterfaceAssociationDescriptor> parseDescriptors(UsbDeviceConnection connection,byte[] rawDescriptor){
  int length;
  byte[] desc;
  Type type;
  int i=0;
  State state=null;
  InterfaceAssociationDescriptor iad=null;
  ArrayList<InterfaceAssociationDescriptor> iads=new ArrayList<>();
  UvcInterface uvcInterface=null;
  Endpoint aEndpoint=null;
  int endpointIndex=1;
  while (i < rawDescriptor.length) {
    length=rawDescriptor[i];
    desc=new byte[length];
    System.arraycopy(rawDescriptor,i,desc,0,length);
    type=Type.getType(desc);
switch (type) {
case INTERFACE_ASSOCIATION:
      if (state == State.STANDARD_ENDPOINT) {
        i=rawDescriptor.length;
        break;
      }
    if (state != null) {
      throw new IllegalStateException("String_Node_Str" + state);
    }
  state=State.IAD;
iad=InterfaceAssociationDescriptor.parseIAD(desc);
iads.add(iad);
break;
case INTERFACE:
if (state != State.IAD && state != State.CLASS_INTERFACE && state != State.STANDARD_ENDPOINT && state != State.CLASS_ENDPOINT) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.STANDARD_INTERFACE;
endpointIndex=1;
uvcInterface=UvcInterface.parseDescriptor(connection,desc);
if (iad != null && uvcInterface != null) {
final UvcInterface existing=iad.getInterface(uvcInterface.getInterfaceNumber());
if (existing != null) {
uvcInterface=existing;
existing.parseAlternateFunction(connection,desc);
}
 else {
iad.addInterface(uvcInterface);
}
}
break;
case CS_INTERFACE:
if (uvcInterface == null) {
throw new IllegalStateException("String_Node_Str");
}
if (state != State.STANDARD_INTERFACE && state != State.CLASS_INTERFACE) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.CLASS_INTERFACE;
uvcInterface.parseClassDescriptor(desc);
break;
case ENDPOINT:
if (uvcInterface == null) {
throw new IllegalStateException("String_Node_Str");
}
if (state != State.STANDARD_INTERFACE && state != State.CLASS_INTERFACE) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.STANDARD_ENDPOINT;
aEndpoint=Endpoint.parseDescriptor(uvcInterface.getUsbInterface(),desc);
uvcInterface.addEndpoint(endpointIndex,aEndpoint);
++endpointIndex;
break;
case CS_ENDPOINT:
if (aEndpoint == null) {
throw new IllegalStateException("String_Node_Str");
}
if (state != State.STANDARD_ENDPOINT) {
throw new IllegalStateException("String_Node_Str" + state);
}
state=State.CLASS_ENDPOINT;
aEndpoint.parseClassDescriptor(desc);
break;
case DEVICE:
case DEVICE_QUALIFIER:
case CONFIGURATION:
break;
default :
Timber.d("String_Node_Str",Hexdump.dumpHexString(desc));
}
i+=length;
}
return iads;
}