Skip to content

Commit 8a5dd47

Browse files
committed
bail and use logger
1 parent a6bbce3 commit 8a5dd47

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

iabgpp-encoder/src/main/java/com/iab/gpp/encoder/datatype/encoder/FibonacciIntegerRangeEncoder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import java.util.ArrayList;
44
import java.util.Collections;
55
import java.util.List;
6+
import java.util.logging.Logger;
67
import java.util.regex.Pattern;
78
import com.iab.gpp.encoder.error.DecodingException;
89

910
public class FibonacciIntegerRangeEncoder {
1011

12+
private static final Logger LOGGER = Logger.getLogger(FibonacciIntegerRangeEncoder.class.getName());
1113
// NOTE: This is a value roughly the 2x the size of this list
1214
// https://tools.iabtechlab.com/transparencycenter/explorer/business/gpp
1315
static final int MAX_SIZE = 8192;
@@ -74,7 +76,8 @@ public static List<Integer> decode(String bitString) throws DecodingException {
7476
startIndex = index + 2;
7577

7678
if (value.size() + (end - start) > MAX_SIZE) {
77-
throw new DecodingException("FibonacciIntegerRange has too many values");
79+
LOGGER.warning("FibonacciIntegerRange has too many values");
80+
break;
7881
}
7982
for (int j = start; j <= end; j++) {
8083
value.add(j);
@@ -84,7 +87,8 @@ public static List<Integer> decode(String bitString) throws DecodingException {
8487
int val = FibonacciIntegerEncoder.decode(bitString.substring(startIndex, index + 2)) + offset;
8588
offset = val;
8689
if (value.size() == MAX_SIZE) {
87-
throw new DecodingException("FibonacciIntegerRange has too many values");
90+
LOGGER.warning("FibonacciIntegerRange has too many values");
91+
break;
8892
}
8993
value.add(val);
9094
startIndex = index + 2;

iabgpp-encoder/src/main/java/com/iab/gpp/encoder/datatype/encoder/FixedIntegerRangeEncoder.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import java.util.ArrayList;
44
import java.util.Collections;
55
import java.util.List;
6+
import java.util.logging.Logger;
67
import java.util.regex.Pattern;
78
import com.iab.gpp.encoder.error.DecodingException;
89

910
public class FixedIntegerRangeEncoder {
1011

12+
private static final Logger LOGGER = Logger.getLogger(FixedIntegerRangeEncoder.class.getName());
1113
// NOTE: This is a value roughly the 2x the size of this list
1214
// https://tools.iabtechlab.com/transparencycenter/explorer/business/gpp
1315
private static final int MAX_SIZE = 8192;
@@ -65,15 +67,17 @@ public static List<Integer> decode(String bitString) throws DecodingException {
6567
throw new DecodingException("FixedIntegerRange has invalid range");
6668
}
6769
if (value.size() + (end - start) > MAX_SIZE) {
68-
throw new DecodingException("FixedIntegerRange has too many values");
70+
LOGGER.warning("FixedIntegerRange has too many values");
71+
break;
6972
}
7073
for (int j = start; j <= end; j++) {
7174
value.add(j);
7275
}
7376
} else {
7477
int val = FixedIntegerEncoder.decode(bitString.substring(startIndex, startIndex + 16));
7578
if (value.size() == MAX_SIZE) {
76-
throw new DecodingException("FixedIntegerRange has too many values");
79+
LOGGER.warning("FixedIntegerRange has too many values");
80+
break;
7781
}
7882
value.add(val);
7983
startIndex += 16;

iabgpp-encoder/src/test/java/com/iab/gpp/encoder/datatype/encoder/FibonacciIntegerRangeEncoderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertThrows;
44
import java.util.ArrayList;
55
import java.util.Arrays;
6+
import java.util.List;
67
import org.junit.jupiter.api.Assertions;
78
import org.junit.jupiter.api.Test;
89
import com.iab.gpp.encoder.error.DecodingException;
@@ -101,7 +102,6 @@ public void testDecode8() {
101102
@Test
102103
public void testGiantRange() {
103104
String max = FibonacciIntegerEncoder.encode(FibonacciIntegerRangeEncoder.MAX_SIZE + 1);
104-
assertThrows(DecodingException.class, ()->
105-
FibonacciIntegerRangeEncoder.decode("000000000001111" + max));
105+
Assertions.assertEquals(List.of(), FibonacciIntegerRangeEncoder.decode("000000000001111" + max));
106106
}
107107
}

iabgpp-encoder/src/test/java/com/iab/gpp/encoder/datatype/encoder/FixedIntegerRangeEncoderTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static org.junit.jupiter.api.Assertions.assertThrows;
44
import java.util.ArrayList;
55
import java.util.Arrays;
6+
import java.util.List;
67
import org.junit.jupiter.api.Assertions;
78
import org.junit.jupiter.api.Test;
89
import com.iab.gpp.encoder.error.DecodingException;
@@ -131,7 +132,6 @@ public void testDecode10() {
131132
@Test
132133
public void testGiantRange() {
133134
String max = FibonacciIntegerEncoder.encode(FibonacciIntegerRangeEncoder.MAX_SIZE + 1);
134-
assertThrows(DecodingException.class, ()->
135-
FixedIntegerRangeEncoder.decode("00000000000110000000000000001" + max));
135+
Assertions.assertEquals(List.of(), FixedIntegerRangeEncoder.decode("00000000000110000000000000001" + max));
136136
}
137137
}

0 commit comments

Comments
 (0)