marcwrobel / jbanking

A Java banking API
Apache License 2.0
108 stars 56 forks source link

`isValid()` throws IllegalArgumentException: "the check digit cannot be one of 00, 01 or 99" #183

Closed aSemy closed 2 years ago

aSemy commented 2 years ago

Describe the bug

When I use Iban.isValid() it throws an exception when the IBAN is invalid.

I expect that it does not throw an exception, as per the Javadoc

https://github.com/marcwrobel/jbanking/blob/657cabe29dad16ba7251e793e1b2da6a9598e978/src/main/java/fr/marcwrobel/jbanking/iban/Iban.java#L144-L153

To Reproduce

I was using the test data from Apache Commons Validator https://github.com/apache/commons-validator/blob/fe3a76cc3452ec4a3a034aca7c05bcd103390c52/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java

import fr.marcwrobel.jbanking.iban.Iban
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Test

class IbanTest {
    @Test
    fun `verify invalid IBAN is invalid`() {
        assertFalse(Iban.isValid("BY00NBRB3600000000000Z00AB00"))
    }
}

Expected behavior

If an IBAN is invalid then Iban.isValid() returns false and does not throw an exception.

Alternatively, if Iban.isValid() must throw an exception, then this is documented in the Javadoc.

Context:

marcwrobel commented 2 years ago

Hi @aSemy, thanks for reporting this bug. It will be fixed in 4.0.0.

marcwrobel commented 2 years ago

This issue relates to #82. Not sure why I choose to raise an exception instead of simply returning false. Maybe because those check digits are not supposed to be possible.

marcwrobel commented 2 years ago

@aSemy, the bug has been fixed in 4.0.0. But I am still far from releasing this version, so if it's important to you let me know and I will backport the fix to 3.x.

aSemy commented 2 years ago

Thanks! There's no rush, I've wrapped it in a try/catch block for now.

marcwrobel commented 2 years ago

OK, this will wait until the 4.0.0 is released then. Thanks again for reporting this bug !