Skip to content

Commit 40e8243

Browse files
committed
Remove Interval internal cache
The cache is not thread safe, but it was used in the multithreaded context, making it possible for the `Interval.of` method to return invalid values. Signed-off-by: lukasz-stec <[email protected]>
1 parent 857fb46 commit 40e8243

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

runtime/Java/src/org/antlr/v4/runtime/misc/Interval.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,8 @@
77

88
/** An immutable inclusive interval a..b */
99
public class Interval {
10-
public static final int INTERVAL_POOL_MAX_VALUE = 1000;
11-
1210
public static final Interval INVALID = new Interval(-1,-2);
1311

14-
static final Interval[] cache = new Interval[INTERVAL_POOL_MAX_VALUE+1];
15-
1612
public int a;
1713
public int b;
1814

@@ -25,14 +21,7 @@ public class Interval {
2521
* have a..a (set with 1 element).
2622
*/
2723
public static Interval of(int a, int b) {
28-
// cache just a..a
29-
if ( a!=b || a<0 || a>INTERVAL_POOL_MAX_VALUE ) {
30-
return new Interval(a,b);
31-
}
32-
if ( cache[a]==null ) {
33-
cache[a] = new Interval(a,a);
34-
}
35-
return cache[a];
24+
return new Interval(a,b);
3625
}
3726

3827
/** return number of elements between a and b inclusively. x..x is length 1.

0 commit comments

Comments
 (0)