Skip to content

Commit 1e1cf5e

Browse files
committed
Fixed exception being thrown in Java 7 for valid MSI bar codes.
1 parent ba96033 commit 1e1cf5e

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeMSI.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,13 +329,11 @@ public static int getChecksum(String text) {
329329
if (text == null) {
330330
throw new IllegalArgumentException("Valid code required to generate checksum for MSI barcode");
331331
}
332-
String[] strArray = text.split("");
333-
int[] digits = new int[strArray.length];
334-
for (int i = 0; i < strArray.length; i++) {
335-
try {
336-
digits[i] = Integer.parseInt(strArray[i]);
337-
} catch (NumberFormatException e) {
338-
throw new IllegalArgumentException("The character " + text.charAt(i) + " is illegal in MSI bar codes.");
332+
int[] digits = new int[text.length()];
333+
for (int x = 0; x < text.length(); x++) {
334+
digits[x] = (int)(text.charAt(x) - '0');
335+
if (digits[x] < 0 || digits[x] > 9) {
336+
throw new IllegalArgumentException("The character " + text.charAt(x) + " is illegal in MSI bar codes.");
339337
}
340338
}
341339
int sum = 0;

0 commit comments

Comments
 (0)