Skip to content

Commit

Permalink
8325189: Enable this-escape javac warning in java.base
Browse files Browse the repository at this point in the history
Reviewed-by: alanb, erikj, naoto, smarks, ihse, joehw, lancea, weijun
  • Loading branch information
jddarcy committed Feb 7, 2024
1 parent 299a8ee commit fbd15b2
Show file tree
Hide file tree
Showing 93 changed files with 151 additions and 2 deletions.
6 changes: 5 additions & 1 deletion make/modules/java.base/Java.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
# questions.
#

DISABLED_WARNINGS_java += this-escape
# The base module should be built with all warnings enabled. When a
# new warning is added to javac, it can be temporarily added to the
# disabled warnings list.
#
# DISABLED_WARNINGS_java +=

DOCLINT += -Xdoclint:all/protected \
'-Xdoclint/package:java.*,javax.*'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public abstract class Server extends NTLM {
* @param domain the domain, must not be null
* @throws NTLMException if {@code domain} is null.
*/
@SuppressWarnings("this-escape")
public Server(String version, String domain) throws NTLMException {
super(version);
if (domain == null) {
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/io/FileInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public FileInputStream(String name) throws FileNotFoundException {
* @see java.io.File#getPath()
* @see java.lang.SecurityManager#checkRead(java.lang.String)
*/
@SuppressWarnings("this-escape")
public FileInputStream(File file) throws FileNotFoundException {
String name = (file != null ? file.getPath() : null);
@SuppressWarnings("removal")
Expand Down Expand Up @@ -177,6 +178,7 @@ public FileInputStream(File file) throws FileNotFoundException {
* file descriptor.
* @see SecurityManager#checkRead(java.io.FileDescriptor)
*/
@SuppressWarnings("this-escape")
public FileInputStream(FileDescriptor fdObj) {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/io/FileOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public FileOutputStream(File file) throws FileNotFoundException {
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
* @since 1.4
*/
@SuppressWarnings("this-escape")
public FileOutputStream(File file, boolean append)
throws FileNotFoundException
{
Expand Down Expand Up @@ -254,6 +255,7 @@ public FileOutputStream(File file, boolean append)
* write access to the file descriptor
* @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor)
*/
@SuppressWarnings("this-escape")
public FileOutputStream(FileDescriptor fdObj) {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
Expand Down
4 changes: 4 additions & 0 deletions src/java.base/share/classes/java/io/InputStreamReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private static Object lockFor(InputStreamReader reader) {
*
* @see Charset#defaultCharset()
*/
@SuppressWarnings("this-escape")
public InputStreamReader(InputStream in) {
super(in);
Charset cs = Charset.defaultCharset();
Expand All @@ -102,6 +103,7 @@ public InputStreamReader(InputStream in) {
* @throws UnsupportedEncodingException
* If the named charset is not supported
*/
@SuppressWarnings("this-escape")
public InputStreamReader(InputStream in, String charsetName)
throws UnsupportedEncodingException
{
Expand All @@ -119,6 +121,7 @@ public InputStreamReader(InputStream in, String charsetName)
*
* @since 1.4
*/
@SuppressWarnings("this-escape")
public InputStreamReader(InputStream in, Charset cs) {
super(in);
if (cs == null)
Expand All @@ -134,6 +137,7 @@ public InputStreamReader(InputStream in, Charset cs) {
*
* @since 1.4
*/
@SuppressWarnings("this-escape")
public InputStreamReader(InputStream in, CharsetDecoder dec) {
super(in);
if (dec == null)
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/ObjectInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,7 @@ private static class Logging {
* @see ObjectInputStream#readFields()
* @see ObjectOutputStream#ObjectOutputStream(OutputStream)
*/
@SuppressWarnings("this-escape")
public ObjectInputStream(InputStream in) throws IOException {
verifySubclass();
bin = new BlockDataInputStream(in);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ protected Boolean computeValue(Class<?> type) {
* @see ObjectOutputStream#putFields()
* @see ObjectInputStream#ObjectInputStream(InputStream)
*/
@SuppressWarnings("this-escape")
public ObjectOutputStream(OutputStream out) throws IOException {
verifySubclass();
bout = new BlockDataOutputStream(out);
Expand Down
4 changes: 4 additions & 0 deletions src/java.base/share/classes/java/io/OutputStreamWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ private static Object lockFor(OutputStreamWriter writer) {
* @throws UnsupportedEncodingException
* If the named encoding is not supported
*/
@SuppressWarnings("this-escape")
public OutputStreamWriter(OutputStream out, String charsetName)
throws UnsupportedEncodingException
{
Expand All @@ -118,6 +119,7 @@ public OutputStreamWriter(OutputStream out, String charsetName)
* @param out An OutputStream
* @see Charset#defaultCharset()
*/
@SuppressWarnings("this-escape")
public OutputStreamWriter(OutputStream out) {
super(out);
se = StreamEncoder.forOutputStreamWriter(out, lockFor(this),
Expand All @@ -135,6 +137,7 @@ public OutputStreamWriter(OutputStream out) {
*
* @since 1.4
*/
@SuppressWarnings("this-escape")
public OutputStreamWriter(OutputStream out, Charset cs) {
super(out);
if (cs == null)
Expand All @@ -153,6 +156,7 @@ public OutputStreamWriter(OutputStream out, Charset cs) {
*
* @since 1.4
*/
@SuppressWarnings("this-escape")
public OutputStreamWriter(OutputStream out, CharsetEncoder enc) {
super(out);
if (enc == null)
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/PipedInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public PipedInputStream(PipedOutputStream src) throws IOException {
* @throws IllegalArgumentException if {@code pipeSize <= 0}.
* @since 1.6
*/
@SuppressWarnings("this-escape")
public PipedInputStream(PipedOutputStream src, int pipeSize)
throws IOException {
initPipe(pipeSize);
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/PipedOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ more sophisticated. Either using thread groups (but what about
* @param snk The piped input stream to connect to.
* @throws IOException if an I/O error occurs.
*/
@SuppressWarnings("this-escape")
public PipedOutputStream(PipedInputStream snk) throws IOException {
connect(snk);
}
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/PipedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public PipedReader(PipedWriter src) throws IOException {
* @throws IllegalArgumentException if {@code pipeSize <= 0}.
* @since 1.6
*/
@SuppressWarnings("this-escape")
public PipedReader(PipedWriter src, int pipeSize) throws IOException {
initPipe(pipeSize);
connect(src);
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/PipedWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ more sophisticated. Either using thread groups (but what about
* @param snk The piped reader to connect to.
* @throws IOException if an I/O error occurs.
*/
@SuppressWarnings("this-escape")
public PipedWriter(PipedReader snk) throws IOException {
connect(snk);
}
Expand Down
4 changes: 4 additions & 0 deletions src/java.base/share/classes/java/io/PrintStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public PrintStream(OutputStream out) {
* @see java.io.PrintWriter#PrintWriter(java.io.OutputStream, boolean)
* @see Charset#defaultCharset()
*/
@SuppressWarnings("this-escape")
public PrintStream(OutputStream out, boolean autoFlush) {
this(autoFlush, requireNonNull(out, "Null output stream"));
}
Expand Down Expand Up @@ -212,6 +213,7 @@ public PrintStream(OutputStream out, boolean autoFlush, String encoding)
*
* @since 10
*/
@SuppressWarnings("this-escape")
public PrintStream(OutputStream out, boolean autoFlush, Charset charset) {
super(out);
this.autoFlush = autoFlush;
Expand Down Expand Up @@ -255,6 +257,7 @@ public PrintStream(OutputStream out, boolean autoFlush, Charset charset) {
*
* @since 1.5
*/
@SuppressWarnings("this-escape")
public PrintStream(String fileName) throws FileNotFoundException {
this(false, new FileOutputStream(fileName));
}
Expand Down Expand Up @@ -356,6 +359,7 @@ public PrintStream(String fileName, Charset charset) throws IOException {
*
* @since 1.5
*/
@SuppressWarnings("this-escape")
public PrintStream(File file) throws FileNotFoundException {
this(false, new FileOutputStream(file));
}
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/io/RandomAccessFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ public RandomAccessFile(String pathname, String mode)
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
* @see java.nio.channels.FileChannel#force(boolean)
*/
@SuppressWarnings("this-escape")
public RandomAccessFile(File file, String mode)
throws FileNotFoundException
{
Expand Down
2 changes: 2 additions & 0 deletions src/java.base/share/classes/java/io/StreamTokenizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ private StreamTokenizer() {
* @see java.io.StreamTokenizer#StreamTokenizer(java.io.Reader)
*/
@Deprecated
@SuppressWarnings("this-escape")
public StreamTokenizer(InputStream is) {
this();
if (is == null) {
Expand All @@ -242,6 +243,7 @@ public StreamTokenizer(InputStream is) {
* @param r a Reader object providing the input stream.
* @since 1.1
*/
@SuppressWarnings("this-escape")
public StreamTokenizer(Reader r) {
this();
if (r == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public class WriteAbortedException extends ObjectStreamException {
* @param s String describing the exception.
* @param ex Exception causing the abort.
*/
@SuppressWarnings("this-escape")
public WriteAbortedException(String s, Exception ex) {
super(s);
initCause(null); // Disallow subsequent initCause
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/lang/AssertionError.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ private AssertionError(String detailMessage) {
* @param detailMessage value to be used in constructing detail message
* @see Throwable#getCause()
*/
@SuppressWarnings("this-escape")
public AssertionError(Object detailMessage) {
this(String.valueOf(detailMessage));
if (detailMessage instanceof Throwable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public BootstrapMethodError(String s, Throwable cause) {
*
* @param cause the cause, may be {@code null}.
*/
@SuppressWarnings("this-escape")
public BootstrapMethodError(Throwable cause) {
// cf. Throwable(Throwable cause) constructor.
super(cause == null ? null : cause.toString());
Expand Down
3 changes: 3 additions & 0 deletions src/java.base/share/classes/java/lang/ClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ String nameAndId() {
*
* @since 9
*/
@SuppressWarnings("this-escape")
protected ClassLoader(String name, ClassLoader parent) {
this(checkCreateClassLoader(name), name, parent);
}
Expand All @@ -457,6 +458,7 @@ protected ClassLoader(String name, ClassLoader parent) {
*
* @since 1.2
*/
@SuppressWarnings("this-escape")
protected ClassLoader(ClassLoader parent) {
this(checkCreateClassLoader(), null, parent);
}
Expand All @@ -476,6 +478,7 @@ protected ClassLoader(ClassLoader parent) {
* {@code checkCreateClassLoader} method doesn't allow creation
* of a new class loader.
*/
@SuppressWarnings("this-escape")
protected ClassLoader() {
this(checkCreateClassLoader(), null, getSystemClassLoader());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class ExceptionInInitializerError extends LinkageError {
* throwable object.
* A detail message is a String that describes this particular exception.
*/
@SuppressWarnings("this-escape")
public ExceptionInInitializerError() {
initCause(null); // Disallow subsequent initCause
}
Expand Down
1 change: 1 addition & 0 deletions src/java.base/share/classes/java/lang/ThreadGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public ThreadGroup(String name) {
* thread in the specified thread group.
* @see java.lang.ThreadGroup#checkAccess()
*/
@SuppressWarnings("this-escape")
public ThreadGroup(ThreadGroup parent, String name) {
this(checkParentAccess(parent), parent, name);
}
Expand Down
5 changes: 5 additions & 0 deletions src/java.base/share/classes/java/lang/Throwable.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ private static class SentinelHolder {
* <p>The {@link #fillInStackTrace()} method is called to initialize
* the stack trace data in the newly created throwable.
*/
@SuppressWarnings("this-escape")
public Throwable() {
fillInStackTrace();
if (jfrTracing) {
Expand All @@ -278,6 +279,7 @@ public Throwable() {
* @param message the detail message. The detail message is saved for
* later retrieval by the {@link #getMessage()} method.
*/
@SuppressWarnings("this-escape")
public Throwable(String message) {
fillInStackTrace();
detailMessage = message;
Expand All @@ -303,6 +305,7 @@ public Throwable(String message) {
* unknown.)
* @since 1.4
*/
@SuppressWarnings("this-escape")
public Throwable(String message, Throwable cause) {
fillInStackTrace();
detailMessage = message;
Expand All @@ -329,6 +332,7 @@ public Throwable(String message, Throwable cause) {
* unknown.)
* @since 1.4
*/
@SuppressWarnings("this-escape")
public Throwable(Throwable cause) {
fillInStackTrace();
detailMessage = (cause==null ? null : cause.toString());
Expand Down Expand Up @@ -378,6 +382,7 @@ public Throwable(Throwable cause) {
* @see ArithmeticException
* @since 1.7
*/