From 4013b3e695a1cda049b162b044b06a9c199addc0 Mon Sep 17 00:00:00 2001 From: Weitian Xing Date: Tue, 29 Sep 2020 17:13:53 -0400 Subject: [PATCH] Revert "Add aliasing annotations (#57)" This reverts commit 4891771e --- .../share/classes/java/lang/Exception.java | 13 +++--- .../share/classes/java/lang/String.java | 33 ++++++++------- .../share/classes/java/lang/StringBuffer.java | 41 +++++++++---------- 3 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/java.base/share/classes/java/lang/Exception.java b/src/java.base/share/classes/java/lang/Exception.java index 51d57a81326ae..5b44bbbf99d6e 100644 --- a/src/java.base/share/classes/java/lang/Exception.java +++ b/src/java.base/share/classes/java/lang/Exception.java @@ -28,7 +28,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; -import org.checkerframework.common.aliasing.qual.Unique; /** * The class {@code Exception} and its subclasses are a form of @@ -47,7 +46,7 @@ * @jls 11.2 Compile-Time Checking of Exceptions * @since 1.0 */ -@AnnotatedFor({"aliasing", "nullness"}) +@AnnotatedFor({"nullness"}) public class Exception extends Throwable { static final long serialVersionUID = -3387516993124229948L; @@ -57,7 +56,7 @@ public class Exception extends Throwable { * call to {@link #initCause}. */ @SideEffectFree - public @Unique Exception() { + public Exception() { super(); } @@ -70,7 +69,7 @@ public class Exception extends Throwable { * later retrieval by the {@link #getMessage()} method. */ @SideEffectFree - public @Unique Exception(@Nullable String message) { + public Exception(@Nullable String message) { super(message); } @@ -89,7 +88,7 @@ public class Exception extends Throwable { * @since 1.4 */ @SideEffectFree - public @Unique Exception(@Nullable String message, @Nullable Throwable cause) { + public Exception(@Nullable String message, @Nullable Throwable cause) { super(message, cause); } @@ -108,7 +107,7 @@ public class Exception extends Throwable { * @since 1.4 */ @SideEffectFree - public @Unique Exception(@Nullable Throwable cause) { + public Exception(@Nullable Throwable cause) { super(cause); } @@ -126,7 +125,7 @@ public class Exception extends Throwable { * be writable * @since 1.7 */ - protected @Unique Exception(@Nullable String message, @Nullable Throwable cause, + protected Exception(@Nullable String message, @Nullable Throwable cause, boolean enableSuppression, boolean writableStackTrace) { super(message, cause, enableSuppression, writableStackTrace); diff --git a/src/java.base/share/classes/java/lang/String.java b/src/java.base/share/classes/java/lang/String.java index e209fcaa2d24f..a5a05cb5a1d7f 100644 --- a/src/java.base/share/classes/java/lang/String.java +++ b/src/java.base/share/classes/java/lang/String.java @@ -55,7 +55,6 @@ import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; import org.checkerframework.framework.qual.CFComment; -import org.checkerframework.common.aliasing.qual.Unique; import java.io.ObjectStreamField; import java.io.UnsupportedEncodingException; @@ -154,7 +153,7 @@ * @jls 15.18.1 String Concatenation Operator + */ -@AnnotatedFor({"aliasing", "formatter", "index", "interning", "lock", "nullness", "regex", "signature", "signedness"}) +@AnnotatedFor({"formatter", "index", "interning", "lock", "nullness", "regex", "signature", "signedness", "value"}) public final class String implements java.io.Serializable, Comparable, CharSequence { @@ -251,7 +250,7 @@ public final class String */ @SideEffectFree @StaticallyExecutable - public @StringVal("") @Unique String() { + public @StringVal("") String() { this.value = "".value; this.coder = "".coder; } @@ -269,7 +268,7 @@ public final class String @SideEffectFree @StaticallyExecutable @HotSpotIntrinsicCandidate - public @PolyValue @Unique String(@PolyValue String original) { + public @PolyValue String(@PolyValue String original) { this.value = original.value; this.coder = original.coder; this.hash = original.hash; @@ -286,7 +285,7 @@ public final class String */ @SideEffectFree @StaticallyExecutable - public @PolyValue @Unique String(char value @GuardSatisfied @PolyValue []) { + public @PolyValue String(char value @GuardSatisfied @PolyValue []) { this(value, 0, value.length, null); } @@ -313,7 +312,7 @@ public final class String */ @SideEffectFree @StaticallyExecutable - public @Unique String(char value @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int count) { + public String(char value @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int count) { this(value, offset, count, rangeCheck(value, offset, count)); } @@ -352,7 +351,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(int @GuardSatisfied [] codePoints, @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int count) { + public String(int @GuardSatisfied [] codePoints, @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int count) { checkBoundsOffCount(offset, count, codePoints.length); if (count == 0) { this.value = "".value; @@ -414,7 +413,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { @SideEffectFree @StaticallyExecutable @Deprecated(since="1.1") - public @Unique String(byte ascii @GuardSatisfied [], int hibyte, @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int count) { + public String(byte ascii @GuardSatisfied [], int hibyte, @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int count) { checkBoundsOffCount(offset, count, ascii.length); if (count == 0) { this.value = "".value; @@ -468,7 +467,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { @SideEffectFree @StaticallyExecutable @Deprecated(since="1.1") - public @Unique String(byte ascii @GuardSatisfied [], int hibyte) { + public String(byte ascii @GuardSatisfied [], int hibyte) { this(ascii, hibyte, 0, ascii.length); } @@ -507,7 +506,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@PolySigned byte bytes @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int length, String charsetName) + public String(@PolySigned byte bytes @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int length, String charsetName) throws UnsupportedEncodingException { if (charsetName == null) throw new NullPointerException("charsetName"); @@ -550,7 +549,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@PolySigned byte bytes @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int length, Charset charset) { + public String(@PolySigned byte bytes @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int length, Charset charset) { if (charset == null) throw new NullPointerException("charset"); checkBoundsOffCount(offset, length, bytes.length); @@ -585,7 +584,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@PolySigned byte bytes @GuardSatisfied [], String charsetName) + public String(@PolySigned byte bytes @GuardSatisfied [], String charsetName) throws UnsupportedEncodingException { this(bytes, 0, bytes.length, charsetName); } @@ -612,7 +611,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@PolySigned byte bytes @GuardSatisfied [], Charset charset) { + public String(@PolySigned byte bytes @GuardSatisfied [], Charset charset) { this(bytes, 0, bytes.length, charset); } @@ -644,7 +643,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@PolySigned byte bytes @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int length) { + public String(@PolySigned byte bytes @GuardSatisfied [], @IndexOrHigh({"#1"}) int offset, @LTLengthOf(value={"#1"}, offset={"#2 - 1"}) @NonNegative int length) { checkBoundsOffCount(offset, length, bytes.length); StringCoding.Result ret = StringCoding.decode(bytes, offset, length); this.value = ret.value; @@ -669,7 +668,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@PolySigned byte @GuardSatisfied [] bytes) { + public String(@PolySigned byte @GuardSatisfied [] bytes) { this(bytes, 0, bytes.length); } @@ -684,7 +683,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@GuardSatisfied StringBuffer buffer) { + public String(@GuardSatisfied StringBuffer buffer) { this(buffer.toString()); } @@ -705,7 +704,7 @@ private static Void rangeCheck(char[] value, int offset, int count) { */ @SideEffectFree @StaticallyExecutable - public @Unique String(@GuardSatisfied StringBuilder builder) { + public String(@GuardSatisfied StringBuilder builder) { this(builder, null); } diff --git a/src/java.base/share/classes/java/lang/StringBuffer.java b/src/java.base/share/classes/java/lang/StringBuffer.java index 60a11ee6194a0..f6b6d9ebca1c2 100644 --- a/src/java.base/share/classes/java/lang/StringBuffer.java +++ b/src/java.base/share/classes/java/lang/StringBuffer.java @@ -33,9 +33,6 @@ import org.checkerframework.dataflow.qual.Pure; import org.checkerframework.dataflow.qual.SideEffectFree; import org.checkerframework.framework.qual.AnnotatedFor; -import org.checkerframework.common.aliasing.qual.Unique; -import org.checkerframework.common.aliasing.qual.LeakedToResult; -import org.checkerframework.common.aliasing.qual.NonLeaked; import java.util.Arrays; import jdk.internal.HotSpotIntrinsicCandidate; @@ -115,7 +112,7 @@ * @see java.lang.String * @since 1.0 */ -@AnnotatedFor({"aliasing", "lock", "nullness", "index"}) +@AnnotatedFor({"lock", "nullness", "index"}) public final class StringBuffer extends AbstractStringBuilder implements java.io.Serializable, Comparable, CharSequence @@ -135,7 +132,7 @@ public final class StringBuffer * initial capacity of 16 characters. */ @HotSpotIntrinsicCandidate - public @Unique StringBuffer() { + public StringBuffer() { super(16); } @@ -148,7 +145,7 @@ public final class StringBuffer * argument is less than {@code 0}. */ @HotSpotIntrinsicCandidate - public @Unique StringBuffer(@NonNegative int capacity) { + public StringBuffer(@NonNegative int capacity) { super(capacity); } @@ -160,7 +157,7 @@ public final class StringBuffer * @param str the initial contents of the buffer. */ @HotSpotIntrinsicCandidate - public @Unique StringBuffer(String str) { + public StringBuffer(String str) { super(str.length() + 16); append(str); } @@ -178,7 +175,7 @@ public final class StringBuffer * @param seq the sequence to copy. * @since 1.5 */ - public @Unique StringBuffer(CharSequence seq) { + public StringBuffer(CharSequence seq) { this(seq.length() + 16); append(seq); } @@ -313,7 +310,7 @@ public synchronized void setCharAt(int index, char ch) { } @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked @Nullable Object obj) { + public synchronized StringBuffer append(@Nullable Object obj) { toStringCache = null; super.append(String.valueOf(obj)); return this; @@ -321,7 +318,7 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL @Override @HotSpotIntrinsicCandidate - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked @Nullable String str) { + public synchronized StringBuffer append(@Nullable String str) { toStringCache = null; super.append(str); return this; @@ -351,7 +348,7 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL * @return a reference to this object. * @since 1.4 */ - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked @Nullable StringBuffer sb) { + public synchronized StringBuffer append(@Nullable StringBuffer sb) { toStringCache = null; super.append(sb); return this; @@ -361,7 +358,7 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL * @since 1.8 */ @Override - synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked AbstractStringBuilder asb) { + synchronized StringBuffer append(AbstractStringBuilder asb) { toStringCache = null; super.append(asb); return this; @@ -389,7 +386,7 @@ synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked A * @since 1.5 */ @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked @Nullable CharSequence s) { + public synchronized StringBuffer append(@Nullable CharSequence s) { toStringCache = null; super.append(s); return this; @@ -400,7 +397,7 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL * @since 1.5 */ @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked @Nullable CharSequence s, @IndexOrHigh({"#1"}) int start, @IndexOrHigh({"#1"}) int end) + public synchronized StringBuffer append(@Nullable CharSequence s, @IndexOrHigh({"#1"}) int start, @IndexOrHigh({"#1"}) int end) { toStringCache = null; super.append(s, start, end); @@ -408,7 +405,7 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL } @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked char[] str) { + public synchronized StringBuffer append(char[] str) { toStringCache = null; super.append(str); return this; @@ -418,14 +415,14 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL * @throws IndexOutOfBoundsException {@inheritDoc} */ @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked char[] str, @IndexOrHigh({"#1"}) int offset, @IndexOrHigh({"#1"}) int len) { + public synchronized StringBuffer append(char[] str, @IndexOrHigh({"#1"}) int offset, @IndexOrHigh({"#1"}) int len) { toStringCache = null; super.append(str, offset, len); return this; } @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked boolean b) { + public synchronized StringBuffer append(boolean b) { toStringCache = null; super.append(b); return this; @@ -433,7 +430,7 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL @Override @HotSpotIntrinsicCandidate - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked char c) { + public synchronized StringBuffer append(char c) { toStringCache = null; super.append(c); return this; @@ -441,7 +438,7 @@ public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonL @Override @HotSpotIntrinsicCandidate - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked int i) { + public synchronized StringBuffer append(int i) { toStringCache = null; super.append(i); return this; @@ -458,21 +455,21 @@ public synchronized StringBuffer appendCodePoint(int codePoint) { } @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked long lng) { + public synchronized StringBuffer append(long lng) { toStringCache = null; super.append(lng); return this; } @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked float f) { + public synchronized StringBuffer append(float f) { toStringCache = null; super.append(f); return this; } @Override - public synchronized StringBuffer append(@LeakedToResult StringBuffer this, @NonLeaked double d) { + public synchronized StringBuffer append(double d) { toStringCache = null; super.append(d); return this;