Program: 65167
Project: 65167
Buggy source:
/** 
 * INTERNAL compute the re-ordered indices - Do the IN args first, then the 'IN-half' of the INOUT args next, the OUT args, then the 'OUT-half' of the INOUT args
 */
protected void assignIndices(){
  List<PLSQLargument> inArguments=getArguments(arguments,IN);
  List<PLSQLargument> inOutArguments=getArguments(arguments,INOUT);
  inArguments.addAll(inOutArguments);
  int newIndex=1;
  List<PLSQLargument> expandedArguments=new ArrayList<PLSQLargument>();
  for (ListIterator<PLSQLargument> inArgsIter=inArguments.listIterator(); inArgsIter.hasNext(); ) {
    PLSQLargument inArg=inArgsIter.next();
    if (inArg.databaseType.isComplexDatabaseType() && (!((ComplexDatabaseType)inArg.databaseType).hasCompatibleType())) {
      expandedArguments.add(inArg);
      inArgsIter.remove();
    }
  }
  inArguments.addAll(expandedArguments);
  for (ListIterator<PLSQLargument> inArgsIter=inArguments.listIterator(); inArgsIter.hasNext(); ) {
    PLSQLargument inArg=inArgsIter.next();
    newIndex=inArg.databaseType.computeInIndex(inArg,newIndex,inArgsIter);
  }
  for (  PLSQLargument inArg : inArguments) {
    DatabaseType type=inArg.databaseType;
    if (!type.isComplexDatabaseType()) {
      super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode());
    }
 else {
      ComplexDatabaseType complexType=(ComplexDatabaseType)type;
      if (inArg.inIndex != MIN_VALUE) {
        if (type instanceof OracleObjectType) {
          super.addNamedArgument(inArg.name,inArg.name,Types.STRUCT,complexType.getCompatibleType());
        }
 else         if (complexType instanceof OracleArrayType) {
          DatabaseType nestedType=((OracleArrayType)type).getNestedType();
          if (nestedType != null) {
            ObjectRelationalDatabaseField field=new ObjectRelationalDatabaseField(inArg.name);
            field.setSqlType(Types.STRUCT);
            if (nestedType.isComplexDatabaseType()) {
              field.setSqlTypeName(((ComplexDatabaseType)nestedType).getCompatibleType());
            }
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType(),field);
          }
 else {
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType());
          }
        }
 else         if (type instanceof PLSQLCollection) {
          DatabaseType nestedType=((PLSQLCollection)type).getNestedType();
          if (nestedType != null) {
            ObjectRelationalDatabaseField field=new ObjectRelationalDatabaseField(inArg.name);
            field.setSqlType(nestedType.getConversionCode());
            if (nestedType.isComplexDatabaseType()) {
              field.setSqlTypeName(((ComplexDatabaseType)nestedType).getCompatibleType());
            }
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType(),field);
          }
 else {
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType());
          }
        }
 else {
          super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType());
        }
      }
    }
  }
  List<PLSQLargument> outArguments=getArguments(arguments,OUT);
  outArguments.addAll(inOutArguments);
  for (ListIterator<PLSQLargument> outArgsIter=outArguments.listIterator(); outArgsIter.hasNext(); ) {
    PLSQLargument outArg=outArgsIter.next();
    newIndex=outArg.databaseType.computeOutIndex(outArg,newIndex,outArgsIter);
  }
  for (  PLSQLargument outArg : outArguments) {
    DatabaseType type=outArg.databaseType;
    if (!type.isComplexDatabaseType()) {
      super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode());
    }
 else {
      ComplexDatabaseType complexType=(ComplexDatabaseType)type;
      if (outArg.outIndex != MIN_VALUE) {
        if (complexType instanceof OracleArrayType) {
          DatabaseType nestedType=((OracleArrayType)complexType).getNestedType();
          if (nestedType != null) {
            ObjectRelationalDatabaseField nestedField=new ObjectRelationalDatabaseField(outArg.name);
            nestedField.setSqlType(Types.STRUCT);
            if (nestedType.isComplexDatabaseType()) {
              ComplexDatabaseType complexNestedType=(ComplexDatabaseType)nestedType;
              nestedField.setType(complexNestedType.getJavaType());
              nestedField.setSqlTypeName(complexNestedType.getCompatibleType());
            }
            super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getTypeName(),complexType.getJavaType(),nestedField);
          }
 else {
            super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getTypeName(),complexType.getJavaType());
          }
        }
 else         if (complexType instanceof OracleObjectType) {
          super.addNamedOutputArgument(outArg.name,outArg.name,Types.STRUCT,complexType.getTypeName(),complexType.getJavaType());
        }
 else         if (complexType instanceof PLSQLCollection) {
          DatabaseType nestedType=((PLSQLCollection)complexType).getNestedType();
          if (nestedType != null) {
            ObjectRelationalDatabaseField nestedField=new ObjectRelationalDatabaseField(outArg.name);
            nestedField.setSqlType(nestedType.getConversionCode());
            if (nestedType.isComplexDatabaseType()) {
              ComplexDatabaseType complexNestedType=(ComplexDatabaseType)nestedType;
              nestedField.setType(complexNestedType.getJavaType());
              nestedField.setSqlTypeName(complexNestedType.getCompatibleType());
            }
            super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getCompatibleType(),complexType.getJavaType(),nestedField);
          }
 else {
            super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getCompatibleType());
          }
        }
 else         if (complexType.hasCompatibleType()) {
          super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getCompatibleType(),complexType.getJavaType());
        }
 else {
          super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode());
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * INTERNAL compute the re-ordered indices - Do the IN args first, then the 'IN-half' of the INOUT args next, the OUT args, then the 'OUT-half' of the INOUT args
 */
protected void assignIndices(){
  List<PLSQLargument> inArguments=getArguments(arguments,IN);
  List<PLSQLargument> inOutArguments=getArguments(arguments,INOUT);
  inArguments.addAll(inOutArguments);
  int newIndex=1;
  List<PLSQLargument> expandedArguments=new ArrayList<PLSQLargument>();
  for (ListIterator<PLSQLargument> inArgsIter=inArguments.listIterator(); inArgsIter.hasNext(); ) {
    PLSQLargument inArg=inArgsIter.next();
    if (inArg.databaseType.isComplexDatabaseType() && (!((ComplexDatabaseType)inArg.databaseType).hasCompatibleType())) {
      expandedArguments.add(inArg);
      inArgsIter.remove();
    }
  }
  inArguments.addAll(expandedArguments);
  for (ListIterator<PLSQLargument> inArgsIter=inArguments.listIterator(); inArgsIter.hasNext(); ) {
    PLSQLargument inArg=inArgsIter.next();
    newIndex=inArg.databaseType.computeInIndex(inArg,newIndex,inArgsIter);
  }
  for (  PLSQLargument inArg : inArguments) {
    DatabaseType type=inArg.databaseType;
    if (!type.isComplexDatabaseType()) {
      super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode());
    }
 else {
      ComplexDatabaseType complexType=(ComplexDatabaseType)type;
      if (inArg.inIndex != MIN_VALUE) {
        if (type instanceof OracleObjectType) {
          super.addNamedArgument(inArg.name,inArg.name,Types.STRUCT,complexType.getCompatibleType());
        }
 else         if (complexType instanceof OracleArrayType) {
          DatabaseType nestedType=((OracleArrayType)type).getNestedType();
          if (nestedType != null) {
            ObjectRelationalDatabaseField field=new ObjectRelationalDatabaseField(inArg.name);
            field.setSqlType(Types.STRUCT);
            if (nestedType.isComplexDatabaseType()) {
              field.setSqlTypeName(((ComplexDatabaseType)nestedType).getCompatibleType());
            }
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType(),field);
          }
 else {
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType());
          }
        }
 else         if (type instanceof PLSQLCollection) {
          DatabaseType nestedType=((PLSQLCollection)type).getNestedType();
          if (nestedType != null) {
            ObjectRelationalDatabaseField field=new ObjectRelationalDatabaseField(inArg.name);
            field.setSqlType(nestedType.getConversionCode());
            if (nestedType.isComplexDatabaseType()) {
              field.setSqlTypeName(((ComplexDatabaseType)nestedType).getCompatibleType());
            }
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType(),field);
          }
 else {
            super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType());
          }
        }
 else {
          super.addNamedArgument(inArg.name,inArg.name,type.getConversionCode(),complexType.getCompatibleType());
        }
      }
    }
  }
  List<PLSQLargument> outArguments=getArguments(arguments,OUT);
  outArguments.addAll(inOutArguments);
  for (ListIterator<PLSQLargument> outArgsIter=outArguments.listIterator(); outArgsIter.hasNext(); ) {
    PLSQLargument outArg=outArgsIter.next();
    newIndex=outArg.databaseType.computeOutIndex(outArg,newIndex,outArgsIter);
  }
  for (  PLSQLargument outArg : outArguments) {
    if (outArg.cursorOutput) {
      super.useNamedCursorOutputAsResultSet(outArg.name);
    }
 else {
      DatabaseType type=outArg.databaseType;
      if (!type.isComplexDatabaseType()) {
        super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode());
      }
 else {
        ComplexDatabaseType complexType=(ComplexDatabaseType)type;
        if (outArg.outIndex != MIN_VALUE) {
          if (complexType instanceof OracleArrayType) {
            DatabaseType nestedType=((OracleArrayType)complexType).getNestedType();
            if (nestedType != null) {
              ObjectRelationalDatabaseField nestedField=new ObjectRelationalDatabaseField(outArg.name);
              nestedField.setSqlType(Types.STRUCT);
              if (nestedType.isComplexDatabaseType()) {
                ComplexDatabaseType complexNestedType=(ComplexDatabaseType)nestedType;
                nestedField.setType(complexNestedType.getJavaType());
                nestedField.setSqlTypeName(complexNestedType.getCompatibleType());
              }
              super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getTypeName(),complexType.getJavaType(),nestedField);
            }
 else {
              super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getTypeName(),complexType.getJavaType());
            }
          }
 else           if (complexType instanceof OracleObjectType) {
            super.addNamedOutputArgument(outArg.name,outArg.name,Types.STRUCT,complexType.getTypeName(),complexType.getJavaType());
          }
 else           if (complexType instanceof PLSQLCollection) {
            DatabaseType nestedType=((PLSQLCollection)complexType).getNestedType();
            if (nestedType != null) {
              ObjectRelationalDatabaseField nestedField=new ObjectRelationalDatabaseField(outArg.name);
              nestedField.setSqlType(nestedType.getConversionCode());
              if (nestedType.isComplexDatabaseType()) {
                ComplexDatabaseType complexNestedType=(ComplexDatabaseType)nestedType;
                nestedField.setType(complexNestedType.getJavaType());
                nestedField.setSqlTypeName(complexNestedType.getCompatibleType());
              }
              super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getCompatibleType(),complexType.getJavaType(),nestedField);
            }
 else {
              super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getCompatibleType());
            }
          }
 else           if (complexType.hasCompatibleType()) {
            super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode(),complexType.getCompatibleType(),complexType.getJavaType());
          }
 else {
            super.addNamedOutputArgument(outArg.name,outArg.name,type.getConversionCode());
          }
        }
      }
    }
  }
}