RegExp.parseRepeatExp is not fully checked.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 1.4k
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 88
Description
### Description
parseRepeatExp has the following code:
final RegExp parseRepeatExp() throws IllegalArgumentException {
..
if (start == pos) throw new IllegalArgumentException("integer expected at position " + pos);
if (start != pos) m = Integer.parseInt(originalString.substring(start, pos));
...
}
Integer.parseInt(originalString.substring(start, pos)) can throw NumberFormatException, but not IllegalArgumentException. Please note that the above statement throws IllegalArgumentException.
Indeed, in the same class, another method rethrow IllegalArgumentException as follows:
final RegExp parseSimpleExp() throws IllegalArgumentException {
...
try {
if (i == 0 || i == s.length() - 1 || i != s.lastIndexOf('-'))
throw new NumberFormatException();
String smin = s.substring(0, i);
String smax = s.substring(i + 1, s.length());
int imin = Integer.parseInt(smin);
int imax = Integer.parseInt(smax);
int digits;
if (smin.length() == smax.length()) digits = smin.length();
else digits = 0;
if (imin > imax) {
int t = imin;
imin = imax;
imax = t;
}
return makeInterval(flags, imin, imax, digits);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("interval syntax error at position " + (pos - 1), e);
}
}
It can be better for parseRepeatExp to rethrow IllegalArgumentException. Can this problem be fixed?
### Version and environment details
_No response_
Contributor guide
Research direction
Start at RegExp.parseRepeatExp and compare its integer parsing with the rethrow behavior shown for parseSimpleExp. Confirm the expected exception type and message for an invalid repeat expression, then add coverage for that case and run the relevant Lucene tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- search
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100