diff --git a/AUTHORS b/AUTHORS index 0b4bdf753..aeda95fcc 100644 --- a/AUTHORS +++ b/AUTHORS @@ -53,6 +53,7 @@ Isaac Potoczny-Jones Ivan Poliakov Jacob Haynes (Google) Jeff Breidenbach (Google) +jjYBdx4IL Joan Montané (Softcatalà.cat) John Connolly (Bug Labs) Jonas Petersson (Prisjakt) diff --git a/core/src/main/java/com/google/zxing/ReaderException.java b/core/src/main/java/com/google/zxing/ReaderException.java index 871a0d98d..2253d657d 100644 --- a/core/src/main/java/com/google/zxing/ReaderException.java +++ b/core/src/main/java/com/google/zxing/ReaderException.java @@ -33,7 +33,7 @@ public abstract class ReaderException extends Exception { } ReaderException(Throwable cause) { - super(cause); + super(cause); } // Prevent stack traces from being taken diff --git a/core/src/main/java/com/google/zxing/common/BitMatrix.java b/core/src/main/java/com/google/zxing/common/BitMatrix.java index c3004a0d0..1a3bba8f4 100755 --- a/core/src/main/java/com/google/zxing/common/BitMatrix.java +++ b/core/src/main/java/com/google/zxing/common/BitMatrix.java @@ -63,7 +63,6 @@ public final class BitMatrix implements Cloneable { } public static BitMatrix parse(String stringRepresentation, String setString, String unsetString) { - int pos = 0; if (stringRepresentation == null) { throw new IllegalArgumentException(); } @@ -73,8 +72,10 @@ public final class BitMatrix implements Cloneable { int rowStartPos = 0; int rowLength = -1; int nRows = 0; + int pos = 0; while (pos < stringRepresentation.length()) { - if (stringRepresentation.substring(pos, pos + 1).equals("\n") || stringRepresentation.substring(pos, pos + 1).equals("\r")) { + if (stringRepresentation.charAt(pos) == '\n' || + stringRepresentation.charAt(pos) == '\r') { if (bitsPos > rowStartPos) { if(rowLength == -1) { rowLength = bitsPos - rowStartPos; @@ -97,7 +98,8 @@ public final class BitMatrix implements Cloneable { bits[bitsPos] = false; bitsPos++; } else { - throw new IllegalArgumentException("illegal character encountered: " + stringRepresentation.substring(pos)); + throw new IllegalArgumentException( + "illegal character encountered: " + stringRepresentation.substring(pos)); } } @@ -105,15 +107,14 @@ public final class BitMatrix implements Cloneable { if (bitsPos > rowStartPos) { if(rowLength == -1) { rowLength = bitsPos - rowStartPos; - } - else if (bitsPos - rowStartPos != rowLength) { + } else if (bitsPos - rowStartPos != rowLength) { throw new IllegalArgumentException("row lengths do not match"); } nRows++; } BitMatrix matrix = new BitMatrix(rowLength, nRows); - for (int i=0; iXOR for {@link BitMatrix}.

- * Flip the bit in this {@link BitMatrix} if the corresponding mask bit is set. + * Exclusive-or (XOR): Flip the bit in this {@code BitMatrix} if the corresponding + * mask bit is set. * - * @param mask + * @param mask XOR mask */ public void xor(BitMatrix mask) { if (width != mask.getWidth() || height != mask.getHeight() || rowSize != mask.getRowSize()) { throw new IllegalArgumentException("input matrix dimensions do not match"); } - BitArray rowArray = new BitArray(width/32+1); + BitArray rowArray = new BitArray(width / 32 + 1); for (int y = 0; y < height; y++) { int offset = y * rowSize; int[] row = mask.getRow(y, rowArray).getBitArray(); diff --git a/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java b/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java index 1babafc13..2df4f202f 100644 --- a/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java +++ b/core/src/test/java/com/google/zxing/aztec/decoder/DecoderTest.java @@ -19,11 +19,9 @@ import com.google.zxing.FormatException; import com.google.zxing.ResultPoint; import com.google.zxing.aztec.AztecDetectorResult; import com.google.zxing.common.BitMatrix; -import com.google.zxing.common.DecoderResult; import org.junit.Test; -import static org.junit.Assert.*; -public class DecoderTest { +public final class DecoderTest { private static final ResultPoint[] NO_POINTS = new ResultPoint[0]; @@ -36,8 +34,8 @@ public class DecoderTest { * at com.google.zxing.aztec.decoder.Decoder.decode(Decoder.java:77) * at com.google.zxing.aztec.decoder.DecoderTest.testDecodeBug1(DecoderTest.java:66) */ - @Test - public void testDecodeTooManyErrors() { + @Test(expected = FormatException.class) + public void testDecodeTooManyErrors() throws FormatException { BitMatrix matrix = BitMatrix.parse("" + "X X . X . . . X X . . . X . . X X X . X . X X X X X . \n" + "X X . . X X . . . . . X X . . . X X . . . X . X . . X \n" @@ -68,15 +66,11 @@ public class DecoderTest { + "X X . X . X . . . X . X . . . . X X . X . . X X . . . \n", "X ", ". "); AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4); - try { - DecoderResult res = new Decoder().decode(r); - fail(); - } catch (FormatException ex) { - } + new Decoder().decode(r); } - @Test - public void testDecodeTooManyErrors2() { + @Test(expected = FormatException.class) + public void testDecodeTooManyErrors2() throws FormatException { BitMatrix matrix = BitMatrix.parse("" + ". X X . . X . X X . . . X . . X X X . . . X X . X X . \n" + "X X . X X . . X . . . X X . . . X X . X X X . X . X X \n" @@ -107,11 +101,7 @@ public class DecoderTest { + "X X . . . X X . . X . X . . . . X X . X . . X . X . X \n", "X ", ". "); AztecDetectorResult r = new AztecDetectorResult(matrix, NO_POINTS, true, 16, 4); - try { - DecoderResult res = new Decoder().decode(r); - fail(); - } catch (FormatException ex) { - } + new Decoder().decode(r); } } diff --git a/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java b/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java index aaf45e2ae..5331ad14b 100644 --- a/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java +++ b/core/src/test/java/com/google/zxing/aztec/encoder/EncoderTest.java @@ -27,17 +27,14 @@ import com.google.zxing.common.BitArray; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.DecoderResult; import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.security.SecureRandom; import java.util.EnumMap; import java.util.Map; import java.util.Random; import java.util.regex.Pattern; -import org.junit.Before; /** * Aztec 2D generator unit tests. @@ -49,12 +46,6 @@ public final class EncoderTest extends Assert { private static final Pattern DOTX = Pattern.compile("[^.X]"); private static final ResultPoint[] NO_POINTS = new ResultPoint[0]; - private static Random random; - - @Before - public void beforeTest() { - random = new Random(0); - } // real life tests @@ -513,7 +504,7 @@ public final class EncoderTest extends Assert { } private static Random getPseudoRandom() { - return random; + return new Random(0xDEADBEEF); } private static void testModeMessage(boolean compact, int layers, int words, String expected) { diff --git a/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java b/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java index 872188c09..e86406dd9 100644 --- a/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java +++ b/core/src/test/java/com/google/zxing/common/BitArrayTestCase.java @@ -101,7 +101,7 @@ public final class BitArrayTestCase extends Assert { @Test public void testGetNextSet5() { - Random r = new SecureRandom(new byte[] {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF}); + Random r = new Random(0xDEADBEEF); for (int i = 0; i < 10; i++) { BitArray array = new BitArray(1 + r.nextInt(100)); int numSet = r.nextInt(20); diff --git a/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java b/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java index 60cd3f93b..0b43278b2 100644 --- a/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java +++ b/core/src/test/java/com/google/zxing/common/BitMatrixTestCase.java @@ -173,7 +173,9 @@ public final class BitMatrixTestCase extends Assert { try { assertEquals(centerMatrix, BitMatrix.parse(" \n xy\n \n", "x", " ")); fail(); - } catch (IllegalArgumentException ex) {} + } catch (IllegalArgumentException ex) { + // good + } assertEquals(emptyMatrix24, BitMatrix.parse(" \n \n \n \n", "x", " ")); @@ -222,12 +224,16 @@ public final class BitMatrixTestCase extends Assert { try { emptyMatrix.clone().xor(badMatrix); fail(); - } catch(IllegalArgumentException ex) {} + } catch(IllegalArgumentException ex) { + // good + } try { badMatrix.clone().xor(emptyMatrix); fail(); - } catch(IllegalArgumentException ex) {} + } catch(IllegalArgumentException ex) { + // good + } } private static void testXOR(BitMatrix dataMatrix, BitMatrix flipMatrix, BitMatrix expectedMatrix) { diff --git a/core/src/test/java/com/google/zxing/common/reedsolomon/ReedSolomonTestCase.java b/core/src/test/java/com/google/zxing/common/reedsolomon/ReedSolomonTestCase.java index f86d35efa..0e85564dd 100644 --- a/core/src/test/java/com/google/zxing/common/reedsolomon/ReedSolomonTestCase.java +++ b/core/src/test/java/com/google/zxing/common/reedsolomon/ReedSolomonTestCase.java @@ -501,7 +501,7 @@ public final class ReedSolomonTestCase extends Assert { } private static Random getPseudoRandom() { - return new SecureRandom(new byte[] {(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF}); + return new Random(0xDEADBEEF); } } \ No newline at end of file diff --git a/core/src/test/java/com/google/zxing/pdf417/decoder/ec/AbstractErrorCorrectionTestCase.java b/core/src/test/java/com/google/zxing/pdf417/decoder/ec/AbstractErrorCorrectionTestCase.java index 06d7221c4..b017f6130 100644 --- a/core/src/test/java/com/google/zxing/pdf417/decoder/ec/AbstractErrorCorrectionTestCase.java +++ b/core/src/test/java/com/google/zxing/pdf417/decoder/ec/AbstractErrorCorrectionTestCase.java @@ -49,7 +49,7 @@ abstract class AbstractErrorCorrectionTestCase extends Assert { } static Random getRandom() { - return new Random(0); + return new Random(0xDEADBEEF); } } \ No newline at end of file