8325189: Enable this-escape javac warning in java.base

Reviewed-by: alanb, erikj, naoto, smarks, ihse, joehw, lancea, weijun
This commit is contained in:
Joe Darcy 2024-02-07 20:05:11 +00:00
parent 299a8ee68d
commit fbd15b2087
93 changed files with 151 additions and 2 deletions

View file

@ -204,6 +204,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
* @param c the collection whose elements are to be placed into the deque
* @throws NullPointerException if the specified collection is null
*/
@SuppressWarnings("this-escape")
public ArrayDeque(Collection<? extends E> c) {
this(c.size());
copyElements(c);

View file

@ -165,6 +165,7 @@ public class EnumMap<K extends Enum<K>, V> extends AbstractMap<K, V>
* {@code EnumMap} instance and contains no mappings
* @throws NullPointerException if {@code m} is null
*/
@SuppressWarnings("this-escape")
public EnumMap(Map<K, ? extends V> m) {
if (m instanceof EnumMap) {
EnumMap<K, ? extends V> em = (EnumMap<K, ? extends V>) m;

View file

@ -588,6 +588,7 @@ public class GregorianCalendar extends Calendar {
* in the default time zone with the default
* {@link Locale.Category#FORMAT FORMAT} locale.
*/
@SuppressWarnings("this-escape")
public GregorianCalendar() {
this(TimeZone.getDefaultRef(), Locale.getDefault(Locale.Category.FORMAT));
setZoneShared(true);
@ -612,6 +613,7 @@ public class GregorianCalendar extends Calendar {
* @param aLocale the given locale.
* @throws NullPointerException if {@code aLocale} is {@code null}
*/
@SuppressWarnings("this-escape")
public GregorianCalendar(Locale aLocale) {
this(TimeZone.getDefaultRef(), aLocale);
setZoneShared(true);
@ -625,6 +627,7 @@ public class GregorianCalendar extends Calendar {
* @param aLocale the given locale.
* @throws NullPointerException if {@code zone} or {@code aLocale} is {@code null}
*/
@SuppressWarnings("this-escape")
public GregorianCalendar(TimeZone zone, Locale aLocale) {
super(zone, aLocale);
gdate = gcal.newCalendarDate(zone);
@ -640,6 +643,7 @@ public class GregorianCalendar extends Calendar {
* Month value is 0-based. e.g., 0 for January.
* @param dayOfMonth the value used to set the {@code DAY_OF_MONTH} calendar field in the calendar.
*/
@SuppressWarnings("this-escape")
public GregorianCalendar(int year, int month, int dayOfMonth) {
this(year, month, dayOfMonth, 0, 0, 0, 0);
}
@ -657,6 +661,7 @@ public class GregorianCalendar extends Calendar {
* @param minute the value used to set the {@code MINUTE} calendar field
* in the calendar.
*/
@SuppressWarnings("this-escape")
public GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay,
int minute) {
this(year, month, dayOfMonth, hourOfDay, minute, 0, 0);
@ -677,6 +682,7 @@ public class GregorianCalendar extends Calendar {
* @param second the value used to set the {@code SECOND} calendar field
* in the calendar.
*/
@SuppressWarnings("this-escape")
public GregorianCalendar(int year, int month, int dayOfMonth, int hourOfDay,
int minute, int second) {
this(year, month, dayOfMonth, hourOfDay, minute, second, 0);

View file

@ -487,6 +487,7 @@ public class HashMap<K,V> extends AbstractMap<K,V>
* @param m the map whose mappings are to be placed in this map
* @throws NullPointerException if the specified map is null
*/
@SuppressWarnings("this-escape")
public HashMap(Map<? extends K, ? extends V> m) {
this.loadFactor = DEFAULT_LOAD_FACTOR;
putMapEntries(m, false);

View file

@ -116,6 +116,7 @@ public class HashSet<E>
* @param c the collection whose elements are to be placed into this set
* @throws NullPointerException if the specified collection is null
*/
@SuppressWarnings("this-escape")
public HashSet(Collection<? extends E> c) {
map = HashMap.newHashMap(Math.max(c.size(), 12));
addAll(c);

View file

@ -226,6 +226,7 @@ public class Hashtable<K,V>
* @throws NullPointerException if the specified map is null.
* @since 1.2
*/
@SuppressWarnings("this-escape")
public Hashtable(Map<? extends K, ? extends V> t) {
this(Math.max(2*t.size(), 11), 0.75f);
putAll(t);

View file

@ -273,6 +273,7 @@ public class IdentityHashMap<K,V>
* @param m the map whose mappings are to be placed into this map
* @throws NullPointerException if the specified map is null
*/
@SuppressWarnings("this-escape")
public IdentityHashMap(Map<? extends K, ? extends V> m) {
// Allow for a bit of growth
this((int) ((1 + m.size()) * 1.1));

View file

@ -55,6 +55,7 @@ public class InvalidPropertiesFormatException extends IOException {
* @param cause the cause (which is saved for later retrieval by the
* {@link Throwable#getCause()} method).
*/
@SuppressWarnings("this-escape")
public InvalidPropertiesFormatException(Throwable cause) {
super(cause==null ? null : cause.toString());
this.initCause(cause);

View file

@ -474,6 +474,7 @@ public class LinkedHashMap<K,V>
* @param m the map whose mappings are to be placed in this map
* @throws NullPointerException if the specified map is null
*/
@SuppressWarnings("this-escape")
public LinkedHashMap(Map<? extends K, ? extends V> m) {
super();
accessOrder = false;

View file

@ -177,6 +177,7 @@ public class LinkedHashSet<E>
* this set
* @throws NullPointerException if the specified collection is null
*/
@SuppressWarnings("this-escape")
public LinkedHashSet(Collection<? extends E> c) {
super(HashMap.calculateHashMapCapacity(Math.max(c.size(), 12)), .75f, true);
addAll(c);

View file

@ -125,6 +125,7 @@ public class LinkedList<E>
* @param c the collection whose elements are to be placed into this list
* @throws NullPointerException if the specified collection is null
*/
@SuppressWarnings("this-escape")
public LinkedList(Collection<? extends E> c) {
this();
addAll(c);

View file

@ -350,6 +350,7 @@ public class Random implements RandomGenerator, java.io.Serializable {
* @param seed the initial seed
* @see #setSeed(long)
*/
@SuppressWarnings("this-escape")
public Random(long seed) {
if (getClass() == Random.class)
this.seed = new AtomicLong(initialScramble(seed));

View file

@ -156,6 +156,7 @@ public class SimpleTimeZone extends TimeZone {
* @param rawOffset The base time zone offset in milliseconds to GMT.
* @param ID The time zone name that is given to this instance.
*/
@SuppressWarnings("this-escape")
public SimpleTimeZone(int rawOffset, String ID)
{
this.rawOffset = rawOffset;
@ -326,6 +327,7 @@ public class SimpleTimeZone extends TimeZone {
*
* @since 1.4
*/
@SuppressWarnings("this-escape")
public SimpleTimeZone(int rawOffset, String ID,
int startMonth, int startDay, int startDayOfWeek,
int startTime, int startTimeMode,

View file

@ -178,6 +178,7 @@ public class Timer {
* @throws NullPointerException if {@code name} is null
* @since 1.5
*/
@SuppressWarnings("this-escape")
public Timer(String name, boolean isDaemon) {
var threadReaper = new ThreadReaper(queue, thread);
this.cleanup = CleanerFactory.cleaner().register(this, threadReaper);

View file

@ -193,6 +193,7 @@ public class TreeMap<K,V>
* or are not mutually comparable
* @throws NullPointerException if the specified map is null
*/
@SuppressWarnings("this-escape")
public TreeMap(Map<? extends K, ? extends V> m) {
comparator = null;
putAll(m);

View file

@ -159,6 +159,7 @@ public class TreeSet<E> extends AbstractSet<E>
* not {@link Comparable}, or are not mutually comparable
* @throws NullPointerException if the specified collection is null
*/
@SuppressWarnings("this-escape")
public TreeSet(Collection<? extends E> c) {
this();
addAll(c);
@ -171,6 +172,7 @@ public class TreeSet<E> extends AbstractSet<E>
* @param s sorted set whose elements will comprise the new set
* @throws NullPointerException if the specified sorted set is null
*/
@SuppressWarnings("this-escape")
public TreeSet(SortedSet<E> s) {
this(s.comparator());
addAll(s);

View file

@ -256,6 +256,7 @@ public class WeakHashMap<K,V>
* @throws NullPointerException if the specified map is null
* @since 1.3
*/
@SuppressWarnings("this-escape")
public WeakHashMap(Map<? extends K, ? extends V> m) {
this(Math.max((int) Math.ceil(m.size() / (double)DEFAULT_LOAD_FACTOR),
DEFAULT_INITIAL_CAPACITY),

View file

@ -847,6 +847,7 @@ public class ConcurrentHashMap<K,V> extends AbstractMap<K,V>
*
* @param m the map
*/
@SuppressWarnings("this-escape")
public ConcurrentHashMap(Map<? extends K, ? extends V> m) {
this(m.size());
putAll(m);

View file

@ -1096,6 +1096,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
* @throws NullPointerException if the specified map or any of its keys
* or values are null
*/
@SuppressWarnings("this-escape")
public ConcurrentSkipListMap(Map<? extends K, ? extends V> m) {
this.comparator = null;
putAll(m);
@ -1110,6 +1111,7 @@ public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
* @throws NullPointerException if the specified sorted map or any of
* its keys or values are null
*/
@SuppressWarnings("this-escape")
public ConcurrentSkipListMap(SortedMap<K, ? extends V> m) {
this.comparator = m.comparator();
buildFromSorted(m); // initializes transients

View file

@ -137,6 +137,7 @@ public class ConcurrentSkipListSet<E>
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
@SuppressWarnings("this-escape")
public ConcurrentSkipListSet(Collection<? extends E> c) {
m = new ConcurrentSkipListMap<E,Object>();
addAll(c);
@ -150,6 +151,7 @@ public class ConcurrentSkipListSet<E>
* @throws NullPointerException if the specified sorted set or any
* of its elements are null
*/
@SuppressWarnings("this-escape")
public ConcurrentSkipListSet(SortedSet<E> s) {
m = new ConcurrentSkipListMap<E,Object>(s.comparator());
addAll(s);

View file

@ -141,6 +141,7 @@ public class DelayQueue<E extends Delayed> extends AbstractQueue<E>
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
@SuppressWarnings("this-escape")
public DelayQueue(Collection<? extends E> c) {
this.addAll(c);
}

View file

@ -99,6 +99,7 @@ public class ForkJoinWorkerThread extends Thread {
* @throws NullPointerException if pool is null
* @since 19
*/
@SuppressWarnings("this-escape")
protected ForkJoinWorkerThread(ThreadGroup group, ForkJoinPool pool,
boolean preserveThreadLocals) {
this(group, pool, false, !preserveThreadLocals);
@ -110,6 +111,7 @@ public class ForkJoinWorkerThread extends Thread {
* @param pool the pool this thread works in
* @throws NullPointerException if pool is null
*/
@SuppressWarnings("this-escape")
protected ForkJoinWorkerThread(ForkJoinPool pool) {
this(null, pool, false, false);
}

View file

@ -195,6 +195,7 @@ public class LinkedBlockingDeque<E>
* @throws NullPointerException if the specified collection or any
* of its elements are null
*/
@SuppressWarnings("this-escape")
public LinkedBlockingDeque(Collection<? extends E> c) {
this(Integer.MAX_VALUE);
addAll(c);

View file

@ -413,6 +413,7 @@ public class StructuredTaskScope<T> implements AutoCloseable {
* @param name the name of the task scope, can be null
* @param factory the thread factory
*/
@SuppressWarnings("this-escape")
public StructuredTaskScope(String name, ThreadFactory factory) {
this.factory = Objects.requireNonNull(factory, "'factory' is null");
if (name == null)

View file

@ -1297,6 +1297,7 @@ public class ThreadPoolExecutor extends AbstractExecutorService {
* @throws NullPointerException if {@code workQueue}
* or {@code threadFactory} or {@code handler} is null
*/
@SuppressWarnings("this-escape")
public ThreadPoolExecutor(int corePoolSize,
int maximumPoolSize,
long keepAliveTime,

View file

@ -120,6 +120,7 @@ public class JarInputStream extends ZipInputStream {
* it is signed.
* @throws IOException if an I/O error has occurred
*/
@SuppressWarnings("this-escape")
public JarInputStream(InputStream in, boolean verify) throws IOException {
super(in);
this.doVerify = verify;

View file

@ -53,6 +53,7 @@ public class JarOutputStream extends ZipOutputStream {
* @param man the optional {@code Manifest}
* @throws IOException if an I/O error has occurred
*/
@SuppressWarnings("this-escape")
public JarOutputStream(OutputStream out, Manifest man) throws IOException {
super(out);
if (man == null) {

View file

@ -73,6 +73,7 @@ public class Manifest implements Cloneable {
* @param is the input stream containing manifest data
* @throws IOException if an I/O error has occurred
*/
@SuppressWarnings("this-escape")
public Manifest(InputStream is) throws IOException {
this(null, is, null);
}

View file

@ -196,6 +196,7 @@ public class Deflater {
* @param level the compression level (0-9)
* @param nowrap if true then use GZIP compatible compression
*/
@SuppressWarnings("this-escape")
public Deflater(int level, boolean nowrap) {
this.level = level;
this.strategy = DEFAULT_STRATEGY;

View file

@ -130,6 +130,7 @@ public class Inflater {
*
* @param nowrap if true then support GZIP compatible compression
*/
@SuppressWarnings("this-escape")
public Inflater(boolean nowrap) {
this.zsRef = new InflaterZStreamRef(this, init(nowrap));
}

View file

@ -227,6 +227,7 @@ public class ZipFile implements ZipConstants, Closeable {
*
* @since 1.7
*/
@SuppressWarnings("this-escape")
public ZipFile(File file, int mode, Charset charset) throws IOException
{
if (((mode & OPEN_READ) == 0) ||