Skip to content

Commit 7c99b33

Browse files
Set buggy String.replace support to notModelled
1 parent 3712b2d commit 7c99b33

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

src/main/java/java/lang/String.java

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2968,32 +2968,13 @@ public String replaceFirst(String regex, String replacement) {
29682968
* @since 1.4
29692969
* @spec JSR-51
29702970
*
2971-
* @diffblue.limitedSupport
2972-
* We enforce the regex argument is a string literal without any special
2973-
* characters used in regular expressions:
2974-
* '[', ']','.', '\\', '?', '^', '$', '*', '+', '{', '}', '|', '(', ')',
2975-
* hence PatternSyntaxException will never be thrown.
2971+
* @diffblue.noSupport
29762972
*/
29772973
public String replaceAll(String regex, String replacement)
29782974
{
2975+
CProver.notModelled();
2976+
return CProver.nondetWithNullForNotModelled();
29792977
// return Pattern.compile(regex).matcher(this).replaceAll(replacement);
2980-
// DIFFBLUE MODELS LIBRARY: we assume the expression is just a string literal
2981-
CProver.assume(
2982-
regex.indexOf('[') == -1 &&
2983-
regex.indexOf(']') == -1 &&
2984-
regex.indexOf('.') == -1 &&
2985-
regex.indexOf('\\') == -1 &&
2986-
regex.indexOf('?') == -1 &&
2987-
regex.indexOf('^') == -1 &&
2988-
regex.indexOf('$') == -1 &&
2989-
regex.indexOf('*') == -1 &&
2990-
regex.indexOf('+') == -1 &&
2991-
regex.indexOf('{') == -1 &&
2992-
regex.indexOf('}') == -1 &&
2993-
regex.indexOf('|') == -1 &&
2994-
regex.indexOf('(') == -1 &&
2995-
regex.indexOf(')') == -1);
2996-
return replace(regex, replacement);
29972978
}
29982979

29992980
/**
@@ -3008,14 +2989,10 @@ public String replaceAll(String regex, String replacement)
30082989
* @return The resulting string
30092990
* @since 1.5
30102991
*
3011-
* @diffblue.limitedSupport
3012-
* Only works for arguments that are constant strings with only 1 character.
3013-
* For instance, we can generate tests for s.replace("a", "b") but not
3014-
* s.replace("a", "bc") or s.replace(arg, "b").
3015-
* @diffblue.untested
2992+
* @diffblue.noSupport
30162993
*/
30172994
public String replace(CharSequence target, CharSequence replacement) {
3018-
// DIFFBLUE MODEL LIBRARY This is treated internally in CBMC
2995+
CProver.notModelled();
30192996
return CProver.nondetWithNullForNotModelled();
30202997
// return Pattern.compile(target.toString(), Pattern.LITERAL).matcher(
30212998
// this).replaceAll(Matcher.quoteReplacement(replacement.toString()));

0 commit comments

Comments
 (0)