{"record":{"id":"48b7b3e7667c8b0f","repo":"pentaho/pentaho-kettle","slug":"randomcreditcardnumbbergenerator-unsupportedlength","errorCode":"RandomCreditCardNumbberGenerator.UnSupportedLength","errorMessage":"RandomCreditCardNumbberGenerator.UnSupportedLength","messagePattern":"RandomCreditCardNumbberGenerator\\.UnSupportedLength","errorType":"error_code","errorClass":"KettleException","httpStatus":null,"severity":"error","filePath":"plugins/random-cc-number-generator/impl/src/main/java/org/pentaho/di/trans/steps/randomccnumber/RandomCreditCardNumberGenerator.java","lineNumber":221,"sourceCode":"      int randomArrayIndex = (int) Math.floor( Math.random() * prefixList.length );\n      String ccnumber = prefixList[randomArrayIndex];\n      result.push( completed_number( ccnumber, length ) );\n    }\n\n    return result.toArray( new String[result.size()] );\n  }\n\n  private static void checkLength( int cardType, int size, int[] lengths ) throws KettleException {\n    if ( lengths.length == 0 ) {\n      return;\n    }\n    for ( int i = 0; i < lengths.length; i++ ) {\n      if ( size == lengths[i] ) {\n        // The size is supported for the card type\n        return;\n      }\n    }\n    throw new KettleException( BaseMessages\n      .getString(\n        PKG, \"RandomCreditCardNumbberGenerator.UnSupportedLength\", String.valueOf( size ),\n        getCardName( cardType ) ) );\n  }\n\n  public static String[] GenerateCreditCardNumbers( int cardType, int size, int howMany ) throws KettleException {\n    String[] cards = null;\n    switch ( cardType ) {\n      case CARD_TYPE_MASTERCARD:\n        checkLength( cardType, size, MASTERCARD_LENGTH_LIST );\n        cards = credit_card_number( MASTERCARD_PREFIX_LIST, size, howMany );\n        break;\n      case CARD_TYPE_AMEX:\n        checkLength( cardType, size, AMEX_LENGTH_LIST );\n        cards = credit_card_number( AMEX_PREFIX_LIST, size, howMany );\n        break;\n      case CARD_TYPE_DINERS:\n        checkLength( cardType, size, DINERS_LENGTH_LIST );","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/pentaho/pentaho-kettle/blob/f3058517a153da500bf4551f46d79b91bf8ec552/plugins/random-cc-number-generator/impl/src/main/java/org/pentaho/di/trans/steps/randomccnumber/RandomCreditCardNumberGenerator.java#L203-L239","documentation":"checkLength verifies that the requested card number size is in the supported length list for the given card type; if not, it throws a KettleException with this localized message naming the size and card name. Credit card numbers must match fixed lengths (e.g. Visa 16, Amex 15) to be valid.","triggerScenarios":"GenerateCreditCardNumbers(cardType, size, howMany) is called with a size that is not in the card type's LENGTH_LIST, e.g. size=10 for Visa or a negative/zero size from a misconfigured field.","commonSituations":"User types an arbitrary card length in the step dialog; card length read from a field/variable evaluates to an unexpected value; changing card type without updating the length.","solutions":["Set the card size to a supported length for the selected card type (Visa 13/16, Amex 15, MasterCard 16, etc.)","Align the card type and size settings — pick the type first, then one of its allowed lengths","If size comes from a field/variable, log its resolved value and correct it","Add validation in the step dialog to restrict the size field to the selected type's lengths"],"exampleFix":"// before\ngenerator.generate(CARD_TYPE_VISA, 10, 100); // 10 unsupported\n// after\ngenerator.generate(CARD_TYPE_VISA, 16, 100);","handlingStrategy":"validation","validationCode":"// Java — validate size before generating\nboolean supported = false;\nfor ( int len : RandomCreditCardNumberGenerator.VISA_LENGTH_LIST ) {\n  if ( len == size ) { supported = true; break; }\n}\nif ( !supported ) throw new IllegalArgumentException( \"Size \" + size + \" unsupported for card type\" );","typeGuard":null,"tryCatchPattern":"try {\n  String[] cards = RandomCreditCardNumberGenerator.GenerateCreditCardNumbers( type, size, n );\n} catch ( KettleException e ) {\n  logError( \"Unsupported length/card type combo: \" + e.getMessage() );\n}","preventionTips":["Map card types to their legal lengths in UI or caller code","Log resolved variable/field values feeding the size","Use dropdowns limited to valid lengths instead of free-text"],"tags":["validation","credit-card","range"],"backgroundTag":"value-out-of-range","analyzedSha":"f3058517a153da500bf4551f46d79b91bf8ec552","analyzedAt":"2026-09-13T14:04:16.340Z","contentChangedAt":"2026-09-13T14:04:16.340Z","schemaVersion":2},"datasetVersion":"2026-09-20T23:17:15.980Z"}