barend / java-iban

An Apache licensed, immutable Java value type for IBAN's.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exception when composing IBANs where the check digits have a leading zero

trustlydaniel opened this issue · comments

Check digits can have leading zeroes, Modulo97#calculateCheckDigits returns an int so the value needs to be left padded if size is less than two.

Example (IBAN in example is generated, not a real bank account):

public class CheckDigitsLeadingZeroExample {

  public static void main(String[] args) {
    String bban = "50516227620311";
    IBAN iban = IBAN.compose("DK", bban);
    //Expected iban: DK0350516227620311
    //throws: Input failed length validation: found 17, but expect 18 for country code.

    String input = "DK0050516227620311";
    int checkDigits = Modulo97.calculateCheckDigits(input);
    // checkDigits is 3
  }

}

Hi @trustlydaniel,

Thanks! That's a good catch. The error is quite glaring once you see it, but I have missed it all these years 😬

Thanks also for providing #93 to fix it. Much appreciated.

Cheers,
Barend