jlcout / epctagcoder

Java library for RFID EPC encode / decode
https://jlcout.github.io/epctagcoder
Apache License 2.0
51 stars 31 forks source link

SGTIN - java.lang.StringIndexOutOfBoundsException: String index out of range: 12 #1

Closed jlcout closed 7 years ago

jlcout commented 7 years ago

I was trying out different EPCs and ran into an error. If the checkdigit=0, then code was throwing an error on out of bounds. After troubleshooting it I noticed it was happening on the calculation of the check digit and found it was caused by the value of item reference not having enough digits. The leading 0's from item reference were getting dropped. I noticed you had a function to fill those, so I tried it and it fixed issue. After this line String itemReferenceWithExtensionDec = Converter.binToDec(itemReferenceWithExtensionBin); I added this
itemReferenceWithExtensionDec = Converter.strZero(itemReferenceWithExtensionDec, tableItem.getDigits());

Nervin

jlcout commented 7 years ago

Thanks Nervin, your fix was added