Skip to content

Commit c6267a7

Browse files
authored
Test case for Pattern.pattern and Pattern.toString (eisop#1590)
1 parent 9353961 commit c6267a7

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Test case for typetools issue #7539:
2+
// https://github.com/typetools/checker-framework/issues/7539
3+
4+
import java.util.regex.Matcher;
5+
import java.util.regex.Pattern;
6+
7+
public class PatternRegexes {
8+
void simple() {
9+
Pattern abc = Pattern.compile("abc");
10+
String str = abc.pattern();
11+
System.out.println("abc".replaceAll(str, ""));
12+
}
13+
14+
void complex(String content) {
15+
Pattern g2 = Pattern.compile("a(b*)(c*)");
16+
String strPattern = g2.pattern();
17+
Pattern g2Pattern = Pattern.compile(strPattern);
18+
Matcher matPattern = g2Pattern.matcher(content);
19+
20+
if (matPattern.matches()) {
21+
matPattern.group(2); // ok
22+
// :: error: (group.count.invalid)
23+
matPattern.group(3);
24+
}
25+
26+
String strToString = g2.toString();
27+
Pattern g2ToString = Pattern.compile(strToString);
28+
Matcher matToString = g2ToString.matcher(content);
29+
if (matToString.matches()) {
30+
matToString.group(2); // ok
31+
// :: error: (group.count.invalid)
32+
matToString.group(3);
33+
}
34+
}
35+
}

docs/CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@ instead.
8686

8787
**Closed issues:**
8888

89-
typetools#7096, eisop#1099, eisop#1219, eisop#1225, eisop#1231, eisop#1242,
90-
eisop#1247, eisop#1257, eisop#1263, eisop#1265, eisop#1272, eisop#1310,
91-
eisop#1326, eisop#1444, eisop#1448, eisop#1500, eisop#1506, eisop#1536,
92-
eisop#1543, eisop#1565.
89+
typetools#7096, typetools#7539, eisop#1099, eisop#1219, eisop#1225, eisop#1231,
90+
eisop#1242, eisop#1247, eisop#1257, eisop#1263, eisop#1265, eisop#1272,
91+
eisop#1310, eisop#1326, eisop#1444, eisop#1448, eisop#1500, eisop#1506,
92+
eisop#1536, eisop#1543, eisop#1565.
9393

9494

9595
Version 3.49.5 (June 30, 2025)

0 commit comments

Comments
 (0)