Skip to content

Commit 3241fe6

Browse files
authored
Side-effect annotations
1 parent cb6bce1 commit 3241fe6

39 files changed

Lines changed: 59 additions & 67 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ merge conflicts.)
159159
```sh
160160
cd jdk21u
161161
git pull && \
162+
git pull ../jdk && \
162163
git pull https://github.com/openjdk/jdk21u.git && \
163164
git pull https://github.com/typetools/jdk.git
164165
```

src/java.base/share/classes/java/lang/AbstractStringBuilder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.checkerframework.checker.nullness.qual.Nullable;
3636
import org.checkerframework.dataflow.qual.Pure;
3737
import org.checkerframework.dataflow.qual.SideEffectFree;
38+
import org.checkerframework.dataflow.qual.SideEffectsOnly;
3839
import org.checkerframework.framework.qual.AnnotatedFor;
3940

4041
import jdk.internal.math.DoubleToDecimal;
@@ -521,6 +522,7 @@ public int codePointBefore(@Positive int index) {
521522
* {@code dst.length}
522523
* </ul>
523524
*/
525+
@SideEffectsOnly("#3")
524526
public void getChars(@NonNegative int srcBegin, @NonNegative int srcEnd, char[] dst, @IndexOrHigh({"#3"}) int dstBegin)
525527
{
526528
Preconditions.checkFromToIndex(srcBegin, srcEnd, count, Preconditions.SIOOBE_FORMATTER); // compatible to old version

src/java.base/share/classes/java/lang/String.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.checkerframework.common.value.qual.StringVal;
5757
import org.checkerframework.dataflow.qual.Pure;
5858
import org.checkerframework.dataflow.qual.SideEffectFree;
59+
import org.checkerframework.dataflow.qual.SideEffectsOnly;
5960
import org.checkerframework.framework.qual.AnnotatedFor;
6061
import org.checkerframework.framework.qual.CFComment;
6162

@@ -1787,6 +1788,7 @@ public int codePointBefore(@LTEqLengthOf({"this"}) @Positive int index) {
17871788
* <li>{@code dstBegin+(srcEnd-srcBegin)} is larger than
17881789
* {@code dst.length}</ul>
17891790
*/
1791+
@SideEffectsOnly("#3")
17901792
public void getChars(@IndexOrHigh({"this"}) int srcBegin, @IndexOrHigh({"this"}) int srcEnd, char @GuardSatisfied [] dst, @IndexOrHigh({"#3"}) int dstBegin) {
17911793
checkBoundsBeginEnd(srcBegin, srcEnd, length());
17921794
checkBoundsOffCount(dstBegin, srcEnd - srcBegin, dst.length);
@@ -2174,6 +2176,7 @@ private static class CaseInsensitiveComparator
21742176
@java.io.Serial
21752177
private static final long serialVersionUID = 8575799808933029326L;
21762178

2179+
@Pure
21772180
public int compare(String s1, String s2) {
21782181
byte[] v1 = s1.value;
21792182
byte[] v2 = s2.value;
@@ -2617,6 +2620,7 @@ public int hashCode() {
26172620
* {@code endIndex}.
26182621
* @since 21
26192622
*/
2623+
@Pure
26202624
public int indexOf(int ch, int beginIndex, int endIndex) {
26212625
checkBoundsBeginEnd(beginIndex, endIndex, length());
26222626
return isLatin1() ? StringLatin1.indexOf(value, ch, beginIndex, endIndex)
@@ -2781,6 +2785,7 @@ public int indexOf(int ch, int beginIndex, int endIndex) {
27812785
* {@code endIndex}.
27822786
* @since 21
27832787
*/
2788+
@Pure
27842789
public int indexOf(String str, int beginIndex, int endIndex) {
27852790
if (str.length() == 1) {
27862791
/* Simple optimization, can be omitted without behavioral impact */
@@ -3474,6 +3479,7 @@ public String replace(@GuardSatisfied CharSequence target, @GuardSatisfied CharS
34743479
*
34753480
* @since 21
34763481
*/
3482+
@SideEffectFree
34773483
public String[] splitWithDelimiters(String regex, int limit) {
34783484
return split(regex, limit, true);
34793485
}
@@ -4094,6 +4100,7 @@ public boolean isBlank() {
40944100
*
40954101
* @since 11
40964102
*/
4103+
@SideEffectFree
40974104
public Stream<String> lines() {
40984105
return isLatin1() ? StringLatin1.lines(value) : StringUTF16.lines(value);
40994106
}
@@ -4491,6 +4498,7 @@ public <R> R transform(Function<? super String, ? extends R> f) {
44914498
* @return an IntStream of char values from this sequence
44924499
* @since 9
44934500
*/
4501+
@SideEffectFree
44944502
@Override
44954503
public IntStream chars() {
44964504
return StreamSupport.intStream(
@@ -4511,6 +4519,7 @@ public IntStream chars() {
45114519
* @return an IntStream of Unicode code points from this sequence
45124520
* @since 9
45134521
*/
4522+
@SideEffectFree
45144523
@Override
45154524
public IntStream codePoints() {
45164525
return StreamSupport.intStream(
@@ -5113,6 +5122,7 @@ static String valueOfCodePoint(int codePoint) {
51135122
* @return an {@link Optional} describing the {@linkplain String} instance
51145123
* @since 12
51155124
*/
5125+
@SideEffectFree
51165126
@Override
51175127
public Optional<String> describeConstable() {
51185128
return Optional.of(this);
@@ -5126,6 +5136,7 @@ public Optional<String> describeConstable() {
51265136
* @return the {@linkplain String} instance
51275137
* @since 12
51285138
*/
5139+
@Pure
51295140
@Override
51305141
public String resolveConstantDesc(MethodHandles.Lookup lookup) {
51315142
return this;

src/java.base/share/classes/java/lang/StringBuffer.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.checkerframework.common.aliasing.qual.Unique;
3636
import org.checkerframework.dataflow.qual.Pure;
3737
import org.checkerframework.dataflow.qual.SideEffectFree;
38+
import org.checkerframework.dataflow.qual.SideEffectsOnly;
3839
import org.checkerframework.framework.qual.AnnotatedFor;
3940

4041
import java.io.IOException;
@@ -208,6 +209,7 @@ public final class StringBuffer
208209
*
209210
* @since 11
210211
*/
212+
@SideEffectFree
211213
@Override
212214
public synchronized int compareTo(StringBuffer another) {
213215
return super.compareTo(another);
@@ -219,6 +221,7 @@ public synchronized int compareTo(StringBuffer another) {
219221
return count;
220222
}
221223

224+
@Pure
222225
@Override
223226
public synchronized @NonNegative int capacity() {
224227
return super.capacity();
@@ -252,6 +255,7 @@ public synchronized void setLength(@NonNegative int newLength) {
252255
* @throws IndexOutOfBoundsException {@inheritDoc}
253256
* @see #length()
254257
*/
258+
@Pure
255259
@Override
256260
public synchronized char charAt(int index) {
257261
return super.charAt(index);
@@ -261,6 +265,7 @@ public synchronized char charAt(int index) {
261265
* @throws IndexOutOfBoundsException {@inheritDoc}
262266
* @since 1.5
263267
*/
268+
@Pure
264269
@Override
265270
public synchronized int codePointAt(int index) {
266271
return super.codePointAt(index);
@@ -270,6 +275,7 @@ public synchronized int codePointAt(int index) {
270275
* @throws IndexOutOfBoundsException {@inheritDoc}
271276
* @since 1.5
272277
*/
278+
@Pure
273279
@Override
274280
public synchronized int codePointBefore(int index) {
275281
return super.codePointBefore(index);
@@ -279,6 +285,7 @@ public synchronized int codePointBefore(int index) {
279285
* @throws IndexOutOfBoundsException {@inheritDoc}
280286
* @since 1.5
281287
*/
288+
@Pure
282289
@Override
283290
public synchronized int codePointCount(int beginIndex, int endIndex) {
284291
return super.codePointCount(beginIndex, endIndex);
@@ -288,6 +295,7 @@ public synchronized int codePointCount(int beginIndex, int endIndex) {
288295
* @throws IndexOutOfBoundsException {@inheritDoc}
289296
* @since 1.5
290297
*/
298+
@Pure
291299
@Override
292300
public synchronized int offsetByCodePoints(int index, int codePointOffset) {
293301
return super.offsetByCodePoints(index, codePointOffset);
@@ -296,6 +304,7 @@ public synchronized int offsetByCodePoints(int index, int codePointOffset) {
296304
/**
297305
* @throws IndexOutOfBoundsException {@inheritDoc}
298306
*/
307+
@SideEffectsOnly("#3")
299308
@Override
300309
public synchronized void getChars(int srcBegin, int srcEnd, char[] dst,
301310
@IndexOrHigh({"#3"}) int dstBegin)
@@ -516,6 +525,7 @@ public synchronized StringBuffer replace(int start, int end, String str) {
516525
* @throws StringIndexOutOfBoundsException {@inheritDoc}
517526
* @since 1.2
518527
*/
528+
@SideEffectFree
519529
@Override
520530
public synchronized String substring(int start) {
521531
return substring(start, count);
@@ -525,6 +535,7 @@ public synchronized String substring(int start) {
525535
* @throws IndexOutOfBoundsException {@inheritDoc}
526536
* @since 1.4
527537
*/
538+
@SideEffectFree
528539
@Override
529540
public synchronized CharSequence subSequence(int start, int end) {
530541
return super.substring(start, end);
@@ -534,6 +545,7 @@ public synchronized CharSequence subSequence(int start, int end) {
534545
* @throws StringIndexOutOfBoundsException {@inheritDoc}
535546
* @since 1.2
536547
*/
548+
@SideEffectFree
537549
@Override
538550
public synchronized String substring(int start, int end) {
539551
return super.substring(start, end);
@@ -749,6 +761,7 @@ public synchronized StringBuffer repeat(CharSequence cs, int count) {
749761
return this;
750762
}
751763

764+
@SideEffectFree
752765
@Override
753766
@IntrinsicCandidate
754767
public synchronized String toString(@GuardSatisfied StringBuffer this) {

src/java.base/share/classes/java/lang/StringBuilder.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ public StringBuilder(CharSequence seq) {
176176
*
177177
* @since 11
178178
*/
179+
@SideEffectFree
179180
@Override
180181
public int compareTo(StringBuilder another) {
181182
return super.compareTo(another);
@@ -498,6 +499,7 @@ public StringBuilder reverse() {
498499
*
499500
* @since 21
500501
*/
502+
@SideEffectsOnly("this")
501503
@Override
502504
@SideEffectFree
503505
public StringBuilder repeat(int codePoint, int count) {
@@ -510,12 +512,14 @@ public StringBuilder repeat(int codePoint, int count) {
510512
*
511513
* @since 21
512514
*/
515+
@SideEffectsOnly("this")
513516
@Override
514517
public StringBuilder repeat(CharSequence cs, int count) {
515518
super.repeat(cs, count);
516519
return this;
517520
}
518521

522+
@SideEffectFree
519523
@Override
520524
@IntrinsicCandidate
521525
public @PolyRegex String toString(@GuardSatisfied @PolyRegex StringBuilder this) {

src/java.base/share/classes/java/lang/StringLatin1.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
package java.lang;
2727

28+
import org.checkerframework.dataflow.qual.SideEffectsOnly;
29+
2830
import java.util.Arrays;
2931
import java.util.Locale;
3032
import java.util.Spliterator;
@@ -79,6 +81,7 @@ public static byte[] inflate(byte[] value, int off, int len) {
7981
return ret;
8082
}
8183

84+
@SideEffectsOnly("#3")
8285
public static void getChars(byte[] value, int srcBegin, int srcEnd, char[] dst, int dstBegin) {
8386
inflate(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
8487
}

src/java.base/share/classes/java/lang/StringUTF16.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
package java.lang;
2727

28+
import org.checkerframework.dataflow.qual.SideEffectsOnly;
29+
2830
import java.util.Arrays;
2931
import java.util.Locale;
3032
import java.util.Spliterator;
@@ -247,6 +249,7 @@ static byte[] toBytesSupplementary(int cp) {
247249
}
248250

249251
@IntrinsicCandidate
252+
@SideEffectsOnly("#3")
250253
public static void getChars(byte[] value, int srcBegin, int srcEnd, char[] dst, int dstBegin) {
251254
// We need a range check here because 'getChar' has no checks
252255
if (srcBegin < srcEnd) {

src/java.base/share/classes/java/util/EnumMap.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.checkerframework.checker.signedness.qual.UnknownSignedness;
4040
import org.checkerframework.dataflow.qual.Pure;
4141
import org.checkerframework.dataflow.qual.SideEffectFree;
42-
import org.checkerframework.dataflow.qual.SideEffectsOnly;
4342
import org.checkerframework.framework.qual.AnnotatedFor;
4443
import org.checkerframework.framework.qual.CFComment;
4544

src/java.base/share/classes/jdk/internal/icu/text/Replaceable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737

3838
package jdk.internal.icu.text;
3939

40+
import org.checkerframework.dataflow.qual.SideEffectFree;
41+
import org.checkerframework.dataflow.qual.SideEffectsOnly;
42+
4043
/**
4144
* <code>Replaceable</code> is an interface representing a
4245
* string of characters that supports the replacement of a range of
@@ -117,5 +120,6 @@ public interface Replaceable {
117120
* @param dstStart the start offset in the destination array.
118121
* @stable ICU 2.0
119122
*/
123+
@SideEffectsOnly("#3")
120124
void getChars(int srcStart, int srcLimit, char dst[], int dstStart);
121125
}

src/java.base/share/classes/jdk/internal/icu/text/ReplaceableString.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
package jdk.internal.icu.text;
3434

35+
import org.checkerframework.dataflow.qual.SideEffectFree;
36+
import org.checkerframework.dataflow.qual.SideEffectsOnly;
37+
3538
/**
3639
* <code>ReplaceableString</code> is an adapter class that implements the
3740
* <code>Replaceable</code> API around an ordinary <code>StringBuffer</code>.
@@ -110,6 +113,7 @@ public char charAt(int offset) {
110113
* @param dstStart the start offset in the destination array.
111114
* @stable ICU 2.0
112115
*/
116+
@SideEffectsOnly("#3")
113117
public void getChars(int srcStart, int srcLimit, char dst[], int dstStart) {
114118
if (srcStart != srcLimit) {
115119
buf.getChars(srcStart, srcLimit, dst, dstStart);

0 commit comments

Comments
 (0)